public static int encode(final ByteBuf byteBuf, final int streamId, final int requestN) { final int frameLength = computeFrameLength(); int length = FrameHeaderFlyweight.encodeFrameHeader( byteBuf, frameLength, 0, FrameType.REQUEST_N, streamId); byteBuf.setInt(REQUEST_N_FIELD_OFFSET, requestN); return length + Integer.BYTES; }
public static int encode( final ByteBuf byteBuf, final int streamId, final int errorCode, final ByteBuf data) { final int frameLength = computeFrameLength(data.readableBytes()); int length = FrameHeaderFlyweight.encodeFrameHeader(byteBuf, frameLength, 0, FrameType.ERROR, streamId); byteBuf.setInt(ERROR_CODE_FIELD_OFFSET, errorCode); length += Integer.BYTES; length += FrameHeaderFlyweight.encodeData(byteBuf, length, data); return length; }
public static int encode(final ByteBuf byteBuf, int flags, final ByteBuf data) { final int frameLength = computeFrameLength(data.readableBytes()); int length = FrameHeaderFlyweight.encodeFrameHeader(byteBuf, frameLength, flags, FrameType.KEEPALIVE, 0); // We don't support resumability, last position is always zero byteBuf.setLong(length, 0); length += Long.BYTES; length += FrameHeaderFlyweight.encodeData(byteBuf, length, data); return length; }
@Test(expected = IllegalArgumentException.class) public void headerSizeTooLarge() { FrameHeaderFlyweight.encodeFrameHeader(byteBuf, FRAME_MAX_SIZE + 1, 0, FrameType.SETUP, 0); }
public static int encode( final ByteBuf byteBuf, final int ttl, final int numRequests, final ByteBuf metadata) { final int frameLength = computeFrameLength(metadata.readableBytes()); int length = FrameHeaderFlyweight.encodeFrameHeader(byteBuf, frameLength, 0, FrameType.LEASE, 0); byteBuf.setInt(TTL_FIELD_OFFSET, ttl); byteBuf.setInt(NUM_REQUESTS_FIELD_OFFSET, numRequests); length += Integer.BYTES * 2; length += FrameHeaderFlyweight.encodeMetadata(byteBuf, FrameType.LEASE, length, metadata); return length; }
public static int encode( final ByteBuf byteBuf, final int streamId, final int flags, final FrameType type, final @Nullable ByteBuf metadata, final ByteBuf data) { if (Frame.isFlagSet(flags, FrameHeaderFlyweight.FLAGS_M) != (metadata != null)) { throw new IllegalArgumentException("metadata flag set incorrectly"); } if (type.hasInitialRequestN()) { throw new AssertionError(type + " must not be encoded without initial request N"); } final int frameLength = computeFrameLength( type, metadata != null ? metadata.readableBytes() : null, data.readableBytes()); int length = FrameHeaderFlyweight.encodeFrameHeader(byteBuf, frameLength, flags, type, streamId); length += FrameHeaderFlyweight.encodeMetadata(byteBuf, type, length, metadata); length += FrameHeaderFlyweight.encodeData(byteBuf, length, data); return length; }
public static int encode( final ByteBuf byteBuf, final int streamId, int flags, final FrameType type, final int initialRequestN, final @Nullable ByteBuf metadata, final ByteBuf data) { if (Frame.isFlagSet(flags, FrameHeaderFlyweight.FLAGS_M) != (metadata != null)) { throw new IllegalArgumentException("metadata flag set incorrectly"); } final int frameLength = computeFrameLength( type, metadata != null ? metadata.readableBytes() : null, data.readableBytes()); int length = FrameHeaderFlyweight.encodeFrameHeader(byteBuf, frameLength, flags, type, streamId); byteBuf.setInt(INITIAL_REQUEST_N_FIELD_OFFSET, initialRequestN); length += Integer.BYTES; length += FrameHeaderFlyweight.encodeMetadata(byteBuf, type, length, metadata); length += FrameHeaderFlyweight.encodeData(byteBuf, length, data); return length; }
int length = encodeFrameHeader(byteBuf, frameLength, flags, outFrameType, streamId);
@Test public void headerSize() { int frameLength = 123456; FrameHeaderFlyweight.encodeFrameHeader(byteBuf, frameLength, 0, FrameType.SETUP, 0); assertEquals(frameLength, FrameHeaderFlyweight.frameLength(byteBuf)); }
@Test public void headerSizeMax() { int frameLength = FRAME_MAX_SIZE; FrameHeaderFlyweight.encodeFrameHeader(byteBuf, frameLength, 0, FrameType.SETUP, 0); assertEquals(frameLength, FrameHeaderFlyweight.frameLength(byteBuf)); }
FrameHeaderFlyweight.encodeFrameHeader(byteBuf, frameLength, flags, FrameType.SETUP, 0);
public static int encode(final ByteBuf byteBuf, final int streamId, final int requestN) { final int frameLength = computeFrameLength(); int length = FrameHeaderFlyweight.encodeFrameHeader( byteBuf, frameLength, 0, FrameType.REQUEST_N, streamId); byteBuf.setInt(REQUEST_N_FIELD_OFFSET, requestN); return length + Integer.BYTES; }
public static int encode( final ByteBuf byteBuf, final int streamId, final int errorCode, final ByteBuf data) { final int frameLength = computeFrameLength(data.readableBytes()); int length = FrameHeaderFlyweight.encodeFrameHeader(byteBuf, frameLength, 0, FrameType.ERROR, streamId); byteBuf.setInt(ERROR_CODE_FIELD_OFFSET, errorCode); length += Integer.BYTES; length += FrameHeaderFlyweight.encodeData(byteBuf, length, data); return length; }
public static int encode(final ByteBuf byteBuf, int flags, final ByteBuf data) { final int frameLength = computeFrameLength(data.readableBytes()); int length = FrameHeaderFlyweight.encodeFrameHeader(byteBuf, frameLength, flags, FrameType.KEEPALIVE, 0); // We don't support resumability, last position is always zero byteBuf.setLong(length, 0); length += Long.BYTES; length += FrameHeaderFlyweight.encodeData(byteBuf, length, data); return length; }
public static int encode( final ByteBuf byteBuf, final int ttl, final int numRequests, final ByteBuf metadata) { final int frameLength = computeFrameLength(metadata.readableBytes()); int length = FrameHeaderFlyweight.encodeFrameHeader(byteBuf, frameLength, 0, FrameType.LEASE, 0); byteBuf.setInt(TTL_FIELD_OFFSET, ttl); byteBuf.setInt(NUM_REQUESTS_FIELD_OFFSET, numRequests); length += Integer.BYTES * 2; length += FrameHeaderFlyweight.encodeMetadata(byteBuf, FrameType.LEASE, length, metadata); return length; }
public static int encode( final ByteBuf byteBuf, final int streamId, final int flags, final FrameType type, final @Nullable ByteBuf metadata, final ByteBuf data) { if (Frame.isFlagSet(flags, FrameHeaderFlyweight.FLAGS_M) != (metadata != null)) { throw new IllegalArgumentException("metadata flag set incorrectly"); } if (type.hasInitialRequestN()) { throw new AssertionError(type + " must not be encoded without initial request N"); } final int frameLength = computeFrameLength( type, metadata != null ? metadata.readableBytes() : null, data.readableBytes()); int length = FrameHeaderFlyweight.encodeFrameHeader(byteBuf, frameLength, flags, type, streamId); length += FrameHeaderFlyweight.encodeMetadata(byteBuf, type, length, metadata); length += FrameHeaderFlyweight.encodeData(byteBuf, length, data); return length; }
public static int encode( final ByteBuf byteBuf, final int streamId, int flags, final FrameType type, final int initialRequestN, final @Nullable ByteBuf metadata, final ByteBuf data) { if (Frame.isFlagSet(flags, FrameHeaderFlyweight.FLAGS_M) != (metadata != null)) { throw new IllegalArgumentException("metadata flag set incorrectly"); } final int frameLength = computeFrameLength( type, metadata != null ? metadata.readableBytes() : null, data.readableBytes()); int length = FrameHeaderFlyweight.encodeFrameHeader(byteBuf, frameLength, flags, type, streamId); byteBuf.setInt(INITIAL_REQUEST_N_FIELD_OFFSET, initialRequestN); length += Integer.BYTES; length += FrameHeaderFlyweight.encodeMetadata(byteBuf, type, length, metadata); length += FrameHeaderFlyweight.encodeData(byteBuf, length, data); return length; }
int length = encodeFrameHeader(byteBuf, frameLength, flags, outFrameType, streamId);
FrameHeaderFlyweight.encodeFrameHeader(byteBuf, frameLength, flags, FrameType.SETUP, 0);