/** * Return {@link ByteBuf} that is a {@link ByteBuf#slice()} for the frame data * * <p>If no data is present, the ByteBuf will have 0 capacity. * * @return ByteBuf containing the data */ public ByteBuf sliceData() { return FrameHeaderFlyweight.sliceFrameData(content); }
public static String message(ByteBuf content) { return FrameHeaderFlyweight.sliceFrameData(content).toString(StandardCharsets.UTF_8); } }
@Test public void dataSlice() { ByteBuf data = Unpooled.wrappedBuffer(new byte[] {1, 2, 3, 4, 5}); FrameHeaderFlyweight.encode( byteBuf, 0, FLAGS_M, FrameType.REQUEST_RESPONSE, Unpooled.EMPTY_BUFFER, data); data.resetReaderIndex(); assertEquals(data, FrameHeaderFlyweight.sliceFrameData(byteBuf)); }
@Test public void canReadData() { ByteBuf data = Unpooled.wrappedBuffer(new byte[] {5, 4, 3}); int length = KeepaliveFrameFlyweight.encode(byteBuf, KeepaliveFrameFlyweight.FLAGS_KEEPALIVE_R, data); data.resetReaderIndex(); assertEquals( KeepaliveFrameFlyweight.FLAGS_KEEPALIVE_R, FrameHeaderFlyweight.flags(byteBuf) & KeepaliveFrameFlyweight.FLAGS_KEEPALIVE_R); assertEquals(data, FrameHeaderFlyweight.sliceFrameData(byteBuf)); }
ByteBuf data = FrameHeaderFlyweight.sliceFrameData(content); if (0 < data.readableBytes()) { payload.append(String.format("data: \"%s\" ", data.toString(StandardCharsets.UTF_8)));
/** * Return {@link ByteBuf} that is a {@link ByteBuf#slice()} for the frame data * * <p>If no data is present, the ByteBuf will have 0 capacity. * * @return ByteBuf containing the data */ public ByteBuf sliceData() { return FrameHeaderFlyweight.sliceFrameData(content); }
@Test public void validFrame() { ByteBuf metadata = Unpooled.wrappedBuffer(new byte[] {1, 2, 3, 4}); ByteBuf data = Unpooled.wrappedBuffer(new byte[] {5, 4, 3}); SetupFrameFlyweight.encode(byteBuf, 0, 5, 500, "metadata_type", "data_type", metadata, data); metadata.resetReaderIndex(); data.resetReaderIndex(); assertEquals(FrameType.SETUP, FrameHeaderFlyweight.frameType(byteBuf)); assertEquals("metadata_type", SetupFrameFlyweight.metadataMimeType(byteBuf)); assertEquals("data_type", SetupFrameFlyweight.dataMimeType(byteBuf)); assertEquals(metadata, FrameHeaderFlyweight.sliceFrameMetadata(byteBuf)); assertEquals(data, FrameHeaderFlyweight.sliceFrameData(byteBuf)); }
@Test public void validResumeFrame() { ByteBuf token = Unpooled.wrappedBuffer(new byte[] {2, 3}); ByteBuf metadata = Unpooled.wrappedBuffer(new byte[] {1, 2, 3, 4}); ByteBuf data = Unpooled.wrappedBuffer(new byte[] {5, 4, 3}); SetupFrameFlyweight.encode( byteBuf, SetupFrameFlyweight.FLAGS_RESUME_ENABLE, 5, 500, token, "metadata_type", "data_type", metadata, data); token.resetReaderIndex(); metadata.resetReaderIndex(); data.resetReaderIndex(); assertEquals(FrameType.SETUP, FrameHeaderFlyweight.frameType(byteBuf)); assertEquals("metadata_type", SetupFrameFlyweight.metadataMimeType(byteBuf)); assertEquals("data_type", SetupFrameFlyweight.dataMimeType(byteBuf)); assertEquals(metadata, FrameHeaderFlyweight.sliceFrameMetadata(byteBuf)); assertEquals(data, FrameHeaderFlyweight.sliceFrameData(byteBuf)); assertEquals( SetupFrameFlyweight.FLAGS_RESUME_ENABLE, FrameHeaderFlyweight.flags(byteBuf) & SetupFrameFlyweight.FLAGS_RESUME_ENABLE); }
public static String message(ByteBuf content) { return FrameHeaderFlyweight.sliceFrameData(content).toString(StandardCharsets.UTF_8); } }
ByteBuf data = FrameHeaderFlyweight.sliceFrameData(content); if (0 < data.readableBytes()) { payload.append(String.format("data: \"%s\" ", data.toString(StandardCharsets.UTF_8)));