List of usage examples for io.netty.buffer ByteBuf writeShort
public abstract ByteBuf writeShort(int value);
From source file:com.tesora.dve.mysqlapi.repl.messages.MyTableMapLogEvent.java
License:Open Source License
@Override public void marshallMessage(ByteBuf cb) { cb.writeInt(tableId); cb.writeShort(reserved); cb.writeBytes(variableData); }
From source file:com.torchmind.netty.msgpack.codec.MessageCodec.java
License:Apache License
/** * {@inheritDoc}//from w ww . ja va 2s .c o m */ @Override protected void encode(ChannelHandlerContext ctx, Object msg, ByteBuf out) throws Exception { // verify argument Preconditions.checkNotNull(msg, "msg"); // search message identifier short identifier = this.getRegistry().getMessageID(msg.getClass()); // send identifier out.writeShort(identifier); // encode message out.writeBytes(this.messagePack.write(msg)); }
From source file:com.torchmind.netty.msgpack.test.MessageCodecTest.java
License:Apache License
/** * Tests message decoding.//w ww.ja va 2s.c o m */ @Test public void decoding() throws IOException { // create a msgpack instance MessagePack messagePack = new MessagePack(); // create ByteBuf ByteBuf buffer = this.channel.alloc().buffer(); // generate a message buffer.writeShort(0x00); buffer.writeBytes(messagePack.write(new TestMessage1(42))); // write this.channel.writeInbound(buffer); // create ByteBuf buffer = this.channel.alloc().buffer(); // generate a message buffer.writeShort(0x10); buffer.writeBytes(messagePack.write(new TestMessage2(42, 21))); // write this.channel.writeInbound(buffer); // check inbound queue Assert.assertEquals("Less than two messages decoded", 2, this.channel.inboundMessages().size()); // get first object TestMessage1 message1 = ((TestMessage1) this.channel.inboundMessages().poll()); TestMessage2 message2 = ((TestMessage2) this.channel.inboundMessages().poll()); // verify values Assert.assertEquals("Test value one does not match", 42, message1.getValue()); Assert.assertEquals("Test value one does not match", 42, message2.getValue()); Assert.assertEquals("Test value two does not match", 21, message2.getValue2()); }
From source file:com.turn.ttorrent.common.protocol.udp.UDPAnnounceRequestMessage.java
License:Apache License
@Override public void toWire(ByteBuf out) { _toWire(out);/*w w w .j a v a2s . com*/ out.writeBytes(infoHash); out.writeBytes(getPeerId()); out.writeLong(downloaded); out.writeLong(uploaded); out.writeLong(left); out.writeInt(event.getId()); out.writeBytes(getIp4Address(peerAddress)); out.writeInt(key); out.writeInt(numWant); out.writeShort(peerAddress.getPort()); }
From source file:com.turn.ttorrent.common.protocol.udp.UDPAnnounceResponseMessage.java
License:Apache License
@Override public void toWire(ByteBuf out) { _toWire(out);//from ww w .j ava 2 s . c o m out.writeInt(interval); /** * Leechers (incomplete) are first, before seeders (complete) in the packet. */ out.writeInt(incomplete); out.writeInt(complete); for (Peer peer : peers) { byte[] ip = peer.getIpBytes(); if (ip == null || ip.length != 4) continue; out.writeBytes(ip); out.writeShort((short) peer.getPort()); } }
From source file:com.twitter.http2.HttpFrameDecoderTest.java
License:Apache License
@Test public void testHttpSettingsFrame() throws Exception { int length = 6; byte flags = 0; int streamId = 0; // connection identifier int id = RANDOM.nextInt() & 0xFFFF; int value = RANDOM.nextInt(); ByteBuf frame = settingsFrame(length, flags, streamId); frame.writeShort(id); frame.writeInt(value);/* ww w . ja v a 2s. c o m*/ decoder.decode(frame); InOrder inOrder = inOrder(delegate); inOrder.verify(delegate).readSettingsFrame(false); inOrder.verify(delegate).readSetting(id, value); inOrder.verify(delegate).readSettingsEnd(); verifyNoMoreInteractions(delegate); }
From source file:com.twitter.http2.HttpFrameDecoderTest.java
License:Apache License
@Test public void testHttpSettingsFrameWithMultiples() throws Exception { int length = 12; byte flags = 0; int streamId = 0; // connection identifier int id = RANDOM.nextInt() & 0xFFFF; int value1 = RANDOM.nextInt(); int value2 = RANDOM.nextInt(); ByteBuf frame = settingsFrame(length, flags, streamId); frame.writeShort(id); frame.writeInt(value1);// ww w.jav a 2 s . c o m frame.writeShort(id); frame.writeInt(value2); decoder.decode(frame); InOrder inOrder = inOrder(delegate); inOrder.verify(delegate).readSettingsFrame(false); inOrder.verify(delegate).readSetting(id, value1); inOrder.verify(delegate).readSetting(id, value2); inOrder.verify(delegate).readSettingsEnd(); verifyNoMoreInteractions(delegate); }
From source file:com.twitter.http2.HttpFrameDecoderTest.java
License:Apache License
@Test public void testHttpSettingsFrameReservedBits() throws Exception { int length = 6; byte flags = (byte) 0xFE; // should ignore any unknown flags int streamId = 0; // connection identifier int id = RANDOM.nextInt() & 0xFFFF; int value = RANDOM.nextInt(); ByteBuf frame = settingsFrame(length, flags, streamId); setReservedBits(frame);/* w w w . ja v a 2 s . c o m*/ frame.writeShort(id); frame.writeInt(value); decoder.decode(frame); InOrder inOrder = inOrder(delegate); inOrder.verify(delegate).readSettingsFrame(false); inOrder.verify(delegate).readSetting(id, value); inOrder.verify(delegate).readSettingsEnd(); verifyNoMoreInteractions(delegate); }
From source file:com.twitter.http2.HttpFrameDecoderTest.java
License:Apache License
@Test public void testInvalidHttpSettingsFrame() throws Exception { int length = 8; // invalid length byte flags = 0; int streamId = 0; // connection identifier int id = RANDOM.nextInt() & 0xFFFF; int value = RANDOM.nextInt(); ByteBuf frame = settingsFrame(length, flags, streamId); frame.writeShort(id); frame.writeInt(value);/* w w w. ja va2 s. c om*/ decoder.decode(frame); verify(delegate).readFrameError(anyString()); verifyNoMoreInteractions(delegate); }
From source file:com.twitter.http2.HttpFrameDecoderTest.java
License:Apache License
@Test public void testInvalidHttpSettingsAckFrame() throws Exception { int length = 6; // invalid length byte flags = 0x01; // ACK int streamId = 0; // connection identifier int id = RANDOM.nextInt() & 0xFFFF; int value = RANDOM.nextInt(); ByteBuf frame = settingsFrame(length, flags, streamId); frame.writeShort(id); frame.writeInt(value);/*from w w w .jav a 2 s.co m*/ decoder.decode(frame); verify(delegate).readFrameError(anyString()); verifyNoMoreInteractions(delegate); }