Package com.google.protobuf
Class CodedInputStream.ArrayDecoder
java.lang.Object
com.google.protobuf.CodedInputStream
com.google.protobuf.CodedInputStream.ArrayDecoder
- Enclosing class:
CodedInputStream
A
CodedInputStream
implementation that uses a backing array as the input.-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final byte[]
private int
private int
The absolute position of the end of the current message.private boolean
private final boolean
private int
private int
private int
private int
Fields inherited from class com.google.protobuf.CodedInputStream
groupDepth, messageDepth, recursionLimit, sizeLimit, wrapper
-
Constructor Summary
ConstructorsModifierConstructorDescriptionprivate
ArrayDecoder
(byte[] buffer, int offset, int len, boolean immutable) -
Method Summary
Modifier and TypeMethodDescriptionvoid
checkLastTagWas
(int value) Verifies that the last call to readTag() returned the given tag value.void
enableAliasing
(boolean enabled) EnablesByteString
aliasing of the underlying buffer, trading off on buffer pinning for data copies.int
Returns the number of bytes to be read before the current limit.int
int
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) SetscurrentLimit
to (current position) +byteLimit
.boolean
readBool()
Read abool
field value from the stream.byte[]
Read abytes
field value from the stream.Read abytes
field value from the stream.Read abytes
field value from the stream.double
Read adouble
field value from the stream.int
readEnum()
Read an enum field value from the stream.int
Read afixed32
field value from the stream.long
Read afixed64
field value from the stream.float
Read afloat
field value from the stream.void
readGroup
(int fieldNumber, MessageLite.Builder builder, ExtensionRegistryLite extensionRegistry) Read agroup
field value from the stream.<T extends MessageLite>
TreadGroup
(int fieldNumber, Parser<T> parser, ExtensionRegistryLite extensionRegistry) Read agroup
field value from the stream.int
Read anint32
field value from the stream.long
Read anint64
field value from the stream.void
readMessage
(MessageLite.Builder builder, ExtensionRegistryLite extensionRegistry) Read an embedded message field value from the stream.<T extends MessageLite>
TreadMessage
(Parser<T> parser, ExtensionRegistryLite extensionRegistry) Read an embedded message field value from the stream.byte
Read one byte from the input.byte[]
readRawBytes
(int length) Read a fixed size of bytes from the input.int
Read a 32-bit little-endian integer from the stream.long
Read a 64-bit little-endian integer from the stream.int
Read a raw Varint from the stream.long
Read a raw Varint from the stream.(package private) long
Variant of readRawVarint64 for when uncomfortably close to the limit.int
Read ansfixed32
field value from the stream.long
Read ansfixed64
field value from the stream.int
Read ansint32
field value from the stream.long
Read ansint64
field value from the stream.Read astring
field value from the stream.Read astring
field value from the stream.int
readTag()
Attempt to read a field tag, returning zero if we have reached EOF.int
Read auint32
field value from the stream.long
Read auint64
field value from the stream.void
readUnknownGroup
(int fieldNumber, MessageLite.Builder builder) Deprecated.private void
void
Resets the current size counter to zero (seeCodedInputStream.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
skipRawBytes
(int length) Reads and discardssize
bytes.private void
private void
private void
Methods inherited from class com.google.protobuf.CodedInputStream
checkRecursionLimit, checkValidEndTag, decodeZigZag32, decodeZigZag64, discardUnknownFields, newInstance, newInstance, newInstance, newInstance, newInstance, newInstance, newInstance, newInstance, newInstance, readRawVarint32, readRawVarint32, setRecursionLimit, setSizeLimit, shouldDiscardUnknownFields, skipMessage, skipMessage, unsetDiscardUnknownFields
-
Field Details
-
buffer
private final byte[] buffer -
immutable
private final boolean immutable -
limit
private int limit -
bufferSizeAfterLimit
private int bufferSizeAfterLimit -
pos
private int pos -
startPos
private int startPos -
lastTag
private int lastTag -
enableAliasing
private boolean enableAliasing -
currentLimit
private int currentLimitThe absolute position of the end of the current message.
-
-
Constructor Details
-
ArrayDecoder
private ArrayDecoder(byte[] buffer, int offset, int len, boolean immutable)
-
-
Method Details
-
readTag
Description copied from class:CodedInputStream
Attempt to read a field tag, returning zero if we have reached EOF. Protocol message parsers use this to read tags, since a protocol message may legally end wherever a tag occurs, and zero is not a valid tag number.- Specified by:
readTag
in classCodedInputStream
- Throws:
IOException
-
checkLastTagWas
Description copied from class:CodedInputStream
Verifies that the last call to readTag() returned the given tag value. This is used to verify that a nested group ended with the correct end tag.- Specified by:
checkLastTagWas
in classCodedInputStream
- Throws:
InvalidProtocolBufferException
-value
does not match the last tag.
-
getLastTag
public int getLastTag()- Specified by:
getLastTag
in classCodedInputStream
-
skipField
Description copied from class:CodedInputStream
Reads and discards a single field, given its tag value.- Specified by:
skipField
in classCodedInputStream
- Returns:
false
if the tag is an endgroup tag, in which case nothing is skipped. Otherwise, returnstrue
.- Throws:
IOException
-
skipField
Description copied from class:CodedInputStream
Reads a single field and writes it to output in wire format, given its tag value.- Specified by:
skipField
in classCodedInputStream
- Returns:
false
if the tag is an endgroup tag, in which case nothing is skipped. Otherwise, returnstrue
.- Throws:
IOException
-
readDouble
Description copied from class:CodedInputStream
Read adouble
field value from the stream.- Specified by:
readDouble
in classCodedInputStream
- Throws:
IOException
-
readFloat
Description copied from class:CodedInputStream
Read afloat
field value from the stream.- Specified by:
readFloat
in classCodedInputStream
- Throws:
IOException
-
readUInt64
Description copied from class:CodedInputStream
Read auint64
field value from the stream.- Specified by:
readUInt64
in classCodedInputStream
- Throws:
IOException
-
readInt64
Description copied from class:CodedInputStream
Read anint64
field value from the stream.- Specified by:
readInt64
in classCodedInputStream
- Throws:
IOException
-
readInt32
Description copied from class:CodedInputStream
Read anint32
field value from the stream.- Specified by:
readInt32
in classCodedInputStream
- Throws:
IOException
-
readFixed64
Description copied from class:CodedInputStream
Read afixed64
field value from the stream.- Specified by:
readFixed64
in classCodedInputStream
- Throws:
IOException
-
readFixed32
Description copied from class:CodedInputStream
Read afixed32
field value from the stream.- Specified by:
readFixed32
in classCodedInputStream
- Throws:
IOException
-
readBool
Description copied from class:CodedInputStream
Read abool
field value from the stream.- Specified by:
readBool
in classCodedInputStream
- Throws:
IOException
-
readString
Description copied from class:CodedInputStream
Read astring
field value from the stream. If the stream contains malformed UTF-8, replace the offending bytes with the standard UTF-8 replacement character.- Specified by:
readString
in classCodedInputStream
- Throws:
IOException
-
readStringRequireUtf8
Description copied from class:CodedInputStream
Read astring
field value from the stream. If the stream contains malformed UTF-8, throw exceptionInvalidProtocolBufferException
.- Specified by:
readStringRequireUtf8
in classCodedInputStream
- Throws:
IOException
-
readGroup
public void readGroup(int fieldNumber, MessageLite.Builder builder, ExtensionRegistryLite extensionRegistry) throws IOException Description copied from class:CodedInputStream
Read agroup
field value from the stream.- Specified by:
readGroup
in classCodedInputStream
- Throws:
IOException
-
readGroup
public <T extends MessageLite> T readGroup(int fieldNumber, Parser<T> parser, ExtensionRegistryLite extensionRegistry) throws IOException Description copied from class:CodedInputStream
Read agroup
field value from the stream.- Specified by:
readGroup
in classCodedInputStream
- Throws:
IOException
-
readUnknownGroup
@Deprecated public void readUnknownGroup(int fieldNumber, MessageLite.Builder builder) throws IOException Deprecated.Description copied from class:CodedInputStream
Reads agroup
field value from the stream and merges it into the givenUnknownFieldSet
.- Specified by:
readUnknownGroup
in classCodedInputStream
- Throws:
IOException
-
readMessage
public void readMessage(MessageLite.Builder builder, ExtensionRegistryLite extensionRegistry) throws IOException Description copied from class:CodedInputStream
Read an embedded message field value from the stream.- Specified by:
readMessage
in classCodedInputStream
- Throws:
IOException
-
readMessage
public <T extends MessageLite> T readMessage(Parser<T> parser, ExtensionRegistryLite extensionRegistry) throws IOException Description copied from class:CodedInputStream
Read an embedded message field value from the stream.- Specified by:
readMessage
in classCodedInputStream
- Throws:
IOException
-
readBytes
Description copied from class:CodedInputStream
Read abytes
field value from the stream.- Specified by:
readBytes
in classCodedInputStream
- Throws:
IOException
-
readByteArray
Description copied from class:CodedInputStream
Read abytes
field value from the stream.- Specified by:
readByteArray
in classCodedInputStream
- Throws:
IOException
-
readByteBuffer
Description copied from class:CodedInputStream
Read abytes
field value from the stream.- Specified by:
readByteBuffer
in classCodedInputStream
- Throws:
IOException
-
readUInt32
Description copied from class:CodedInputStream
Read auint32
field value from the stream.- Specified by:
readUInt32
in classCodedInputStream
- Throws:
IOException
-
readEnum
Description copied from class:CodedInputStream
Read an enum field value from the stream. Caller is responsible for converting the numeric value to an actual enum.- Specified by:
readEnum
in classCodedInputStream
- Throws:
IOException
-
readSFixed32
Description copied from class:CodedInputStream
Read ansfixed32
field value from the stream.- Specified by:
readSFixed32
in classCodedInputStream
- Throws:
IOException
-
readSFixed64
Description copied from class:CodedInputStream
Read ansfixed64
field value from the stream.- Specified by:
readSFixed64
in classCodedInputStream
- Throws:
IOException
-
readSInt32
Description copied from class:CodedInputStream
Read ansint32
field value from the stream.- Specified by:
readSInt32
in classCodedInputStream
- Throws:
IOException
-
readSInt64
Description copied from class:CodedInputStream
Read ansint64
field value from the stream.- Specified by:
readSInt64
in classCodedInputStream
- Throws:
IOException
-
readRawVarint32
Description copied from class:CodedInputStream
Read a raw Varint from the stream. If larger than 32 bits, discard the upper bits.- Specified by:
readRawVarint32
in classCodedInputStream
- Throws:
IOException
-
skipRawVarint
- Throws:
IOException
-
skipRawVarintFastPath
- Throws:
IOException
-
skipRawVarintSlowPath
- Throws:
IOException
-
readRawVarint64
Description copied from class:CodedInputStream
Read a raw Varint from the stream.- Specified by:
readRawVarint64
in classCodedInputStream
- Throws:
IOException
-
readRawVarint64SlowPath
Description copied from class:CodedInputStream
Variant of readRawVarint64 for when uncomfortably close to the limit.- Specified by:
readRawVarint64SlowPath
in classCodedInputStream
- Throws:
IOException
-
readRawLittleEndian32
Description copied from class:CodedInputStream
Read a 32-bit little-endian integer from the stream.- Specified by:
readRawLittleEndian32
in classCodedInputStream
- Throws:
IOException
-
readRawLittleEndian64
Description copied from class:CodedInputStream
Read a 64-bit little-endian integer from the stream.- Specified by:
readRawLittleEndian64
in classCodedInputStream
- Throws:
IOException
-
enableAliasing
public void enableAliasing(boolean enabled) Description copied from class:CodedInputStream
EnablesByteString
aliasing of the underlying buffer, trading off on buffer pinning for data copies. Only valid for buffer-backed streams.- Specified by:
enableAliasing
in classCodedInputStream
-
resetSizeCounter
public void resetSizeCounter()Description copied from class:CodedInputStream
Resets the current size counter to zero (seeCodedInputStream.setSizeLimit(int)
). Only valid forInputStream
-backed streams.- Specified by:
resetSizeCounter
in classCodedInputStream
-
pushLimit
Description copied from class:CodedInputStream
SetscurrentLimit
to (current position) +byteLimit
. This is called when descending into a length-delimited embedded message.Note that
pushLimit()
does NOT affect how many bytes theCodedInputStream
reads from an underlyingInputStream
when refreshing its buffer. If you need to prevent reading past a certain point in the underlyingInputStream
(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 yourInputStream
which limits the amount of data that can be read from it.- Specified by:
pushLimit
in classCodedInputStream
- Returns:
- the old limit.
- Throws:
InvalidProtocolBufferException
-
recomputeBufferSizeAfterLimit
private void recomputeBufferSizeAfterLimit() -
popLimit
public void popLimit(int oldLimit) Description copied from class:CodedInputStream
Discards the current limit, returning to the previous limit.- Specified by:
popLimit
in classCodedInputStream
- Parameters:
oldLimit
- The old limit, as returned bypushLimit
.
-
getBytesUntilLimit
public int getBytesUntilLimit()Description copied from class:CodedInputStream
Returns the number of bytes to be read before the current limit. If no limit is set, returns -1.- Specified by:
getBytesUntilLimit
in classCodedInputStream
-
isAtEnd
Description copied from class:CodedInputStream
Returns true if the stream has reached the end of the input. This is the case if either the end of the underlying input source has been reached or if the stream has reached a limit created usingCodedInputStream.pushLimit(int)
. This function may get blocked when using StreamDecoder as it invokesCodedInputStream.StreamDecoder.tryRefillBuffer(int)
in this function which will try to read bytes from input.- Specified by:
isAtEnd
in classCodedInputStream
- Throws:
IOException
-
getTotalBytesRead
public int getTotalBytesRead()Description copied from class:CodedInputStream
The total bytes read up to the current position. CallingCodedInputStream.resetSizeCounter()
resets this value to zero.- Specified by:
getTotalBytesRead
in classCodedInputStream
-
readRawByte
Description copied from class:CodedInputStream
Read one byte from the input.- Specified by:
readRawByte
in classCodedInputStream
- Throws:
IOException
-
readRawBytes
Description copied from class:CodedInputStream
Read a fixed size of bytes from the input.- Specified by:
readRawBytes
in classCodedInputStream
- Throws:
IOException
-
skipRawBytes
Description copied from class:CodedInputStream
Reads and discardssize
bytes.- Specified by:
skipRawBytes
in classCodedInputStream
- Throws:
IOException
-