Package com.google.protobuf
Class CodedInputStream.IterableDirectByteBufferDecoder
- java.lang.Object
-
- com.google.protobuf.CodedInputStream
-
- com.google.protobuf.CodedInputStream.IterableDirectByteBufferDecoder
-
- Enclosing class:
- CodedInputStream
private static final class CodedInputStream.IterableDirectByteBufferDecoder extends CodedInputStream
Implementation ofCodedInputStreamthat uses anas the data source. Requires the use ofsun.misc.Unsafeto perform fast reads on the buffer.
-
-
Field Summary
Fields Modifier and Type Field Description private intbufferSizeAfterCurrentLimitThe amount of available data in the input beyondcurrentLimit.private longcurrentAddressIf the current ByteBuffer is unsafe-direct based, currentAddress is the start address of this ByteBuffer; otherwise should be zero.private java.nio.ByteBuffercurrentByteBufferThe current ByteBuffer;private longcurrentByteBufferLimitThe limit position for current ByteBufferprivate longcurrentByteBufferPosThe current position for current ByteBufferprivate longcurrentByteBufferStartPosprivate intcurrentLimitThe absolute position of the end of the current message.private booleanenableAliasingIftrue, indicates that calls to readByteStringorbyte[]may return slices of the underlying buffer, rather than copies.private booleanimmutableIftrue, indicates that all the buffers are backing aByteStringand are therefore considered to be an immutable input source.private java.lang.Iterable<java.nio.ByteBuffer>inputThe object that need to decode.private java.util.Iterator<java.nio.ByteBuffer>iteratorTheIteratorwith typeByteBufferofinputprivate intlastTagThe last tag that was read from this stream.private intstartOffsetThe start position offset of the whole message, used as to reset the totalBytesReadprivate inttotalBufferSizeThe global total message length limitprivate inttotalBytesReadTotal Bytes have been Read from theIterableByteBuffer-
Fields inherited from class com.google.protobuf.CodedInputStream
recursionDepth, recursionLimit, sizeLimit, wrapper
-
-
Constructor Summary
Constructors Modifier Constructor Description privateIterableDirectByteBufferDecoder(java.lang.Iterable<java.nio.ByteBuffer> inputBufs, int size, boolean immutableFlag)The constructor ofIterable<ByteBuffer>decoder.
-
Method Summary
All Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description voidcheckLastTagWas(int value)Verifies that the last call to readTag() returned the given tag value.private longcurrentRemaining()Try to get the number of remaining bytes incurrentByteBuffer.voidenableAliasing(boolean enabled)EnablesByteStringaliasing of the underlying buffer, trading off on buffer pinning for data copies.intgetBytesUntilLimit()Returns the number of bytes to be read before the current limit.intgetLastTag()private voidgetNextByteBuffer()To get the next ByteBuffer frominput, and then update the parametersintgetTotalBytesRead()The total bytes read up to the current position.booleanisAtEnd()Returns true if the stream has reached the end of the input.voidpopLimit(int oldLimit)Discards the current limit, returning to the previous limit.intpushLimit(int byteLimit)SetscurrentLimitto (current position) +byteLimit.booleanreadBool()Read aboolfield value from the stream.byte[]readByteArray()Read abytesfield value from the stream.java.nio.ByteBufferreadByteBuffer()Read abytesfield value from the stream.ByteStringreadBytes()Read abytesfield value from the stream.doublereadDouble()Read adoublefield value from the stream.intreadEnum()Read an enum field value from the stream.intreadFixed32()Read afixed32field value from the stream.longreadFixed64()Read afixed64field value from the stream.floatreadFloat()Read afloatfield value from the stream.voidreadGroup(int fieldNumber, MessageLite.Builder builder, ExtensionRegistryLite extensionRegistry)Read agroupfield value from the stream.<T extends MessageLite>
TreadGroup(int fieldNumber, Parser<T> parser, ExtensionRegistryLite extensionRegistry)Read agroupfield value from the stream.intreadInt32()Read anint32field value from the stream.longreadInt64()Read anint64field value from the stream.voidreadMessage(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.bytereadRawByte()Read one byte from the input.byte[]readRawBytes(int length)Read a fixed size of bytes from the input.private voidreadRawBytesTo(byte[] bytes, int offset, int length)Try to get raw bytes frominputwith the size oflengthand copy tobytesarray.intreadRawLittleEndian32()Read a 32-bit little-endian integer from the stream.longreadRawLittleEndian64()Read a 64-bit little-endian integer from the stream.intreadRawVarint32()Read a raw Varint from the stream.longreadRawVarint64()Read a raw Varint from the stream.(package private) longreadRawVarint64SlowPath()Variant of readRawVarint64 for when uncomfortably close to the limit.intreadSFixed32()Read ansfixed32field value from the stream.longreadSFixed64()Read ansfixed64field value from the stream.intreadSInt32()Read ansint32field value from the stream.longreadSInt64()Read ansint64field value from the stream.java.lang.StringreadString()Read astringfield value from the stream.java.lang.StringreadStringRequireUtf8()Read astringfield value from the stream.intreadTag()Attempt to read a field tag, returning zero if we have reached EOF.intreadUInt32()Read auint32field value from the stream.longreadUInt64()Read auint64field value from the stream.voidreadUnknownGroup(int fieldNumber, MessageLite.Builder builder)Deprecated.private voidrecomputeBufferSizeAfterLimit()private intremaining()Try to get the number of remaining bytes ininput.voidresetSizeCounter()Resets the current size counter to zero (seeCodedInputStream.setSizeLimit(int)).booleanskipField(int tag)Reads and discards a single field, given its tag value.booleanskipField(int tag, CodedOutputStream output)Reads a single field and writes it to output in wire format, given its tag value.voidskipRawBytes(int length)Reads and discardssizebytes.private voidskipRawVarint()private java.nio.ByteBufferslice(int begin, int end)private voidtryGetNextByteBuffer()-
Methods inherited from class com.google.protobuf.CodedInputStream
checkRecursionLimit, decodeZigZag32, decodeZigZag64, discardUnknownFields, newInstance, newInstance, newInstance, newInstance, newInstance, newInstance, newInstance, newInstance, newInstance, readRawVarint32, readRawVarint32, setRecursionLimit, setSizeLimit, shouldDiscardUnknownFields, skipMessage, skipMessage, unsetDiscardUnknownFields
-
-
-
-
Field Detail
-
input
private final java.lang.Iterable<java.nio.ByteBuffer> input
The object that need to decode.
-
iterator
private final java.util.Iterator<java.nio.ByteBuffer> iterator
TheIteratorwith typeByteBufferofinput
-
currentByteBuffer
private java.nio.ByteBuffer currentByteBuffer
The current ByteBuffer;
-
immutable
private final boolean immutable
Iftrue, indicates that all the buffers are backing aByteStringand are therefore considered to be an immutable input source.
-
enableAliasing
private boolean enableAliasing
Iftrue, indicates that calls to readByteStringorbyte[]may return slices of the underlying buffer, rather than copies.
-
totalBufferSize
private int totalBufferSize
The global total message length limit
-
bufferSizeAfterCurrentLimit
private int bufferSizeAfterCurrentLimit
The amount of available data in the input beyondcurrentLimit.
-
currentLimit
private int currentLimit
The absolute position of the end of the current message.
-
lastTag
private int lastTag
The last tag that was read from this stream.
-
totalBytesRead
private int totalBytesRead
Total Bytes have been Read from theIterableByteBuffer
-
startOffset
private int startOffset
The start position offset of the whole message, used as to reset the totalBytesRead
-
currentByteBufferPos
private long currentByteBufferPos
The current position for current ByteBuffer
-
currentByteBufferStartPos
private long currentByteBufferStartPos
-
currentAddress
private long currentAddress
If the current ByteBuffer is unsafe-direct based, currentAddress is the start address of this ByteBuffer; otherwise should be zero.
-
currentByteBufferLimit
private long currentByteBufferLimit
The limit position for current ByteBuffer
-
-
Constructor Detail
-
IterableDirectByteBufferDecoder
private IterableDirectByteBufferDecoder(java.lang.Iterable<java.nio.ByteBuffer> inputBufs, int size, boolean immutableFlag)The constructor ofIterable<ByteBuffer>decoder.- Parameters:
inputBufs- The input data.size- The total size of the input data.immutableFlag- whether the input data is immutable.
-
-
Method Detail
-
getNextByteBuffer
private void getNextByteBuffer() throws InvalidProtocolBufferExceptionTo get the next ByteBuffer frominput, and then update the parameters- Throws:
InvalidProtocolBufferException
-
tryGetNextByteBuffer
private void tryGetNextByteBuffer()
-
readTag
public int readTag() throws java.io.IOExceptionDescription copied from class:CodedInputStreamAttempt 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:
readTagin classCodedInputStream- Throws:
java.io.IOException
-
checkLastTagWas
public void checkLastTagWas(int value) throws InvalidProtocolBufferExceptionDescription copied from class:CodedInputStreamVerifies 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:
checkLastTagWasin classCodedInputStream- Throws:
InvalidProtocolBufferException-valuedoes not match the last tag.
-
getLastTag
public int getLastTag()
- Specified by:
getLastTagin classCodedInputStream
-
skipField
public boolean skipField(int tag) throws java.io.IOExceptionDescription copied from class:CodedInputStreamReads and discards a single field, given its tag value.- Specified by:
skipFieldin classCodedInputStream- Returns:
falseif the tag is an endgroup tag, in which case nothing is skipped. Otherwise, returnstrue.- Throws:
java.io.IOException
-
skipField
public boolean skipField(int tag, CodedOutputStream output) throws java.io.IOExceptionDescription copied from class:CodedInputStreamReads a single field and writes it to output in wire format, given its tag value.- Specified by:
skipFieldin classCodedInputStream- Returns:
falseif the tag is an endgroup tag, in which case nothing is skipped. Otherwise, returnstrue.- Throws:
java.io.IOException
-
readDouble
public double readDouble() throws java.io.IOExceptionDescription copied from class:CodedInputStreamRead adoublefield value from the stream.- Specified by:
readDoublein classCodedInputStream- Throws:
java.io.IOException
-
readFloat
public float readFloat() throws java.io.IOExceptionDescription copied from class:CodedInputStreamRead afloatfield value from the stream.- Specified by:
readFloatin classCodedInputStream- Throws:
java.io.IOException
-
readUInt64
public long readUInt64() throws java.io.IOExceptionDescription copied from class:CodedInputStreamRead auint64field value from the stream.- Specified by:
readUInt64in classCodedInputStream- Throws:
java.io.IOException
-
readInt64
public long readInt64() throws java.io.IOExceptionDescription copied from class:CodedInputStreamRead anint64field value from the stream.- Specified by:
readInt64in classCodedInputStream- Throws:
java.io.IOException
-
readInt32
public int readInt32() throws java.io.IOExceptionDescription copied from class:CodedInputStreamRead anint32field value from the stream.- Specified by:
readInt32in classCodedInputStream- Throws:
java.io.IOException
-
readFixed64
public long readFixed64() throws java.io.IOExceptionDescription copied from class:CodedInputStreamRead afixed64field value from the stream.- Specified by:
readFixed64in classCodedInputStream- Throws:
java.io.IOException
-
readFixed32
public int readFixed32() throws java.io.IOExceptionDescription copied from class:CodedInputStreamRead afixed32field value from the stream.- Specified by:
readFixed32in classCodedInputStream- Throws:
java.io.IOException
-
readBool
public boolean readBool() throws java.io.IOExceptionDescription copied from class:CodedInputStreamRead aboolfield value from the stream.- Specified by:
readBoolin classCodedInputStream- Throws:
java.io.IOException
-
readString
public java.lang.String readString() throws java.io.IOExceptionDescription copied from class:CodedInputStreamRead astringfield value from the stream. If the stream contains malformed UTF-8, replace the offending bytes with the standard UTF-8 replacement character.- Specified by:
readStringin classCodedInputStream- Throws:
java.io.IOException
-
readStringRequireUtf8
public java.lang.String readStringRequireUtf8() throws java.io.IOExceptionDescription copied from class:CodedInputStreamRead astringfield value from the stream. If the stream contains malformed UTF-8, throw exceptionInvalidProtocolBufferException.- Specified by:
readStringRequireUtf8in classCodedInputStream- Throws:
java.io.IOException
-
readGroup
public void readGroup(int fieldNumber, MessageLite.Builder builder, ExtensionRegistryLite extensionRegistry) throws java.io.IOExceptionDescription copied from class:CodedInputStreamRead agroupfield value from the stream.- Specified by:
readGroupin classCodedInputStream- Throws:
java.io.IOException
-
readGroup
public <T extends MessageLite> T readGroup(int fieldNumber, Parser<T> parser, ExtensionRegistryLite extensionRegistry) throws java.io.IOException
Description copied from class:CodedInputStreamRead agroupfield value from the stream.- Specified by:
readGroupin classCodedInputStream- Throws:
java.io.IOException
-
readUnknownGroup
@Deprecated public void readUnknownGroup(int fieldNumber, MessageLite.Builder builder) throws java.io.IOExceptionDeprecated.Description copied from class:CodedInputStreamReads agroupfield value from the stream and merges it into the givenUnknownFieldSet.- Specified by:
readUnknownGroupin classCodedInputStream- Throws:
java.io.IOException
-
readMessage
public void readMessage(MessageLite.Builder builder, ExtensionRegistryLite extensionRegistry) throws java.io.IOException
Description copied from class:CodedInputStreamRead an embedded message field value from the stream.- Specified by:
readMessagein classCodedInputStream- Throws:
java.io.IOException
-
readMessage
public <T extends MessageLite> T readMessage(Parser<T> parser, ExtensionRegistryLite extensionRegistry) throws java.io.IOException
Description copied from class:CodedInputStreamRead an embedded message field value from the stream.- Specified by:
readMessagein classCodedInputStream- Throws:
java.io.IOException
-
readBytes
public ByteString readBytes() throws java.io.IOException
Description copied from class:CodedInputStreamRead abytesfield value from the stream.- Specified by:
readBytesin classCodedInputStream- Throws:
java.io.IOException
-
readByteArray
public byte[] readByteArray() throws java.io.IOExceptionDescription copied from class:CodedInputStreamRead abytesfield value from the stream.- Specified by:
readByteArrayin classCodedInputStream- Throws:
java.io.IOException
-
readByteBuffer
public java.nio.ByteBuffer readByteBuffer() throws java.io.IOExceptionDescription copied from class:CodedInputStreamRead abytesfield value from the stream.- Specified by:
readByteBufferin classCodedInputStream- Throws:
java.io.IOException
-
readUInt32
public int readUInt32() throws java.io.IOExceptionDescription copied from class:CodedInputStreamRead auint32field value from the stream.- Specified by:
readUInt32in classCodedInputStream- Throws:
java.io.IOException
-
readEnum
public int readEnum() throws java.io.IOExceptionDescription copied from class:CodedInputStreamRead an enum field value from the stream. Caller is responsible for converting the numeric value to an actual enum.- Specified by:
readEnumin classCodedInputStream- Throws:
java.io.IOException
-
readSFixed32
public int readSFixed32() throws java.io.IOExceptionDescription copied from class:CodedInputStreamRead ansfixed32field value from the stream.- Specified by:
readSFixed32in classCodedInputStream- Throws:
java.io.IOException
-
readSFixed64
public long readSFixed64() throws java.io.IOExceptionDescription copied from class:CodedInputStreamRead ansfixed64field value from the stream.- Specified by:
readSFixed64in classCodedInputStream- Throws:
java.io.IOException
-
readSInt32
public int readSInt32() throws java.io.IOExceptionDescription copied from class:CodedInputStreamRead ansint32field value from the stream.- Specified by:
readSInt32in classCodedInputStream- Throws:
java.io.IOException
-
readSInt64
public long readSInt64() throws java.io.IOExceptionDescription copied from class:CodedInputStreamRead ansint64field value from the stream.- Specified by:
readSInt64in classCodedInputStream- Throws:
java.io.IOException
-
readRawVarint32
public int readRawVarint32() throws java.io.IOExceptionDescription copied from class:CodedInputStreamRead a raw Varint from the stream. If larger than 32 bits, discard the upper bits.- Specified by:
readRawVarint32in classCodedInputStream- Throws:
java.io.IOException
-
readRawVarint64
public long readRawVarint64() throws java.io.IOExceptionDescription copied from class:CodedInputStreamRead a raw Varint from the stream.- Specified by:
readRawVarint64in classCodedInputStream- Throws:
java.io.IOException
-
readRawVarint64SlowPath
long readRawVarint64SlowPath() throws java.io.IOExceptionDescription copied from class:CodedInputStreamVariant of readRawVarint64 for when uncomfortably close to the limit.- Specified by:
readRawVarint64SlowPathin classCodedInputStream- Throws:
java.io.IOException
-
readRawLittleEndian32
public int readRawLittleEndian32() throws java.io.IOExceptionDescription copied from class:CodedInputStreamRead a 32-bit little-endian integer from the stream.- Specified by:
readRawLittleEndian32in classCodedInputStream- Throws:
java.io.IOException
-
readRawLittleEndian64
public long readRawLittleEndian64() throws java.io.IOExceptionDescription copied from class:CodedInputStreamRead a 64-bit little-endian integer from the stream.- Specified by:
readRawLittleEndian64in classCodedInputStream- Throws:
java.io.IOException
-
enableAliasing
public void enableAliasing(boolean enabled)
Description copied from class:CodedInputStreamEnablesByteStringaliasing of the underlying buffer, trading off on buffer pinning for data copies. Only valid for buffer-backed streams.- Specified by:
enableAliasingin classCodedInputStream
-
resetSizeCounter
public void resetSizeCounter()
Description copied from class:CodedInputStreamResets the current size counter to zero (seeCodedInputStream.setSizeLimit(int)). Only valid forInputStream-backed streams.- Specified by:
resetSizeCounterin classCodedInputStream
-
pushLimit
public int pushLimit(int byteLimit) throws InvalidProtocolBufferExceptionDescription copied from class:CodedInputStreamSetscurrentLimitto (current position) +byteLimit. This is called when descending into a length-delimited embedded message.Note that
pushLimit()does NOT affect how many bytes theCodedInputStreamreads from an underlyingInputStreamwhen 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 yourInputStreamwhich limits the amount of data that can be read from it.- Specified by:
pushLimitin classCodedInputStream- Returns:
- the old limit.
- Throws:
InvalidProtocolBufferException
-
recomputeBufferSizeAfterLimit
private void recomputeBufferSizeAfterLimit()
-
popLimit
public void popLimit(int oldLimit)
Description copied from class:CodedInputStreamDiscards the current limit, returning to the previous limit.- Specified by:
popLimitin classCodedInputStream- Parameters:
oldLimit- The old limit, as returned bypushLimit.
-
getBytesUntilLimit
public int getBytesUntilLimit()
Description copied from class:CodedInputStreamReturns the number of bytes to be read before the current limit. If no limit is set, returns -1.- Specified by:
getBytesUntilLimitin classCodedInputStream
-
isAtEnd
public boolean isAtEnd() throws java.io.IOExceptionDescription copied from class:CodedInputStreamReturns 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:
isAtEndin classCodedInputStream- Throws:
java.io.IOException
-
getTotalBytesRead
public int getTotalBytesRead()
Description copied from class:CodedInputStreamThe total bytes read up to the current position. CallingCodedInputStream.resetSizeCounter()resets this value to zero.- Specified by:
getTotalBytesReadin classCodedInputStream
-
readRawByte
public byte readRawByte() throws java.io.IOExceptionDescription copied from class:CodedInputStreamRead one byte from the input.- Specified by:
readRawBytein classCodedInputStream- Throws:
InvalidProtocolBufferException- The end of the stream or the current limit was reached.java.io.IOException
-
readRawBytes
public byte[] readRawBytes(int length) throws java.io.IOExceptionDescription copied from class:CodedInputStreamRead a fixed size of bytes from the input.- Specified by:
readRawBytesin classCodedInputStream- Throws:
InvalidProtocolBufferException- The end of the stream or the current limit was reached.java.io.IOException
-
readRawBytesTo
private void readRawBytesTo(byte[] bytes, int offset, int length) throws java.io.IOExceptionTry to get raw bytes frominputwith the size oflengthand copy tobytesarray. If the size is bigger than the number of remaining bytes in the input, then throwtruncatedMessageexception.- Throws:
java.io.IOException
-
skipRawBytes
public void skipRawBytes(int length) throws java.io.IOExceptionDescription copied from class:CodedInputStreamReads and discardssizebytes.- Specified by:
skipRawBytesin classCodedInputStream- Throws:
InvalidProtocolBufferException- The end of the stream or the current limit was reached.java.io.IOException
-
skipRawVarint
private void skipRawVarint() throws java.io.IOException- Throws:
java.io.IOException
-
remaining
private int remaining()
Try to get the number of remaining bytes ininput.- Returns:
- the number of remaining bytes in
input.
-
currentRemaining
private long currentRemaining()
Try to get the number of remaining bytes incurrentByteBuffer.- Returns:
- the number of remaining bytes in
currentByteBuffer
-
slice
private java.nio.ByteBuffer slice(int begin, int end) throws java.io.IOException- Throws:
java.io.IOException
-
-