Source:
<code>static ByteBuf encodeFirstFragment( ByteBufAllocator allocator, int mtu, ByteBuf frame, FrameType frameType, int streamId, ByteBuf metadata, ByteBuf data) { int remaining = mtu - FrameHeaderFlyweight.size(); switch (frameType) { case REQUEST_STREAM: case REQUEST_CHANNEL: remaining -= Integer.BYTES; break; default: } ByteBuf metadataFragment = null; if (metadata.isReadable()) { remaining -= 3; int r = Math.min(remaining, metadata.readableBytes()); remaining -= r; metadataFragment = metadata.readRetainedSlice(r); } ByteBuf dataFragment = Unpooled.EMPTY_BUFFER; if (remaining > 0 && data.isReadable()) { int r = Math.min(remaining, data.readableBytes()); dataFragment = data.readRetainedSlice(r); } switch (frameType) { case REQUEST_FNF: return RequestFireAndForgetFrameFlyweight.encode( allocator, streamId, true, metadataFragment, dataFragment); case REQUEST_STREAM: return RequestStreamFrameFlyweight.encode( allocator, streamId, true, RequestStreamFrameFlyweight.initialRequestN(frame), metadataFragment, dataFragment); case REQUEST_RESPONSE: return RequestResponseFrameFlyweight.encode( allocator, streamId, true, metadataFragment, dataFragment); case REQUEST_CHANNEL: return RequestChannelFrameFlyweight.encode( allocator, streamId, true, false, RequestChannelFrameFlyweight.initialRequestN(frame), metadataFragment, dataFragment); case PAYLOAD: return PayloadFrameFlyweight.encode( allocator, streamId, true, false, false, metadataFragment, dataFragment); case NEXT: return PayloadFrameFlyweight.encode( allocator, streamId, true, false, true, metadataFragment, dataFragment); case NEXT_COMPLETE: return PayloadFrameFlyweight.encode( allocator, streamId, true, true, true, metadataFragment, dataFragment); case COMPLETE: return PayloadFrameFlyweight.encode( allocator, streamId, true, true, false, metadataFragment, dataFragment); default: <START> throw new IllegalStateException("unsupported fragment type"); <END> } }</code><technical_language>nit: useful include frameType in message</technical_language>

Target:
static ByteBuf encodeFirstFragment( ByteBufAllocator allocator, int mtu, ByteBuf frame, FrameType frameType, int streamId, ByteBuf metadata, ByteBuf data) { int remaining = mtu - FrameHeaderFlyweight.size(); switch (frameType) { case REQUEST_STREAM: case REQUEST_CHANNEL: remaining -= Integer.BYTES; break; default: } ByteBuf metadataFragment = null; if (metadata.isReadable()) { remaining -= 3; int r = Math.min(remaining, metadata.readableBytes()); remaining -= r; metadataFragment = metadata.readRetainedSlice(r); } ByteBuf dataFragment = Unpooled.EMPTY_BUFFER; if (remaining > 0 && data.isReadable()) { int r = Math.min(remaining, data.readableBytes()); dataFragment = data.readRetainedSlice(r); } switch (frameType) { case REQUEST_FNF: return RequestFireAndForgetFrameFlyweight.encode( allocator, streamId, true, metadataFragment, dataFragment); case REQUEST_STREAM: return RequestStreamFrameFlyweight.encode( allocator, streamId, true, RequestStreamFrameFlyweight.initialRequestN(frame), metadataFragment, dataFragment); case REQUEST_RESPONSE: return RequestResponseFrameFlyweight.encode( allocator, streamId, true, metadataFragment, dataFragment); case REQUEST_CHANNEL: return RequestChannelFrameFlyweight.encode( allocator, streamId, true, false, RequestChannelFrameFlyweight.initialRequestN(frame), metadataFragment, dataFragment); case PAYLOAD: return PayloadFrameFlyweight.encode( allocator, streamId, true, false, false, metadataFragment, dataFragment); case NEXT: return PayloadFrameFlyweight.encode( allocator, streamId, true, false, true, metadataFragment, dataFragment); case NEXT_COMPLETE: return PayloadFrameFlyweight.encode( allocator, streamId, true, true, true, metadataFragment, dataFragment); case COMPLETE: return PayloadFrameFlyweight.encode( allocator, streamId, true, true, false, metadataFragment, dataFragment); default: throw new IllegalStateException("unsupported fragment type: " + frameType); } }