-
Notifications
You must be signed in to change notification settings - Fork 4k
grpc-okhttp: implement OkHttpReadableBuffer readBytes(ByteBuffer dest) #12579
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
grpc-okhttp: implement OkHttpReadableBuffer readBytes(ByteBuffer dest) #12579
Conversation
|
Hi @ejona86 , can you help me reviewing this PR. |
shivaspeaks
left a comment
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.
I don't see there'd be any harm with your PR.
Should we go with something like this to align and be consistent with the rest of the codebase?
@Override
public void readBytes(ByteBuffer dest) {
int remaining = dest.remaining();
try {
int read = buffer.read(dest);
if (read < remaining) {
throw new IndexOutOfBoundsException("EOF trying to read " + remaining + " bytes");
}
} catch (IOException e) {
throw new RuntimeException(e);
}
}
|
Hi @shivaspeaks |
ejona86
left a comment
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.
NAK. I don't mind the implementation, but the reason for the change is very, very bad.
Arrow is using our internals via reflection. This is not okay. Not only is it accessing internal classes, it is digging into its fields. In no way is that acceptable, and in no way are we going to assist in that.
This is an Arrow bug, and that code should be removed in Arrow.
There's no need to dig into our internals for accessing the ByteBuffer (which is what GetReadableBuffer reports to do). We have zero-copy APIs. They can use HasByteBuffer.getByteBuffer()+InputStream.skip() to loop through the ByteBuffers. If they want to access all the byte buffers simultaneously (as skip() will deallocate the last byte buffer, just like read() does), then they can use InputStream.mark(). If they want to take over ownership of the ByteBuffers, then they can use Detachable.detach().
|
Closing in favor of deleting the method. #12580 |
|
Sorry about that. I've opened an issue to get rid of the sketchy code: apache/arrow-java#939 (Albeit, I'd rather recommend people use gRPC directly, I don't think having a gRPC wrapper in our code was really ever a good idea in the first place, but I don't think I can win that battle...) |
Proposed Changes
Changes
readToByteBufferShouldSucceedtest runs for OkHttpReadableBuffer.Additional Information
throw new RuntimeException(e), I'm not sure if this line need to be tested.