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
Replace ByteBufferReadable interface with ManagedBytes, which takes t…
…he responsibility of releasing resources after data access.
  • Loading branch information
voidzcy committed Aug 5, 2020
commit 58165d61a1308ef424f2ccd9055a511dda6a642f
43 changes: 0 additions & 43 deletions api/src/main/java/io/grpc/ByteBufferReadable.java

This file was deleted.

59 changes: 59 additions & 0 deletions api/src/main/java/io/grpc/ManagedBytes.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
/*
* Copyright 2020 The gRPC Authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package io.grpc;

import java.nio.ByteBuffer;
import java.util.List;
import javax.annotation.Nullable;

/**
* A logical representation of bytes with the responsibility of managing the resource lifecycle
* used to hold the data. Usually used for transferring data by directly hand over the ownership
* of the backing resources.
*/
public abstract class ManagedBytes {

/**
* Returns the data in a list of {@link ByteBuffer}s.
*/
public abstract List<ByteBuffer> asByteBuffers();

/**
* Release the usage of the data. The underlying resource used to hold the data may be released
* and no more access should be attempted.
*/
public void release() {
// no-op
}

/**
* A readable data source that supports the operation of reading its content into
* {@link ManagedBytes}.
*/
public interface ManagedBytesReadable {

/**
* Reads up to a total of {@code length} bytes as {@link ManagedBytes}.
*
* @param length the maximum number of bytes to be read.
* @return {@link ManagedBytes} that contains the bytes being read or {@code null}
* if no more bytes can be read.
*/
@Nullable
ManagedBytes readManagedBytes(int length);
}
}