public static int writeArg()

in tchannel-core/src/main/java/com/uber/tchannel/codecs/CodecUtils.java [173:199]


    public static int writeArg(
        @NotNull ByteBufAllocator allocator,
        @NotNull ByteBuf arg,
        int writableBytes,
        @NotNull List<ByteBuf> bufs,
        @NotNull List<ByteBuf> allocatedBufs
    ) {
        if (writableBytes <= TFrame.FRAME_SIZE_LENGTH) {
            throw new UnsupportedOperationException("writableBytes must be larger than " + TFrame.FRAME_SIZE_LENGTH);
        }

        int readableBytes = arg.readableBytes();
        ByteBuf sizeBuf = allocator.buffer(TFrame.FRAME_SIZE_LENGTH);
        allocatedBufs.add(sizeBuf);
        bufs.add(sizeBuf);

        // Write the size of the `arg`
        int headerSize = TFrame.FRAME_SIZE_LENGTH;
        int chunkLength = Math.min(readableBytes + headerSize, writableBytes);
        sizeBuf.writeShort(chunkLength - headerSize);
        if (readableBytes == 0) {
            return TFrame.FRAME_SIZE_LENGTH;
        } else {
            bufs.add(arg.readSlice(chunkLength - headerSize).retain());
            return chunkLength;
        }
    }