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, unsetDiscardUnknownFields
private 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
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
private void skipRawVarint() throws java.io.IOException
java.io.IOException
private void skipRawVarintFastPath() throws java.io.IOException
java.io.IOException
private void skipRawVarintSlowPath() throws java.io.IOException
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
private 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.IOException
private 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.IOException
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 size) 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 byte[] readRawBytesSlowPath(int size) throws java.io.IOException
java.io.IOException
private byte[] readRawBytesSlowPathOneChunk(int size) throws java.io.IOException
java.io.IOException
private java.util.List<byte[]> readRawBytesSlowPathRemainingChunks(int sizeLeft) throws java.io.IOException
java.io.IOException
private ByteString readBytesSlowPath(int size) throws java.io.IOException
java.io.IOException
public void skipRawBytes(int size) 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 skipRawBytesSlowPath(int size) throws java.io.IOException
java.io.IOException