private static final class CodedInputStream.StreamDecoder extends CodedInputStream
CodedInputStream that uses an InputStream as the data source.| Modifier and Type | Class and Description |
|---|---|
private static interface |
CodedInputStream.StreamDecoder.RefillCallback |
private class |
CodedInputStream.StreamDecoder.SkippedDataSink
Collects the bytes skipped and returns the data in a ByteBuffer.
|
| Modifier and Type | Field and Description |
|---|---|
private byte[] |
buffer |
private int |
bufferSize
bufferSize represents how many bytes are currently filled in the buffer
|
private int |
bufferSizeAfterLimit |
private int |
currentLimit
The absolute position of the end of the current message.
|
private java.io.InputStream |
input |
private int |
lastTag |
private int |
pos |
private CodedInputStream.StreamDecoder.RefillCallback |
refillCallback |
private int |
totalBytesRetired
The total number of bytes read before the current buffer.
|
recursionDepth, recursionLimit, sizeLimit| Modifier | Constructor and Description |
|---|---|
private |
StreamDecoder(java.io.InputStream input,
int bufferSize) |
| Modifier and Type | Method and Description |
|---|---|
void |
checkLastTagWas(int value)
Verifies that the last call to readTag() returned the given tag value.
|
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() |
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. |
private ByteString |
readBytesSlowPath(int size)
Like readBytes, but caller must have already checked the fast path: (size <= (bufferSize -
pos) && size > 0 || size == 0)
|
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 size)
Read a fixed size of bytes from the input.
|
private byte[] |
readRawBytesSlowPath(int size)
Exactly like readRawBytes, but caller must have already checked the fast path: (size <=
(bufferSize - pos) && size > 0)
|
private byte[] |
readRawBytesSlowPathOneChunk(int size)
Attempts to read the data in one byte array when it's safe to do.
|
private java.util.List<byte[]> |
readRawBytesSlowPathRemainingChunks(int sizeLeft)
Reads the remaining data in small chunks from the input stream.
|
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 void |
refillBuffer(int n)
Reads more bytes from the input, making at least
n bytes available in the buffer. |
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 size)
Reads and discards
size bytes. |
private void |
skipRawBytesSlowPath(int size)
Exactly like skipRawBytes, but caller must have already checked the fast path: (size <=
(bufferSize - pos) && size >= 0)
|
private void |
skipRawVarint() |
private void |
skipRawVarintFastPath() |
private void |
skipRawVarintSlowPath() |
private boolean |
tryRefillBuffer(int n)
Tries to read more bytes from the input, making at least
n bytes available in the
buffer. |
decodeZigZag32, decodeZigZag64, discardUnknownFields, getProto3DiscardUnknownFieldsDefault, newInstance, newInstance, newInstance, newInstance, newInstance, newInstance, newInstance, newInstance, newInstance, readRawVarint32, readRawVarint32, setProto3DiscardUnknownsByDefaultForTest, setProto3KeepUnknownsByDefaultForTest, setRecursionLimit, setSizeLimit, shouldDiscardUnknownFields, shouldDiscardUnknownFieldsProto3, unsetDiscardUnknownFieldsprivate final java.io.InputStream input
private final byte[] buffer
private int bufferSize
private int bufferSizeAfterLimit
private int pos
private int lastTag
private int totalBytesRetired
totalBytesRetired + pos. This value may be
negative if reading started in the middle of the current buffer (e.g. if the constructor that
takes a byte array and an offset was used).private int currentLimit
private CodedInputStream.StreamDecoder.RefillCallback refillCallback
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.IOExceptionprivate void skipRawVarint()
throws java.io.IOException
java.io.IOExceptionprivate void skipRawVarintFastPath()
throws java.io.IOException
java.io.IOExceptionprivate void skipRawVarintSlowPath()
throws java.io.IOException
java.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 CodedInputStreamprivate void refillBuffer(int n)
throws java.io.IOException
n bytes available in the buffer.
Caller must ensure that the requested space is not yet available, and that the requested
space is less than BUFFER_SIZE.InvalidProtocolBufferException - The end of the stream or the current limit was
reached.java.io.IOExceptionprivate boolean tryRefillBuffer(int n)
throws java.io.IOException
n bytes available in the
buffer. Caller must ensure that the requested space is not yet available, and that the
requested space is less than BUFFER_SIZE.true If the bytes could be made available; false 1. Current at the
end of the stream 2. The current limit was reached 3. The total size limit was reachedjava.io.IOExceptionpublic 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 size)
throws java.io.IOException
CodedInputStreamreadRawBytes in class CodedInputStreamInvalidProtocolBufferException - The end of the stream or the current limit was reached.java.io.IOExceptionprivate byte[] readRawBytesSlowPath(int size)
throws java.io.IOException
java.io.IOExceptionprivate byte[] readRawBytesSlowPathOneChunk(int size)
throws java.io.IOException
java.io.IOExceptionprivate java.util.List<byte[]> readRawBytesSlowPathRemainingChunks(int sizeLeft)
throws java.io.IOException
java.io.IOExceptionprivate ByteString readBytesSlowPath(int size) throws java.io.IOException
java.io.IOExceptionpublic void skipRawBytes(int size)
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 skipRawBytesSlowPath(int size)
throws java.io.IOException
java.io.IOException