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, unsetDiscardUnknownFieldsprivate java.lang.Iterable<java.nio.ByteBuffer> input
private java.util.Iterator<java.nio.ByteBuffer> iterator
Iterator with type ByteBuffer of inputprivate 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 ByteBufferprivate 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 parametersInvalidProtocolBufferExceptionprivate void tryGetNextByteBuffer()
public int readTag()
throws java.io.IOException
CodedInputStreamreadTag in class CodedInputStreamjava.io.IOExceptionpublic void checkLastTagWas(int value)
throws InvalidProtocolBufferException
CodedInputStreamcheckLastTagWas in class CodedInputStreamInvalidProtocolBufferException - value does not match the last tag.public int getLastTag()
getLastTag in class CodedInputStreampublic boolean skipField(int tag)
throws java.io.IOException
CodedInputStreamskipField in class CodedInputStreamfalse if the tag is an endgroup tag, in which case nothing is skipped.
Otherwise, returns true.java.io.IOExceptionpublic boolean skipField(int tag,
CodedOutputStream output)
throws java.io.IOException
CodedInputStreamskipField in class CodedInputStreamfalse if the tag is an endgroup tag, in which case nothing is skipped.
Otherwise, returns true.java.io.IOExceptionpublic void skipMessage()
throws java.io.IOException
CodedInputStreamskipMessage in class CodedInputStreamjava.io.IOExceptionpublic void skipMessage(CodedOutputStream output) throws java.io.IOException
CodedInputStreamskipMessage in class CodedInputStreamjava.io.IOExceptionpublic double readDouble()
throws java.io.IOException
CodedInputStreamdouble field value from the stream.readDouble in class CodedInputStreamjava.io.IOExceptionpublic float readFloat()
throws java.io.IOException
CodedInputStreamfloat field value from the stream.readFloat in class CodedInputStreamjava.io.IOExceptionpublic long readUInt64()
throws java.io.IOException
CodedInputStreamuint64 field value from the stream.readUInt64 in class CodedInputStreamjava.io.IOExceptionpublic long readInt64()
throws java.io.IOException
CodedInputStreamint64 field value from the stream.readInt64 in class CodedInputStreamjava.io.IOExceptionpublic int readInt32()
throws java.io.IOException
CodedInputStreamint32 field value from the stream.readInt32 in class CodedInputStreamjava.io.IOExceptionpublic long readFixed64()
throws java.io.IOException
CodedInputStreamfixed64 field value from the stream.readFixed64 in class CodedInputStreamjava.io.IOExceptionpublic int readFixed32()
throws java.io.IOException
CodedInputStreamfixed32 field value from the stream.readFixed32 in class CodedInputStreamjava.io.IOExceptionpublic boolean readBool()
throws java.io.IOException
CodedInputStreambool field value from the stream.readBool in class CodedInputStreamjava.io.IOExceptionpublic java.lang.String readString()
throws java.io.IOException
CodedInputStreamstring 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 CodedInputStreamjava.io.IOExceptionpublic java.lang.String readStringRequireUtf8()
throws java.io.IOException
CodedInputStreamstring field value from the stream. If the stream contains malformed UTF-8,
throw exception InvalidProtocolBufferException.readStringRequireUtf8 in class CodedInputStreamjava.io.IOExceptionpublic void readGroup(int fieldNumber,
MessageLite.Builder builder,
ExtensionRegistryLite extensionRegistry)
throws java.io.IOException
CodedInputStreamgroup field value from the stream.readGroup in class CodedInputStreamjava.io.IOExceptionpublic <T extends MessageLite> T readGroup(int fieldNumber, Parser<T> parser, ExtensionRegistryLite extensionRegistry) throws java.io.IOException
CodedInputStreamgroup field value from the stream.readGroup in class CodedInputStreamjava.io.IOException@Deprecated
public void readUnknownGroup(int fieldNumber,
MessageLite.Builder builder)
throws java.io.IOException
CodedInputStreamgroup field value from the stream and merges it into the given UnknownFieldSet.readUnknownGroup in class CodedInputStreamjava.io.IOExceptionpublic void readMessage(MessageLite.Builder builder, ExtensionRegistryLite extensionRegistry) throws java.io.IOException
CodedInputStreamreadMessage in class CodedInputStreamjava.io.IOExceptionpublic <T extends MessageLite> T readMessage(Parser<T> parser, ExtensionRegistryLite extensionRegistry) throws java.io.IOException
CodedInputStreamreadMessage in class CodedInputStreamjava.io.IOExceptionpublic ByteString readBytes() throws java.io.IOException
CodedInputStreambytes field value from the stream.readBytes in class CodedInputStreamjava.io.IOExceptionpublic byte[] readByteArray()
throws java.io.IOException
CodedInputStreambytes field value from the stream.readByteArray in class CodedInputStreamjava.io.IOExceptionpublic java.nio.ByteBuffer readByteBuffer()
throws java.io.IOException
CodedInputStreambytes field value from the stream.readByteBuffer in class CodedInputStreamjava.io.IOExceptionpublic int readUInt32()
throws java.io.IOException
CodedInputStreamuint32 field value from the stream.readUInt32 in class CodedInputStreamjava.io.IOExceptionpublic int readEnum()
throws java.io.IOException
CodedInputStreamreadEnum in class CodedInputStreamjava.io.IOExceptionpublic int readSFixed32()
throws java.io.IOException
CodedInputStreamsfixed32 field value from the stream.readSFixed32 in class CodedInputStreamjava.io.IOExceptionpublic long readSFixed64()
throws java.io.IOException
CodedInputStreamsfixed64 field value from the stream.readSFixed64 in class CodedInputStreamjava.io.IOExceptionpublic int readSInt32()
throws java.io.IOException
CodedInputStreamsint32 field value from the stream.readSInt32 in class CodedInputStreamjava.io.IOExceptionpublic long readSInt64()
throws java.io.IOException
CodedInputStreamsint64 field value from the stream.readSInt64 in class CodedInputStreamjava.io.IOExceptionpublic int readRawVarint32()
throws java.io.IOException
CodedInputStreamreadRawVarint32 in class CodedInputStreamjava.io.IOExceptionpublic long readRawVarint64()
throws java.io.IOException
CodedInputStreamreadRawVarint64 in class CodedInputStreamjava.io.IOExceptionlong readRawVarint64SlowPath()
throws java.io.IOException
CodedInputStreamreadRawVarint64SlowPath in class CodedInputStreamjava.io.IOExceptionpublic int readRawLittleEndian32()
throws java.io.IOException
CodedInputStreamreadRawLittleEndian32 in class CodedInputStreamjava.io.IOExceptionpublic long readRawLittleEndian64()
throws java.io.IOException
CodedInputStreamreadRawLittleEndian64 in class CodedInputStreamjava.io.IOExceptionpublic void enableAliasing(boolean enabled)
CodedInputStreamByteString aliasing of the underlying buffer, trading off on buffer pinning for
data copies. Only valid for buffer-backed streams.enableAliasing in class CodedInputStreampublic void resetSizeCounter()
CodedInputStreamCodedInputStream.setSizeLimit(int)). Only valid for InputStream-backed streams.resetSizeCounter in class CodedInputStreampublic int pushLimit(int byteLimit)
throws InvalidProtocolBufferException
CodedInputStreamcurrentLimit 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 CodedInputStreamInvalidProtocolBufferExceptionprivate void recomputeBufferSizeAfterLimit()
public void popLimit(int oldLimit)
CodedInputStreampopLimit in class CodedInputStreamoldLimit - The old limit, as returned by pushLimit.public int getBytesUntilLimit()
CodedInputStreamgetBytesUntilLimit in class CodedInputStreampublic boolean isAtEnd()
throws java.io.IOException
CodedInputStreamCodedInputStream.pushLimit(int).isAtEnd in class CodedInputStreamjava.io.IOExceptionpublic int getTotalBytesRead()
CodedInputStreamCodedInputStream.resetSizeCounter() resets
this value to zero.getTotalBytesRead in class CodedInputStreampublic byte readRawByte()
throws java.io.IOException
CodedInputStreamreadRawByte in class CodedInputStreamInvalidProtocolBufferException - The end of the stream or the current limit was reached.java.io.IOExceptionpublic byte[] readRawBytes(int length)
throws java.io.IOException
CodedInputStreamreadRawBytes in class CodedInputStreamInvalidProtocolBufferException - The end of the stream or the current limit was reached.java.io.IOExceptionprivate 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.IOExceptionpublic void skipRawBytes(int length)
throws java.io.IOException
CodedInputStreamsize bytes.skipRawBytes in class CodedInputStreamInvalidProtocolBufferException - The end of the stream or the current limit was reached.java.io.IOExceptionprivate void skipRawVarint()
throws java.io.IOException
java.io.IOExceptionprivate int remaining()
input.input.private long currentRemaining()
currentByteBuffer.currentByteBufferprivate java.nio.ByteBuffer slice(int begin,
int end)
throws java.io.IOException
java.io.IOException