-
Notifications
You must be signed in to change notification settings - Fork 274
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
Allow for ByteBufferInputStream to return underlying ByteBuffer #320
Conversation
This helps to avoid a copy if the ByteBufferInpustStream consumer needs to get the contents into a ByteBuffer.
stream4.getByteBuffer()); | ||
byteBuf.rewind(); | ||
ByteBufferInputStream stream5 = new ByteBufferInputStream(byteBuf.duplicate()); | ||
ByteBufferInputStream stream6 = new ByteBufferInputStream(stream5, 1024); |
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.
minor: Can you do byteBuf.remaining()
instead of 1024?
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.
Was just going with the pattern in the rest of this class. Also, I think the hardcoded value makes sense here as that is the source of truth. Using byteBuf.remaining()
might mask issues or catch them later (like if byteBuf
was not rewound).
LGTM |
Made another simple required change that might as well go as part of this patch. Please take a look. |
LGTM |
Merging as per @pnarayanan's comment. @xiahome Please take a look |
@pnarayanan Retained your second commit message since it is useful. |
LGTM. |
This helps to avoid a copy if the
ByteBufferInputStream
consumer needs to get the contents into aByteBuffer
. In particular, this will help avoid a copy when the router needs to convert theByteBufferInputStream
returned byMessageFormat
into aByteBuffer
. Rather than read from this stream into an allocatedByteBuffer
, the underlyingByteBuffer
can be directly used once this patch goes in.Ming, Gopal. ~10 minutes.
Built and tested on Linux and OS X, and formatted.