private static final class CodedInputStream.UnsafeDirectNioDecoder extends CodedInputStream
CodedInputStream
implementation that uses a backing direct ByteBuffer as the input.
Requires the use of sun.misc.Unsafe
to perform fast reads on the buffer.Modifier and Type | Field and Description |
---|---|
private long |
address
The unsafe address of the content of
buffer . |
private java.nio.ByteBuffer |
buffer
The direct buffer that is backing this stream.
|
private int |
bufferSizeAfterLimit
The amount of available data in the buffer beyond
limit . |
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 the buffer is backing a ByteString and is therefore
considered to be an immutable input source. |
private int |
lastTag
The last tag that was read from this stream.
|
private long |
limit
The unsafe address of the current read limit of the buffer.
|
private long |
pos
The unsafe address of the current read position of the buffer.
|
private long |
startPos
The unsafe address of the starting read position.
|
recursionDepth, recursionLimit, sizeLimit
Modifier | Constructor and Description |
---|---|
private |
UnsafeDirectNioDecoder(java.nio.ByteBuffer buffer,
boolean immutable) |
Modifier and Type | Method and Description |
---|---|
private int |
bufferPos(long pos) |
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.
|
(package private) static boolean |
isSupported() |
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.
|
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() |
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 void |
skipRawVarintFastPath() |
private void |
skipRawVarintSlowPath() |
private java.nio.ByteBuffer |
slice(long begin,
long end) |
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.nio.ByteBuffer buffer
private final boolean immutable
true
, indicates that the buffer is backing a ByteString
and is therefore
considered to be an immutable input source.private final long address
buffer
.private long limit
private long pos
private long startPos
private int bufferSizeAfterLimit
limit
.private int lastTag
private boolean enableAliasing
true
, indicates that calls to read ByteString
or byte[]
may return slices of the underlying buffer, rather than copies.private int currentLimit
private UnsafeDirectNioDecoder(java.nio.ByteBuffer buffer, boolean immutable)
static boolean isSupported()
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
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
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 length) throws java.io.IOException
CodedInputStream
readRawBytes
in class CodedInputStream
InvalidProtocolBufferException
- The end of the stream or the current limit was reached.java.io.IOException
public void skipRawBytes(int length) 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 recomputeBufferSizeAfterLimit()
private int remaining()
private int bufferPos(long pos)
private java.nio.ByteBuffer slice(long begin, long end) throws java.io.IOException
java.io.IOException