private static final class CodedInputStream.IterableDirectByteBufferDecoder extends CodedInputStream
CodedInputStream
that uses an
as the
data source. Requires the use of sun.misc.Unsafe
to perform fast reads on the buffer.Modifier and Type | Field and Description |
---|---|
private int |
bufferSizeAfterCurrentLimit
The amount of available data in the input beyond
currentLimit . |
private long |
currentAddress
If the current ByteBuffer is unsafe-direct based, currentAddress is the start address of this
ByteBuffer; otherwise should be zero.
|
private java.nio.ByteBuffer |
currentByteBuffer
The current ByteBuffer;
|
private long |
currentByteBufferLimit
The limit position for current ByteBuffer
|
private long |
currentByteBufferPos
The current position for current ByteBuffer
|
private long |
currentByteBufferStartPos |
private int |
currentLimit
The absolute position of the end of the current message.
|
private boolean |
enableAliasing
If
true , indicates that calls to read ByteString or byte[]
may return slices of the underlying buffer, rather than copies. |
private boolean |
immutable
If
true , indicates that all the buffer are backing a ByteString and are
therefore considered to be an immutable input source. |
private java.lang.Iterable<java.nio.ByteBuffer> |
input
The object that need to decode.
|
private java.util.Iterator<java.nio.ByteBuffer> |
iterator
The
Iterator with type ByteBuffer of input |
private int |
lastTag
The last tag that was read from this stream.
|
private int |
startOffset
The start position offset of the whole message, used as to reset the totalBytesRead
|
private int |
totalBufferSize
The global total message length limit
|
private int |
totalBytesRead
Total Bytes have been Read from the
Iterable ByteBuffer |
recursionDepth, recursionLimit, sizeLimit
Modifier | Constructor and Description |
---|---|
private |
IterableDirectByteBufferDecoder(java.lang.Iterable<java.nio.ByteBuffer> inputBufs,
int size,
boolean immutableFlag)
The constructor of
Iterable<ByteBuffer> decoder. |
Modifier and Type | Method and Description |
---|---|
void |
checkLastTagWas(int value)
Verifies that the last call to readTag() returned the given tag value.
|
private long |
currentRemaining()
Try to get the number of remaining bytes in
currentByteBuffer . |
void |
enableAliasing(boolean enabled)
Enables
ByteString aliasing of the underlying buffer, trading off on buffer pinning for
data copies. |
int |
getBytesUntilLimit()
Returns the number of bytes to be read before the current limit.
|
int |
getLastTag() |
private void |
getNextByteBuffer()
To get the next ByteBuffer from
input , and then update the parameters |
int |
getTotalBytesRead()
The total bytes read up to the current position.
|
boolean |
isAtEnd()
Returns true if the stream has reached the end of the input.
|
void |
popLimit(int oldLimit)
Discards the current limit, returning to the previous limit.
|
int |
pushLimit(int byteLimit)
Sets
currentLimit to (current position) + byteLimit . |
boolean |
readBool()
Read a
bool field value from the stream. |
byte[] |
readByteArray()
Read a
bytes field value from the stream. |
java.nio.ByteBuffer |
readByteBuffer()
Read a
bytes field value from the stream. |
ByteString |
readBytes()
Read a
bytes field value from the stream. |
double |
readDouble()
Read a
double field value from the stream. |
int |
readEnum()
Read an enum field value from the stream.
|
int |
readFixed32()
Read a
fixed32 field value from the stream. |
long |
readFixed64()
Read a
fixed64 field value from the stream. |
float |
readFloat()
Read a
float field value from the stream. |
void |
readGroup(int fieldNumber,
MessageLite.Builder builder,
ExtensionRegistryLite extensionRegistry)
Read a
group field value from the stream. |
<T extends MessageLite> |
readGroup(int fieldNumber,
Parser<T> parser,
ExtensionRegistryLite extensionRegistry)
Read a
group field value from the stream. |
int |
readInt32()
Read an
int32 field value from the stream. |
long |
readInt64()
Read an
int64 field value from the stream. |
void |
readMessage(MessageLite.Builder builder,
ExtensionRegistryLite extensionRegistry)
Read an embedded message field value from the stream.
|
<T extends MessageLite> |
readMessage(Parser<T> parser,
ExtensionRegistryLite extensionRegistry)
Read an embedded message field value from the stream.
|
byte |
readRawByte()
Read one byte from the input.
|
byte[] |
readRawBytes(int length)
Read a fixed size of bytes from the input.
|
private void |
readRawBytesTo(byte[] bytes,
int offset,
int length)
Try to get raw bytes from
input with the size of length and copy to bytes array. |
int |
readRawLittleEndian32()
Read a 32-bit little-endian integer from the stream.
|
long |
readRawLittleEndian64()
Read a 64-bit little-endian integer from the stream.
|
int |
readRawVarint32()
Read a raw Varint from the stream.
|
long |
readRawVarint64()
Read a raw Varint from the stream.
|
(package private) long |
readRawVarint64SlowPath()
Variant of readRawVarint64 for when uncomfortably close to the limit.
|
int |
readSFixed32()
Read an
sfixed32 field value from the stream. |
long |
readSFixed64()
Read an
sfixed64 field value from the stream. |
int |
readSInt32()
Read an
sint32 field value from the stream. |
long |
readSInt64()
Read an
sint64 field value from the stream. |
java.lang.String |
readString()
Read a
string field value from the stream. |
java.lang.String |
readStringRequireUtf8()
Read a
string field value from the stream. |
int |
readTag()
Attempt to read a field tag, returning zero if we have reached EOF.
|
int |
readUInt32()
Read a
uint32 field value from the stream. |
long |
readUInt64()
Read a
uint64 field value from the stream. |
void |
readUnknownGroup(int fieldNumber,
MessageLite.Builder builder)
Deprecated.
|
private void |
recomputeBufferSizeAfterLimit() |
private int |
remaining()
Try to get the number of remaining bytes in
input . |
void |
resetSizeCounter()
Resets the current size counter to zero (see
CodedInputStream.setSizeLimit(int) ). |
boolean |
skipField(int tag)
Reads and discards a single field, given its tag value.
|
boolean |
skipField(int tag,
CodedOutputStream output)
Reads a single field and writes it to output in wire format, given its tag value.
|
void |
skipMessage()
Reads and discards an entire message.
|
void |
skipMessage(CodedOutputStream output)
Reads an entire message and writes it to output in wire format.
|
void |
skipRawBytes(int length)
Reads and discards
size bytes. |
private void |
skipRawVarint() |
private java.nio.ByteBuffer |
slice(int begin,
int end) |
private void |
tryGetNextByteBuffer() |
decodeZigZag32, decodeZigZag64, discardUnknownFields, getProto3DiscardUnknownFieldsDefault, newInstance, newInstance, newInstance, newInstance, newInstance, newInstance, newInstance, newInstance, newInstance, readRawVarint32, readRawVarint32, setProto3DiscardUnknownsByDefaultForTest, setProto3KeepUnknownsByDefaultForTest, setRecursionLimit, setSizeLimit, shouldDiscardUnknownFields, shouldDiscardUnknownFieldsProto3, unsetDiscardUnknownFields
private java.lang.Iterable<java.nio.ByteBuffer> input
private java.util.Iterator<java.nio.ByteBuffer> iterator
Iterator
with type ByteBuffer
of input
private java.nio.ByteBuffer currentByteBuffer
private boolean immutable
true
, indicates that all the buffer are backing a ByteString
and are
therefore considered to be an immutable input source.private boolean enableAliasing
true
, indicates that calls to read ByteString
or byte[]
may return slices of the underlying buffer, rather than copies.private int totalBufferSize
private int bufferSizeAfterCurrentLimit
currentLimit
.private int currentLimit
private int lastTag
private int totalBytesRead
Iterable
ByteBuffer
private int startOffset
private long currentByteBufferPos
private long currentByteBufferStartPos
private long currentAddress
private long currentByteBufferLimit
private IterableDirectByteBufferDecoder(java.lang.Iterable<java.nio.ByteBuffer> inputBufs, int size, boolean immutableFlag)
Iterable<ByteBuffer>
decoder.inputBufs
- The input data.size
- The total size of the input data.immutableFlag
- whether the input data is immutable.private void getNextByteBuffer() throws InvalidProtocolBufferException
input
, and then update the parametersInvalidProtocolBufferException
private void tryGetNextByteBuffer()
public int readTag() throws java.io.IOException
CodedInputStream
readTag
in class CodedInputStream
java.io.IOException
public void checkLastTagWas(int value) throws InvalidProtocolBufferException
CodedInputStream
checkLastTagWas
in class CodedInputStream
InvalidProtocolBufferException
- value
does not match the last tag.public int getLastTag()
getLastTag
in class CodedInputStream
public boolean skipField(int tag) throws java.io.IOException
CodedInputStream
skipField
in class CodedInputStream
false
if the tag is an endgroup tag, in which case nothing is skipped.
Otherwise, returns true
.java.io.IOException
public boolean skipField(int tag, CodedOutputStream output) throws java.io.IOException
CodedInputStream
skipField
in class CodedInputStream
false
if the tag is an endgroup tag, in which case nothing is skipped.
Otherwise, returns true
.java.io.IOException
public void skipMessage() throws java.io.IOException
CodedInputStream
skipMessage
in class CodedInputStream
java.io.IOException
public void skipMessage(CodedOutputStream output) throws java.io.IOException
CodedInputStream
skipMessage
in class CodedInputStream
java.io.IOException
public double readDouble() throws java.io.IOException
CodedInputStream
double
field value from the stream.readDouble
in class CodedInputStream
java.io.IOException
public float readFloat() throws java.io.IOException
CodedInputStream
float
field value from the stream.readFloat
in class CodedInputStream
java.io.IOException
public long readUInt64() throws java.io.IOException
CodedInputStream
uint64
field value from the stream.readUInt64
in class CodedInputStream
java.io.IOException
public long readInt64() throws java.io.IOException
CodedInputStream
int64
field value from the stream.readInt64
in class CodedInputStream
java.io.IOException
public int readInt32() throws java.io.IOException
CodedInputStream
int32
field value from the stream.readInt32
in class CodedInputStream
java.io.IOException
public long readFixed64() throws java.io.IOException
CodedInputStream
fixed64
field value from the stream.readFixed64
in class CodedInputStream
java.io.IOException
public int readFixed32() throws java.io.IOException
CodedInputStream
fixed32
field value from the stream.readFixed32
in class CodedInputStream
java.io.IOException
public boolean readBool() throws java.io.IOException
CodedInputStream
bool
field value from the stream.readBool
in class CodedInputStream
java.io.IOException
public java.lang.String readString() throws java.io.IOException
CodedInputStream
string
field value from the stream. If the stream contains malformed UTF-8,
replace the offending bytes with the standard UTF-8 replacement character.readString
in class CodedInputStream
java.io.IOException
public java.lang.String readStringRequireUtf8() throws java.io.IOException
CodedInputStream
string
field value from the stream. If the stream contains malformed UTF-8,
throw exception InvalidProtocolBufferException
.readStringRequireUtf8
in class CodedInputStream
java.io.IOException
public void readGroup(int fieldNumber, MessageLite.Builder builder, ExtensionRegistryLite extensionRegistry) throws java.io.IOException
CodedInputStream
group
field value from the stream.readGroup
in class CodedInputStream
java.io.IOException
public <T extends MessageLite> T readGroup(int fieldNumber, Parser<T> parser, ExtensionRegistryLite extensionRegistry) throws java.io.IOException
CodedInputStream
group
field value from the stream.readGroup
in class CodedInputStream
java.io.IOException
@Deprecated public void readUnknownGroup(int fieldNumber, MessageLite.Builder builder) throws java.io.IOException
CodedInputStream
group
field value from the stream and merges it into the given UnknownFieldSet
.readUnknownGroup
in class CodedInputStream
java.io.IOException
public void readMessage(MessageLite.Builder builder, ExtensionRegistryLite extensionRegistry) throws java.io.IOException
CodedInputStream
readMessage
in class CodedInputStream
java.io.IOException
public <T extends MessageLite> T readMessage(Parser<T> parser, ExtensionRegistryLite extensionRegistry) throws java.io.IOException
CodedInputStream
readMessage
in class CodedInputStream
java.io.IOException
public ByteString readBytes() throws java.io.IOException
CodedInputStream
bytes
field value from the stream.readBytes
in class CodedInputStream
java.io.IOException
public byte[] readByteArray() throws java.io.IOException
CodedInputStream
bytes
field value from the stream.readByteArray
in class CodedInputStream
java.io.IOException
public java.nio.ByteBuffer readByteBuffer() throws java.io.IOException
CodedInputStream
bytes
field value from the stream.readByteBuffer
in class CodedInputStream
java.io.IOException
public int readUInt32() throws java.io.IOException
CodedInputStream
uint32
field value from the stream.readUInt32
in class CodedInputStream
java.io.IOException
public int readEnum() throws java.io.IOException
CodedInputStream
readEnum
in class CodedInputStream
java.io.IOException
public int readSFixed32() throws java.io.IOException
CodedInputStream
sfixed32
field value from the stream.readSFixed32
in class CodedInputStream
java.io.IOException
public long readSFixed64() throws java.io.IOException
CodedInputStream
sfixed64
field value from the stream.readSFixed64
in class CodedInputStream
java.io.IOException
public int readSInt32() throws java.io.IOException
CodedInputStream
sint32
field value from the stream.readSInt32
in class CodedInputStream
java.io.IOException
public long readSInt64() throws java.io.IOException
CodedInputStream
sint64
field value from the stream.readSInt64
in class CodedInputStream
java.io.IOException
public int readRawVarint32() throws java.io.IOException
CodedInputStream
readRawVarint32
in class CodedInputStream
java.io.IOException
public long readRawVarint64() throws java.io.IOException
CodedInputStream
readRawVarint64
in class CodedInputStream
java.io.IOException
long readRawVarint64SlowPath() throws java.io.IOException
CodedInputStream
readRawVarint64SlowPath
in class CodedInputStream
java.io.IOException
public int readRawLittleEndian32() throws java.io.IOException
CodedInputStream
readRawLittleEndian32
in class CodedInputStream
java.io.IOException
public long readRawLittleEndian64() throws java.io.IOException
CodedInputStream
readRawLittleEndian64
in class CodedInputStream
java.io.IOException
public void enableAliasing(boolean enabled)
CodedInputStream
ByteString
aliasing of the underlying buffer, trading off on buffer pinning for
data copies. Only valid for buffer-backed streams.enableAliasing
in class CodedInputStream
public void resetSizeCounter()
CodedInputStream
CodedInputStream.setSizeLimit(int)
). Only valid for InputStream
-backed streams.resetSizeCounter
in class CodedInputStream
public int pushLimit(int byteLimit) throws InvalidProtocolBufferException
CodedInputStream
currentLimit
to (current position) + byteLimit
. This is called when
descending into a length-delimited embedded message.
Note that pushLimit()
does NOT affect how many bytes the CodedInputStream
reads from an underlying InputStream
when refreshing its buffer. If you need to prevent
reading past a certain point in the underlying InputStream
(e.g. because you expect it
to contain more data after the end of the message which you need to handle differently) then
you must place a wrapper around your InputStream
which limits the amount of data that
can be read from it.
pushLimit
in class CodedInputStream
InvalidProtocolBufferException
private void recomputeBufferSizeAfterLimit()
public void popLimit(int oldLimit)
CodedInputStream
popLimit
in class CodedInputStream
oldLimit
- The old limit, as returned by pushLimit
.public int getBytesUntilLimit()
CodedInputStream
getBytesUntilLimit
in class CodedInputStream
public boolean isAtEnd() throws java.io.IOException
CodedInputStream
CodedInputStream.pushLimit(int)
.isAtEnd
in class CodedInputStream
java.io.IOException
public int getTotalBytesRead()
CodedInputStream
CodedInputStream.resetSizeCounter()
resets
this value to zero.getTotalBytesRead
in class CodedInputStream
public byte readRawByte() throws java.io.IOException
CodedInputStream
readRawByte
in class CodedInputStream
InvalidProtocolBufferException
- The end of the stream or the current limit was reached.java.io.IOException
public byte[] readRawBytes(int length) throws java.io.IOException
CodedInputStream
readRawBytes
in class CodedInputStream
InvalidProtocolBufferException
- The end of the stream or the current limit was reached.java.io.IOException
private void readRawBytesTo(byte[] bytes, int offset, int length) throws java.io.IOException
input
with the size of length
and copy to bytes
array. If the size is bigger than the number of remaining bytes in the input, then
throw truncatedMessage
exception.bytes
- offset
- length
- java.io.IOException
public void skipRawBytes(int length) throws java.io.IOException
CodedInputStream
size
bytes.skipRawBytes
in class CodedInputStream
InvalidProtocolBufferException
- The end of the stream or the current limit was reached.java.io.IOException
private void skipRawVarint() throws java.io.IOException
java.io.IOException
private int remaining()
input
.input
.private long currentRemaining()
currentByteBuffer
.currentByteBuffer
private java.nio.ByteBuffer slice(int begin, int end) throws java.io.IOException
java.io.IOException