List of usage examples for io.netty.buffer ByteBuf readInt
public abstract int readInt();
From source file:com.github.spapageo.jannel.channel.ChannelBufferUtilsTest.java
License:Open Source License
@Test public void testWriteStringToOctetStringWhenStringIsNullWritesMinusOne() throws Exception { ByteBuf byteBuf = Unpooled.buffer(4); ChannelBufferUtils.writeStringToOctetString(null, byteBuf, StandardCharsets.UTF_8); assertEquals("Written length prefix in not -1 for null string", -1, byteBuf.readInt()); byteBuf.release();/*from w ww .ja v a2 s . c o m*/ }
From source file:com.github.spapageo.jannel.channel.ChannelBufferUtilsTest.java
License:Open Source License
@Test public void testWriteStringToOctetStringIsEncodedCorrectly() throws Exception { ByteBuf encodedString = Unpooled.copiedBuffer(STRING_TO_ENCODE.getBytes(StandardCharsets.UTF_8)); ByteBuf outputBuffer = Unpooled.buffer(4 + encodedString.capacity()); ChannelBufferUtils.writeStringToOctetString(STRING_TO_ENCODE, outputBuffer, StandardCharsets.UTF_8); assertEquals("Written length prefix in not the length of the encoded string byte array", encodedString.capacity(), outputBuffer.readInt()); assertEquals("Written bytes are not the same with those of the input string", encodedString, outputBuffer); outputBuffer.release();/*from ww w . j a va2s . co m*/ encodedString.release(); }
From source file:com.github.spapageo.jannel.channel.ChannelBufferUtilsTest.java
License:Open Source License
@Test public void testWriteBytesToOctetStringWhenBytesAreNullWritesMinusOne() throws Exception { ByteBuf byteBuf = Unpooled.buffer(4); ChannelBufferUtils.writeBytesToOctetString(null, byteBuf); assertEquals("Written length prefix in not -1 for null byte array", -1, byteBuf.readInt()); byteBuf.release();//from w w w .jav a 2 s . c o m }
From source file:com.github.spapageo.jannel.channel.ChannelBufferUtilsTest.java
License:Open Source License
@Test public void testWriteBytesToOctetStringIsWrittenCorrectly() throws Exception { byte[] payload = { 0x14, 0x16 }; ByteBuf input = Unpooled.copiedBuffer(payload); ByteBuf outputBuffer = Unpooled.buffer(4 + payload.length); ChannelBufferUtils.writeBytesToOctetString(input, outputBuffer); assertEquals("Written length prefix in not the length of the encoded byte array", payload.length, outputBuffer.readInt()); assertEquals("Written bytes are not the same with those of the input array", input.readerIndex(0), outputBuffer);/* w w w.j a va 2s.c o m*/ outputBuffer.release(); input.release(); }
From source file:com.github.spapageo.jannel.channel.ChannelBufferUtilsTest.java
License:Open Source License
@Test public void testWriteUUIDToOctetStringWhenStringIsNullWritesMinusOne() throws Exception { ByteBuf byteBuf = Unpooled.buffer(4); ChannelBufferUtils.writeUUIDToOctetString(null, byteBuf, StandardCharsets.UTF_8); assertEquals("Written length prefix in not -1 for null string", -1, byteBuf.readInt()); byteBuf.release();/*from w w w. j ava 2 s.co m*/ }
From source file:com.github.spapageo.jannel.channel.ChannelBufferUtilsTest.java
License:Open Source License
@Test public void testWriteUUIDToOctetStringIsEncodedCorrectly() throws Exception { UUID input = UUID.randomUUID(); String uuidString = input.toString(); ByteBuf encodedUUID = Unpooled.copiedBuffer(uuidString.getBytes(StandardCharsets.UTF_8)); ByteBuf outputBuffer = Unpooled.buffer(4 + encodedUUID.capacity()); ChannelBufferUtils.writeUUIDToOctetString(input, outputBuffer, StandardCharsets.UTF_8); assertEquals("Written length prefix in not the length of the encoded string byte array", encodedUUID.capacity(), outputBuffer.readInt()); assertEquals("Written bytes are not the same with those of the input string", encodedUUID, outputBuffer); outputBuffer.release();/*from w w w. java 2s . c o m*/ encodedUUID.release(); }
From source file:com.github.spapageo.jannel.channel.MessageEncoderTest.java
License:Open Source License
@Test public void testEncodeWritesMessageTypeAndCallsTranscoder() throws Exception { Transcoder transcoder = mock(DefaultTranscoder.class); MessageEncoder messageEncoder = new MessageEncoder(transcoder); Message msg = new Ack(); ByteBuf byteBuf = Unpooled.buffer(4); messageEncoder.encode(null, msg, byteBuf); assertEquals("The written message type doesn't match the given one", msg.getType().value(), byteBuf.readInt()); verify(transcoder).encode(msg, byteBuf); byteBuf.release();//w w w . ja v a 2s . c o m }
From source file:com.github.spapageo.jannel.transcode.TranscoderHelperTest.java
License:Open Source License
@Test public void testEncodeDatagramEncodesCorrectly() throws Exception { byte[] payload = { 0x56, 0x35 }; ByteBuf payloadBuffer = Unpooled.copiedBuffer(payload); Datagram datagram = new Datagram(); datagram.setDestinationAddress("?"); datagram.setSourceAddress(""); datagram.setDestinationPort(5555);/*from w w w . j a v a 2 s. c om*/ datagram.setSourcePort(4444); datagram.setUserData(payloadBuffer); ByteBuf byteBuf = Unpooled.buffer(); transcoderHelper.encodeDatagram(datagram, byteBuf); assertEquals("Source address is incorrect", "", ChannelBufferUtils.readOctetStringToString(byteBuf, Charsets.UTF_8)); assertEquals("Source port is incorrect", 4444, byteBuf.readInt()); assertEquals("Source address is incorrect", "?", ChannelBufferUtils.readOctetStringToString(byteBuf, Charsets.UTF_8)); assertEquals("Source port is incorrect", 5555, byteBuf.readInt()); assertEquals("Data payload is incorrect", payloadBuffer.readerIndex(0), ChannelBufferUtils.readOctetStringToBytes(byteBuf)); byteBuf.release(); payloadBuffer.release(); }
From source file:com.github.spapageo.jannel.transcode.TranscoderHelperTest.java
License:Open Source License
@Test public void testEncodeAckEncodesCorrectly() throws Exception { Ack ack = new Ack(); ack.setTime(0);/*from w w w . j a v a 2s. c o m*/ ack.setId(UUID.randomUUID()); ack.setResponse(AckType.SUCCESS); ByteBuf byteBuf = Unpooled.buffer(); transcoderHelper.encodeAck(ack, byteBuf); assertEquals("Type of ack response is incorrect", AckType.SUCCESS, AckType.fromValue(byteBuf.readInt())); assertEquals("The time is incorrect", 0, byteBuf.readInt()); assertEquals("Ack id is incorrect", ack.getId(), ChannelBufferUtils.readUUID(byteBuf, Charsets.UTF_8)); byteBuf.release(); }
From source file:com.github.spapageo.jannel.transcode.TranscoderHelperTest.java
License:Open Source License
@Test public void testEncodeHeartBeatEncodesCorrectly() throws Exception { HeartBeat heartBeat = new HeartBeat(); heartBeat.setLoad(1);//from ww w .j a v a2 s. c om ByteBuf byteBuf = Unpooled.buffer(); transcoderHelper.encodeHeartBeat(heartBeat, byteBuf); assertEquals("HeartBeat load is incorrect", 1, byteBuf.readInt()); byteBuf.release(); }