Skip to content

Conversation

shangm2
Copy link

@shangm2 shangm2 commented Aug 18, 2025

  1. Add support to tBinaryProtocol to write from or read to a list of pooled byte buffers


public void release(ByteBuffer byteBuffer)
{
byteBuffer.clear();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: maybe check if the buffer is of expected size

this.bufferSize = bufferSize;
pool = new ArrayBlockingQueue<>(maxCount);

// Pre-populate the pool
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: Is probably okay to populate lazily

private final ArrayBlockingQueue<ByteBuffer> pool;
private final int bufferSize;

private static final AtomicInteger idGenerator = new AtomicInteger();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: unused

@@ -210,6 +213,21 @@ public void writeBinary(ByteBuffer value)
transport.write(value.array(), value.position() + value.arrayOffset(), length);
}

@Override
public void writeBinaryFromBuffers(List<ByteBuffer> byteBuffers)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: maybe simply writeBinary

return Collections.emptyList();
}

List<ByteBuffer> byteBuffers = new ArrayList<>();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: prefer ImutableList (e.g.: ImmutableList.builder())

default void writeBinaryFromBuffers(List<ByteBuffer> byteBuffers)
throws TException
{
throw new UnsupportedOperationException("writeBinaryFromBuffers is not supported");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ditto

import java.nio.ByteBuffer;
import java.util.List;

public class ByteBufferInputStream
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please cover it with a unit test well. Or consider ByteSource from Guava (e.g.: ByteSource#concat)

private final List<ByteBuffer> byteBuffers;
private ByteBuffer currentBuffer;

public ByteBufferOutputStream(ByteBufferPool pool, List<ByteBuffer> byteBuffers)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider creating the List<ByteBuffer> byteBuffers here and returning it from a method (e.g.: List getBytes())

private final List<ByteBuffer> byteBuffers;
private ByteBuffer currentBuffer;

public ByteBufferOutputStream(ByteBufferPool pool, List<ByteBuffer> byteBuffers)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also please add a unit test.

}
}

public void finish()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

e.g.: Return a List from here

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants