/** * Return frame {@link FrameType} * * @return frame type */ public FrameType getType() { return FrameHeaderFlyweight.frameType(content); }
public static @Nullable ByteBuf sliceFrameMetadata(final ByteBuf byteBuf) { final FrameType frameType = frameType(byteBuf); final int frameLength = frameLength(byteBuf); final @Nullable Integer metadataLength = metadataLength(byteBuf, frameType, frameLength); if (metadataLength == null) { return null; } int metadataOffset = metadataOffset(byteBuf); if (hasMetadataLengthField(frameType)) { metadataOffset += FRAME_LENGTH_SIZE; } ByteBuf result = Unpooled.EMPTY_BUFFER; if (0 < metadataLength) { result = byteBuf.slice(metadataOffset, metadataLength); } return result; }
public static ByteBuf sliceFrameData(final ByteBuf byteBuf) { final FrameType frameType = frameType(byteBuf); final int frameLength = frameLength(byteBuf); final int dataLength = dataLength(byteBuf, frameType); final int dataOffset = dataOffset(byteBuf, frameType, frameLength); ByteBuf result = Unpooled.EMPTY_BUFFER; if (0 < dataLength) { result = byteBuf.slice(dataOffset, dataLength); } return result; }
@Override public String toString() { FrameType type = FrameHeaderFlyweight.frameType(content); StringBuilder payload = new StringBuilder(); @Nullable ByteBuf metadata = FrameHeaderFlyweight.sliceFrameMetadata(content);
/** * Return frame {@link FrameType} * * @return frame type */ public FrameType getType() { return FrameHeaderFlyweight.frameType(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 @Nullable ByteBuf sliceFrameMetadata(final ByteBuf byteBuf) { final FrameType frameType = frameType(byteBuf); final int frameLength = frameLength(byteBuf); final @Nullable Integer metadataLength = metadataLength(byteBuf, frameType, frameLength); if (metadataLength == null) { return null; } int metadataOffset = metadataOffset(byteBuf); if (hasMetadataLengthField(frameType)) { metadataOffset += FRAME_LENGTH_SIZE; } ByteBuf result = Unpooled.EMPTY_BUFFER; if (0 < metadataLength) { result = byteBuf.slice(metadataOffset, metadataLength); } return result; }
public static ByteBuf sliceFrameData(final ByteBuf byteBuf) { final FrameType frameType = frameType(byteBuf); final int frameLength = frameLength(byteBuf); final int dataLength = dataLength(byteBuf, frameType); final int dataOffset = dataOffset(byteBuf, frameType, frameLength); ByteBuf result = Unpooled.EMPTY_BUFFER; if (0 < dataLength) { result = byteBuf.slice(dataOffset, dataLength); } return result; }
@Override public String toString() { FrameType type = FrameHeaderFlyweight.frameType(content); StringBuilder payload = new StringBuilder(); @Nullable ByteBuf metadata = FrameHeaderFlyweight.sliceFrameMetadata(content);