use of io.netty.handler.codec.LengthFieldPrepender in project netty by netty.
the class LengthFieldPrependerTest method testPrependLengthInLittleEndian.
@Test
public void testPrependLengthInLittleEndian() throws Exception {
final EmbeddedChannel ch = new EmbeddedChannel(new LengthFieldPrepender(ByteOrder.LITTLE_ENDIAN, 4, 0, false));
ch.writeOutbound(msg);
ByteBuf buf = ch.readOutbound();
assertEquals(4, buf.readableBytes());
byte[] writtenBytes = new byte[buf.readableBytes()];
buf.getBytes(0, writtenBytes);
assertEquals(1, writtenBytes[0]);
assertEquals(0, writtenBytes[1]);
assertEquals(0, writtenBytes[2]);
assertEquals(0, writtenBytes[3]);
buf.release();
buf = ch.readOutbound();
assertSame(buf, msg);
buf.release();
assertFalse(ch.finish(), "The channel must have been completely read");
}
use of io.netty.handler.codec.LengthFieldPrepender in project netty by netty.
the class LengthFieldPrependerTest method testPrependLength.
@Test
public void testPrependLength() throws Exception {
final EmbeddedChannel ch = new EmbeddedChannel(new LengthFieldPrepender(4));
ch.writeOutbound(msg);
ByteBuf buf = ch.readOutbound();
assertEquals(4, buf.readableBytes());
assertEquals(msg.readableBytes(), buf.readInt());
buf.release();
buf = ch.readOutbound();
assertSame(buf, msg);
buf.release();
}
use of io.netty.handler.codec.LengthFieldPrepender in project netty by netty.
the class LengthFieldPrependerTest method testPrependLengthIncludesLengthFieldLength.
@Test
public void testPrependLengthIncludesLengthFieldLength() throws Exception {
final EmbeddedChannel ch = new EmbeddedChannel(new LengthFieldPrepender(4, true));
ch.writeOutbound(msg);
ByteBuf buf = ch.readOutbound();
assertEquals(4, buf.readableBytes());
assertEquals(5, buf.readInt());
buf.release();
buf = ch.readOutbound();
assertSame(buf, msg);
buf.release();
}
use of io.netty.handler.codec.LengthFieldPrepender in project netty by netty.
the class LengthFieldPrependerTest method testPrependAdjustedLength.
@Test
public void testPrependAdjustedLength() throws Exception {
final EmbeddedChannel ch = new EmbeddedChannel(new LengthFieldPrepender(4, -1));
ch.writeOutbound(msg);
ByteBuf buf = ch.readOutbound();
assertEquals(4, buf.readableBytes());
assertEquals(msg.readableBytes() - 1, buf.readInt());
buf.release();
buf = ch.readOutbound();
assertSame(buf, msg);
buf.release();
}
Aggregations