-
Notifications
You must be signed in to change notification settings - Fork 48
Add support to thrift serde with pooled bytebuffer #123
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Conversation
shangm2
commented
Aug 18, 2025
- Add support to tBinaryProtocol to write from or read to a list of pooled byte buffers
|
||
public void release(ByteBuffer byteBuffer) | ||
{ | ||
byteBuffer.clear(); |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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(); |
There was a problem hiding this comment.
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) |
There was a problem hiding this comment.
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<>(); |
There was a problem hiding this comment.
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"); |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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) |
There was a problem hiding this comment.
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) |
There was a problem hiding this comment.
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() |
There was a problem hiding this comment.
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