public static Frame from(int ttl, int numberOfRequests, ByteBuf metadata) { final Frame frame = RECYCLER.get(); frame.setRefCnt(1); frame.content = ByteBufAllocator.DEFAULT.buffer( LeaseFrameFlyweight.computeFrameLength(metadata.readableBytes())); frame.content.writerIndex( LeaseFrameFlyweight.encode(frame.content, ttl, numberOfRequests, metadata)); return frame; }
@Test public void size() { ByteBuf metadata = Unpooled.wrappedBuffer(new byte[] {1, 2, 3, 4}); int length = LeaseFrameFlyweight.encode(byteBuf, 0, 0, metadata); assertEquals(length, 9 + 4 * 2 + 4); // Frame header + ttl + #requests + 4 byte metadata }
@Test public void testEncoding() { int encoded = LeaseFrameFlyweight.encode( byteBuf, 0, 0, Unpooled.copiedBuffer("md", StandardCharsets.UTF_8)); assertEquals( "00001000000000090000000000000000006d64", ByteBufUtil.hexDump(byteBuf, 0, encoded)); } }
public static Frame from(int ttl, int numberOfRequests, ByteBuf metadata) { final Frame frame = RECYCLER.get(); frame.setRefCnt(1); frame.content = ByteBufAllocator.DEFAULT.buffer( LeaseFrameFlyweight.computeFrameLength(metadata.readableBytes())); frame.content.writerIndex( LeaseFrameFlyweight.encode(frame.content, ttl, numberOfRequests, metadata)); return frame; }