Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
18 commits
Select commit Hold shift + click to select a range
c8810ad
Define an interface for retrieving a list of ByteBuffers.
voidzcy Jul 24, 2020
17d6dbb
Add methods to ReadableBuffer to support returning read bytes via Byt…
voidzcy Jul 24, 2020
83f0448
CompositeReadableBuffer's implementation for reading by returning Byt…
voidzcy Jul 24, 2020
69a1ddf
NettyReadableBuffer's implementation for reading by directly returnin…
voidzcy Jul 24, 2020
88d2b6f
Deframer gives an InputStream if the backing ReadableBuffer supports …
voidzcy Jul 24, 2020
94b5124
Feed a list of ByteBuffers into protobuf if the InputStream implement…
voidzcy Jul 24, 2020
ce8969e
Fix readByteBuffers operation for CompositeReadableBuffer.
voidzcy Aug 4, 2020
a16b6ae
Improve ByteBuffer read for netty.
voidzcy Aug 4, 2020
0cb6ea8
update interface for getting a list of ByteBuffers.
voidzcy Aug 4, 2020
f9aaffc
Improve feeding ByteBuffer to protobuf.
voidzcy Aug 4, 2020
8a0c7a2
Should not close ReadableBuffer before reading the returned ByteBuffe…
voidzcy Aug 4, 2020
8fb4534
Add TODO for remembering current implementation leaks buffer.
voidzcy Aug 4, 2020
58165d6
Replace ByteBufferReadable interface with ManagedBytes, which takes t…
voidzcy Aug 5, 2020
e2b3991
Add api for reading data as ManagedBytes from ReadableBuffer.
voidzcy Aug 5, 2020
8959de5
Implement reading via ManagedBytes for netty.
voidzcy Aug 5, 2020
86414ad
Implement reading via ManagedBytes for composite.
voidzcy Aug 5, 2020
093e435
Change stream to use ManagedBytes for data transfer.
voidzcy Aug 5, 2020
c9c123c
Use new ManagedBufferReadable api to transfer data into protobuf and …
voidzcy Aug 5, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Add methods to ReadableBuffer to support returning read bytes via Byt…
…eBuffers.
  • Loading branch information
voidzcy committed Jul 24, 2020
commit 17d6dbb973ab54d11a085c91093ea50e8c2429a4
13 changes: 13 additions & 0 deletions core/src/main/java/io/grpc/internal/AbstractReadableBuffer.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@

package io.grpc.internal;

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

/**
* Abstract base class for {@link ReadableBuffer} implementations.
*/
Expand All @@ -30,6 +33,16 @@ public final int readInt() {
return (b1 << 24) | (b2 << 16) | (b3 << 8) | b4;
}

@Override
public boolean shouldUseByteBuffer() {
return false;
}

@Override
public List<ByteBuffer> readByteBuffers(int length) {
throw new UnsupportedOperationException();
}

@Override
public boolean hasArray() {
return false;
Expand Down
11 changes: 11 additions & 0 deletions core/src/main/java/io/grpc/internal/ForwardingReadableBuffer.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import java.io.IOException;
import java.io.OutputStream;
import java.nio.ByteBuffer;
import java.util.List;

/**
* Base class for a wrapper around another {@link ReadableBuffer}.
Expand Down Expand Up @@ -81,6 +82,16 @@ public ReadableBuffer readBytes(int length) {
return buf.readBytes(length);
}

@Override
public boolean shouldUseByteBuffer() {
return buf.shouldUseByteBuffer();
}

@Override
public List<ByteBuffer> readByteBuffers(int length) {
return buf.readByteBuffers(length);
}

@Override
public boolean hasArray() {
return buf.hasArray();
Expand Down
17 changes: 17 additions & 0 deletions core/src/main/java/io/grpc/internal/ReadableBuffer.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import java.io.IOException;
import java.io.OutputStream;
import java.nio.ByteBuffer;
import java.util.List;

/**
* Interface for an abstract byte buffer. Buffers are intended to be a read-only, except for the
Expand Down Expand Up @@ -102,6 +103,22 @@ public interface ReadableBuffer extends Closeable {
*/
ReadableBuffer readBytes(int length);

/**
* Indicates whether or not this buffer supports {@link #readByteBuffers} operation that returns
* buffer's content as {@link ByteBuffer}s without making an extra copy.
*/
boolean shouldUseByteBuffer();

/**
* Reads {@code length} bytes as {@link ByteBuffer}s. This is an optional method, so callers
* should first check {@link #shouldUseByteBuffer}.
*
* @param length the total number of bytes to contain in the returned {@link ByteBuffer}s.
* @throws UnsupportedOperationException the buffer does not support this method
* @throws IndexOutOfBoundsException if required bytes are not readable
*/
List<ByteBuffer> readByteBuffers(int length);
Copy link
Contributor

Choose a reason for hiding this comment

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

How about just returning null here instead of separate boolean method? This would also be more efficient for composite case since it means not having to iterate over the buffers an additional time.


/**
* Indicates whether or not this buffer exposes a backing array.
*/
Expand Down