Package com.google.protobuf
Class BinaryReader.SafeHeapReader
- java.lang.Object
-
- com.google.protobuf.BinaryReader
-
- com.google.protobuf.BinaryReader.SafeHeapReader
-
- All Implemented Interfaces:
Reader
- Enclosing class:
- BinaryReader
private static final class BinaryReader.SafeHeapReader extends BinaryReader
ABinaryReader
implementation that operates on a heapByteBuffer
. Uses only safe operations on the underlying array.
-
-
Field Summary
Fields Modifier and Type Field Description private byte[]
buffer
private boolean
bufferIsImmutable
private int
endGroupTag
private int
initialPos
private int
limit
private int
pos
private int
tag
-
Fields inherited from interface com.google.protobuf.Reader
READ_DONE, TAG_UNKNOWN
-
-
Constructor Summary
Constructors Constructor Description SafeHeapReader(java.nio.ByteBuffer bytebuf, boolean bufferIsImmutable)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description int
getFieldNumber()
Gets the field number for the current field being read.int
getTag()
Gets the wire tag of the current field.int
getTotalBytesRead()
Returns the total number of bytes read so far from the input buffer.private boolean
isAtEnd()
<T> void
mergeGroupField(T target, Schema<T> schema, ExtensionRegistryLite extensionRegistry)
Read a group field from the wire format and merge the results into the given target.<T> void
mergeMessageField(T target, Schema<T> schema, ExtensionRegistryLite extensionRegistry)
Read a message field from the wire format and merge the results into the given target.boolean
readBool()
Reads and returns the next field of typeBOOL
and advances the reader to the next field.void
readBoolList(java.util.List<java.lang.Boolean> target)
Reads the next field of typeBOOL_LIST
orBOOL_LIST_PACKED
and advances the reader to the next field.private byte
readByte()
ByteString
readBytes()
Reads and returns the next field of typeBYTES
and advances the reader to the next field.void
readBytesList(java.util.List<ByteString> target)
Reads the next field of typeBYTES_LIST
and advances the reader to the next field.double
readDouble()
Reads and returns the next field of typeDOUBLE
and advances the reader to the next field.void
readDoubleList(java.util.List<java.lang.Double> target)
Reads the next field of typeDOUBLE_LIST
orDOUBLE_LIST_PACKED
and advances the reader to the next field.int
readEnum()
Reads and returns the next field of typeENUM
and advances the reader to the next field.void
readEnumList(java.util.List<java.lang.Integer> target)
Reads the next field of typeENUM_LIST
orENUM_LIST_PACKED
and advances the reader to the next field.private java.lang.Object
readField(WireFormat.FieldType fieldType, java.lang.Class<?> messageType, ExtensionRegistryLite extensionRegistry)
int
readFixed32()
Reads and returns the next field of typeFIXED32
and advances the reader to the next field.void
readFixed32List(java.util.List<java.lang.Integer> target)
Reads the next field of typeFIXED32_LIST
orFIXED32_LIST_PACKED
and advances the reader to the next field.long
readFixed64()
Reads and returns the next field of typeFIXED64
and advances the reader to the next field.void
readFixed64List(java.util.List<java.lang.Long> target)
Reads the next field of typeFIXED64_LIST
orFIXED64_LIST_PACKED
and advances the reader to the next field.float
readFloat()
Reads and returns the next field of typeFLOAT
and advances the reader to the next field.void
readFloatList(java.util.List<java.lang.Float> target)
Reads the next field of typeFLOAT_LIST
orFLOAT_LIST_PACKED
and advances the reader to the next field.private <T> T
readGroup(Schema<T> schema, ExtensionRegistryLite extensionRegistry)
<T> T
readGroup(java.lang.Class<T> clazz, ExtensionRegistryLite extensionRegistry)
Reads and returns the next field of typeGROUP
and advances the reader to the next field.<T> T
readGroupBySchemaWithCheck(Schema<T> schema, ExtensionRegistryLite extensionRegistry)
<T> void
readGroupList(java.util.List<T> target, Schema<T> schema, ExtensionRegistryLite extensionRegistry)
<T> void
readGroupList(java.util.List<T> target, java.lang.Class<T> targetType, ExtensionRegistryLite extensionRegistry)
Reads the next field of typeGROUP_LIST
and advances the reader to the next field.int
readInt32()
Reads and returns the next field of typeINT32
and advances the reader to the next field.void
readInt32List(java.util.List<java.lang.Integer> target)
Reads the next field of typeINT32_LIST
orINT32_LIST_PACKED
and advances the reader to the next field.long
readInt64()
Reads and returns the next field of typeINT64
and advances the reader to the next field.void
readInt64List(java.util.List<java.lang.Long> target)
Reads the next field of typeINT64_LIST
orINT64_LIST_PACKED
and advances the reader to the next field.private int
readLittleEndian32()
private int
readLittleEndian32_NoCheck()
private long
readLittleEndian64()
private long
readLittleEndian64_NoCheck()
<K,V>
voidreadMap(java.util.Map<K,V> target, MapEntryLite.Metadata<K,V> metadata, ExtensionRegistryLite extensionRegistry)
Reads the next field of typeMAP
and advances the reader to the next field.private <T> T
readMessage(Schema<T> schema, ExtensionRegistryLite extensionRegistry)
<T> T
readMessage(java.lang.Class<T> clazz, ExtensionRegistryLite extensionRegistry)
Reads and returns the next field of typeMESSAGE
and advances the reader to the next field.<T> T
readMessageBySchemaWithCheck(Schema<T> schema, ExtensionRegistryLite extensionRegistry)
<T> void
readMessageList(java.util.List<T> target, Schema<T> schema, ExtensionRegistryLite extensionRegistry)
Reads the next field of typeMESSAGE_LIST
and advances the reader to the next field.<T> void
readMessageList(java.util.List<T> target, java.lang.Class<T> targetType, ExtensionRegistryLite extensionRegistry)
int
readSFixed32()
Reads and returns the next field of typeSFIXED32
and advances the reader to the next field.void
readSFixed32List(java.util.List<java.lang.Integer> target)
Reads the next field of typeSFIXED32_LIST
orSFIXED32_LIST_PACKED
and advances the reader to the next field.long
readSFixed64()
Reads and returns the next field of typeSFIXED64
and advances the reader to the next field.void
readSFixed64List(java.util.List<java.lang.Long> target)
Reads the next field of typeSFIXED64_LIST
orSFIXED64_LIST_PACKED
and advances the reader to the next field.int
readSInt32()
Reads and returns the next field of typeSINT32
and advances the reader to the next field.void
readSInt32List(java.util.List<java.lang.Integer> target)
Reads the next field of typeSINT32_LIST
orSINT32_LIST_PACKED
and advances the reader to the next field.long
readSInt64()
Reads and returns the next field of typeSINT64
and advances the reader to the next field.void
readSInt64List(java.util.List<java.lang.Long> target)
Reads the next field of typeSINT64_LIST
orSINT64_LIST_PACKED
and advances the reader to the next field.java.lang.String
readString()
Reads and returns the next field of typeSTRING
and advances the reader to the next field.java.lang.String
readStringInternal(boolean requireUtf8)
void
readStringList(java.util.List<java.lang.String> target)
Reads the next field of typeSTRING_LIST
and advances the reader to the next field.void
readStringListInternal(java.util.List<java.lang.String> target, boolean requireUtf8)
void
readStringListRequireUtf8(java.util.List<java.lang.String> target)
Reads the next field of typeSTRING_LIST
and advances the reader to the next field.java.lang.String
readStringRequireUtf8()
Reads and returns the next field of typeSTRING
and advances the reader to the next field.int
readUInt32()
Reads and returns the next field of typeUINT32
and advances the reader to the next field.void
readUInt32List(java.util.List<java.lang.Integer> target)
Reads the next field of typeUINT32_LIST
orUINT32_LIST_PACKED
and advances the reader to the next field.long
readUInt64()
Reads and returns the next field of typeUINT64
and advances the reader to the next field.void
readUInt64List(java.util.List<java.lang.Long> target)
Reads the next field of typeUINT64_LIST
orUINT64_LIST_PACKED
and advances the reader to the next field.private int
readVarint32()
Read a raw Varint from the stream.long
readVarint64()
private long
readVarint64SlowPath()
private void
requireBytes(int size)
private void
requirePosition(int expectedPosition)
private void
requireWireType(int requiredWireType)
private void
skipBytes(int size)
boolean
skipField()
Skips the current field and advances the reader to the next field.private void
skipGroup()
private void
skipVarint()
private void
skipVarintSlowPath()
private void
verifyPackedFixed32Length(int bytes)
private void
verifyPackedFixed64Length(int bytes)
-
Methods inherited from class com.google.protobuf.BinaryReader
newInstance, shouldDiscardUnknownFields
-
-
-
-
Method Detail
-
isAtEnd
private boolean isAtEnd()
-
getTotalBytesRead
public int getTotalBytesRead()
Description copied from class:BinaryReader
Returns the total number of bytes read so far from the input buffer.- Specified by:
getTotalBytesRead
in classBinaryReader
-
getFieldNumber
public int getFieldNumber() throws java.io.IOException
Description copied from interface:Reader
Gets the field number for the current field being read.TODO(liujisi): Rename it to make it more explicit about the side effect on the underlying buffer.
- Returns:
- the current field number or
Reader.READ_DONE
if the end of input has been reached. - Throws:
java.io.IOException
-
getTag
public int getTag()
Description copied from interface:Reader
Gets the wire tag of the current field.- Returns:
- the current wire tag or
Reader.TAG_UNKNOWN
if the reader does not know the tag of the current field.
-
skipField
public boolean skipField() throws java.io.IOException
Description copied from interface:Reader
Skips the current field and advances the reader to the next field.- Returns:
true
if there are more fields orfalse
if the end of input has been reached.- Throws:
java.io.IOException
-
readDouble
public double readDouble() throws java.io.IOException
Description copied from interface:Reader
Reads and returns the next field of typeDOUBLE
and advances the reader to the next field.- Throws:
java.io.IOException
-
readFloat
public float readFloat() throws java.io.IOException
Description copied from interface:Reader
Reads and returns the next field of typeFLOAT
and advances the reader to the next field.- Throws:
java.io.IOException
-
readUInt64
public long readUInt64() throws java.io.IOException
Description copied from interface:Reader
Reads and returns the next field of typeUINT64
and advances the reader to the next field.- Throws:
java.io.IOException
-
readInt64
public long readInt64() throws java.io.IOException
Description copied from interface:Reader
Reads and returns the next field of typeINT64
and advances the reader to the next field.- Throws:
java.io.IOException
-
readInt32
public int readInt32() throws java.io.IOException
Description copied from interface:Reader
Reads and returns the next field of typeINT32
and advances the reader to the next field.- Throws:
java.io.IOException
-
readFixed64
public long readFixed64() throws java.io.IOException
Description copied from interface:Reader
Reads and returns the next field of typeFIXED64
and advances the reader to the next field.- Throws:
java.io.IOException
-
readFixed32
public int readFixed32() throws java.io.IOException
Description copied from interface:Reader
Reads and returns the next field of typeFIXED32
and advances the reader to the next field.- Throws:
java.io.IOException
-
readBool
public boolean readBool() throws java.io.IOException
Description copied from interface:Reader
Reads and returns the next field of typeBOOL
and advances the reader to the next field.- Throws:
java.io.IOException
-
readString
public java.lang.String readString() throws java.io.IOException
Description copied from interface:Reader
Reads and returns the next field of typeSTRING
and advances the reader to the next field. If the stream contains malformed UTF-8, replace the offending bytes with the standard UTF-8 replacement character.- Throws:
java.io.IOException
-
readStringRequireUtf8
public java.lang.String readStringRequireUtf8() throws java.io.IOException
Description copied from interface:Reader
Reads and returns the next field of typeSTRING
and advances the reader to the next field. If the stream contains malformed UTF-8, throw exceptionInvalidProtocolBufferException
.- Throws:
java.io.IOException
-
readStringInternal
public java.lang.String readStringInternal(boolean requireUtf8) throws java.io.IOException
- Throws:
java.io.IOException
-
readMessage
public <T> T readMessage(java.lang.Class<T> clazz, ExtensionRegistryLite extensionRegistry) throws java.io.IOException
Description copied from interface:Reader
Reads and returns the next field of typeMESSAGE
and advances the reader to the next field.- Throws:
java.io.IOException
-
readMessageBySchemaWithCheck
public <T> T readMessageBySchemaWithCheck(Schema<T> schema, ExtensionRegistryLite extensionRegistry) throws java.io.IOException
- Throws:
java.io.IOException
-
readMessage
private <T> T readMessage(Schema<T> schema, ExtensionRegistryLite extensionRegistry) throws java.io.IOException
- Throws:
java.io.IOException
-
mergeMessageField
public <T> void mergeMessageField(T target, Schema<T> schema, ExtensionRegistryLite extensionRegistry) throws java.io.IOException
Description copied from interface:Reader
Read a message field from the wire format and merge the results into the given target.- Throws:
java.io.IOException
-
readGroup
public <T> T readGroup(java.lang.Class<T> clazz, ExtensionRegistryLite extensionRegistry) throws java.io.IOException
Description copied from interface:Reader
Reads and returns the next field of typeGROUP
and advances the reader to the next field.- Throws:
java.io.IOException
-
readGroupBySchemaWithCheck
public <T> T readGroupBySchemaWithCheck(Schema<T> schema, ExtensionRegistryLite extensionRegistry) throws java.io.IOException
- Throws:
java.io.IOException
-
readGroup
private <T> T readGroup(Schema<T> schema, ExtensionRegistryLite extensionRegistry) throws java.io.IOException
- Throws:
java.io.IOException
-
mergeGroupField
public <T> void mergeGroupField(T target, Schema<T> schema, ExtensionRegistryLite extensionRegistry) throws java.io.IOException
Description copied from interface:Reader
Read a group field from the wire format and merge the results into the given target.- Throws:
java.io.IOException
-
readBytes
public ByteString readBytes() throws java.io.IOException
Description copied from interface:Reader
Reads and returns the next field of typeBYTES
and advances the reader to the next field.- Throws:
java.io.IOException
-
readUInt32
public int readUInt32() throws java.io.IOException
Description copied from interface:Reader
Reads and returns the next field of typeUINT32
and advances the reader to the next field.- Throws:
java.io.IOException
-
readEnum
public int readEnum() throws java.io.IOException
Description copied from interface:Reader
Reads and returns the next field of typeENUM
and advances the reader to the next field.- Throws:
java.io.IOException
-
readSFixed32
public int readSFixed32() throws java.io.IOException
Description copied from interface:Reader
Reads and returns the next field of typeSFIXED32
and advances the reader to the next field.- Throws:
java.io.IOException
-
readSFixed64
public long readSFixed64() throws java.io.IOException
Description copied from interface:Reader
Reads and returns the next field of typeSFIXED64
and advances the reader to the next field.- Throws:
java.io.IOException
-
readSInt32
public int readSInt32() throws java.io.IOException
Description copied from interface:Reader
Reads and returns the next field of typeSINT32
and advances the reader to the next field.- Throws:
java.io.IOException
-
readSInt64
public long readSInt64() throws java.io.IOException
Description copied from interface:Reader
Reads and returns the next field of typeSINT64
and advances the reader to the next field.- Throws:
java.io.IOException
-
readDoubleList
public void readDoubleList(java.util.List<java.lang.Double> target) throws java.io.IOException
Description copied from interface:Reader
Reads the next field of typeDOUBLE_LIST
orDOUBLE_LIST_PACKED
and advances the reader to the next field.- Parameters:
target
- the list that will receive the read values.- Throws:
java.io.IOException
-
readFloatList
public void readFloatList(java.util.List<java.lang.Float> target) throws java.io.IOException
Description copied from interface:Reader
Reads the next field of typeFLOAT_LIST
orFLOAT_LIST_PACKED
and advances the reader to the next field.- Parameters:
target
- the list that will receive the read values.- Throws:
java.io.IOException
-
readUInt64List
public void readUInt64List(java.util.List<java.lang.Long> target) throws java.io.IOException
Description copied from interface:Reader
Reads the next field of typeUINT64_LIST
orUINT64_LIST_PACKED
and advances the reader to the next field.- Parameters:
target
- the list that will receive the read values.- Throws:
java.io.IOException
-
readInt64List
public void readInt64List(java.util.List<java.lang.Long> target) throws java.io.IOException
Description copied from interface:Reader
Reads the next field of typeINT64_LIST
orINT64_LIST_PACKED
and advances the reader to the next field.- Parameters:
target
- the list that will receive the read values.- Throws:
java.io.IOException
-
readInt32List
public void readInt32List(java.util.List<java.lang.Integer> target) throws java.io.IOException
Description copied from interface:Reader
Reads the next field of typeINT32_LIST
orINT32_LIST_PACKED
and advances the reader to the next field.- Parameters:
target
- the list that will receive the read values.- Throws:
java.io.IOException
-
readFixed64List
public void readFixed64List(java.util.List<java.lang.Long> target) throws java.io.IOException
Description copied from interface:Reader
Reads the next field of typeFIXED64_LIST
orFIXED64_LIST_PACKED
and advances the reader to the next field.- Parameters:
target
- the list that will receive the read values.- Throws:
java.io.IOException
-
readFixed32List
public void readFixed32List(java.util.List<java.lang.Integer> target) throws java.io.IOException
Description copied from interface:Reader
Reads the next field of typeFIXED32_LIST
orFIXED32_LIST_PACKED
and advances the reader to the next field.- Parameters:
target
- the list that will receive the read values.- Throws:
java.io.IOException
-
readBoolList
public void readBoolList(java.util.List<java.lang.Boolean> target) throws java.io.IOException
Description copied from interface:Reader
Reads the next field of typeBOOL_LIST
orBOOL_LIST_PACKED
and advances the reader to the next field.- Parameters:
target
- the list that will receive the read values.- Throws:
java.io.IOException
-
readStringList
public void readStringList(java.util.List<java.lang.String> target) throws java.io.IOException
Description copied from interface:Reader
Reads the next field of typeSTRING_LIST
and advances the reader to the next field.- Parameters:
target
- the list that will receive the read values.- Throws:
java.io.IOException
-
readStringListRequireUtf8
public void readStringListRequireUtf8(java.util.List<java.lang.String> target) throws java.io.IOException
Description copied from interface:Reader
Reads the next field of typeSTRING_LIST
and advances the reader to the next field. If the stream contains malformed UTF-8, throw exceptionInvalidProtocolBufferException
.- Parameters:
target
- the list that will receive the read values.- Throws:
java.io.IOException
-
readStringListInternal
public void readStringListInternal(java.util.List<java.lang.String> target, boolean requireUtf8) throws java.io.IOException
- Throws:
java.io.IOException
-
readMessageList
public <T> void readMessageList(java.util.List<T> target, java.lang.Class<T> targetType, ExtensionRegistryLite extensionRegistry) throws java.io.IOException
- Throws:
java.io.IOException
-
readMessageList
public <T> void readMessageList(java.util.List<T> target, Schema<T> schema, ExtensionRegistryLite extensionRegistry) throws java.io.IOException
Description copied from interface:Reader
Reads the next field of typeMESSAGE_LIST
and advances the reader to the next field.- Parameters:
target
- the list that will receive the read values.- Throws:
java.io.IOException
-
readGroupList
public <T> void readGroupList(java.util.List<T> target, java.lang.Class<T> targetType, ExtensionRegistryLite extensionRegistry) throws java.io.IOException
Description copied from interface:Reader
Reads the next field of typeGROUP_LIST
and advances the reader to the next field.- Parameters:
target
- the list that will receive the read values.targetType
- the type of the elements stored in thetarget
list.- Throws:
java.io.IOException
-
readGroupList
public <T> void readGroupList(java.util.List<T> target, Schema<T> schema, ExtensionRegistryLite extensionRegistry) throws java.io.IOException
- Throws:
java.io.IOException
-
readBytesList
public void readBytesList(java.util.List<ByteString> target) throws java.io.IOException
Description copied from interface:Reader
Reads the next field of typeBYTES_LIST
and advances the reader to the next field.- Parameters:
target
- the list that will receive the read values.- Throws:
java.io.IOException
-
readUInt32List
public void readUInt32List(java.util.List<java.lang.Integer> target) throws java.io.IOException
Description copied from interface:Reader
Reads the next field of typeUINT32_LIST
orUINT32_LIST_PACKED
and advances the reader to the next field.- Parameters:
target
- the list that will receive the read values.- Throws:
java.io.IOException
-
readEnumList
public void readEnumList(java.util.List<java.lang.Integer> target) throws java.io.IOException
Description copied from interface:Reader
Reads the next field of typeENUM_LIST
orENUM_LIST_PACKED
and advances the reader to the next field.- Parameters:
target
- the list that will receive the read values.- Throws:
java.io.IOException
-
readSFixed32List
public void readSFixed32List(java.util.List<java.lang.Integer> target) throws java.io.IOException
Description copied from interface:Reader
Reads the next field of typeSFIXED32_LIST
orSFIXED32_LIST_PACKED
and advances the reader to the next field.- Parameters:
target
- the list that will receive the read values.- Throws:
java.io.IOException
-
readSFixed64List
public void readSFixed64List(java.util.List<java.lang.Long> target) throws java.io.IOException
Description copied from interface:Reader
Reads the next field of typeSFIXED64_LIST
orSFIXED64_LIST_PACKED
and advances the reader to the next field.- Parameters:
target
- the list that will receive the read values.- Throws:
java.io.IOException
-
readSInt32List
public void readSInt32List(java.util.List<java.lang.Integer> target) throws java.io.IOException
Description copied from interface:Reader
Reads the next field of typeSINT32_LIST
orSINT32_LIST_PACKED
and advances the reader to the next field.- Parameters:
target
- the list that will receive the read values.- Throws:
java.io.IOException
-
readSInt64List
public void readSInt64List(java.util.List<java.lang.Long> target) throws java.io.IOException
Description copied from interface:Reader
Reads the next field of typeSINT64_LIST
orSINT64_LIST_PACKED
and advances the reader to the next field.- Parameters:
target
- the list that will receive the read values.- Throws:
java.io.IOException
-
readMap
public <K,V> void readMap(java.util.Map<K,V> target, MapEntryLite.Metadata<K,V> metadata, ExtensionRegistryLite extensionRegistry) throws java.io.IOException
Description copied from interface:Reader
Reads the next field of typeMAP
and advances the reader to the next field.- Parameters:
target
- the mutable map that will receive the read values.metadata
- the default entry of the map field.extensionRegistry
- the extension registry for parsing message value fields.- Throws:
java.io.IOException
-
readField
private java.lang.Object readField(WireFormat.FieldType fieldType, java.lang.Class<?> messageType, ExtensionRegistryLite extensionRegistry) throws java.io.IOException
- Throws:
java.io.IOException
-
readVarint32
private int readVarint32() throws java.io.IOException
Read a raw Varint from the stream. If larger than 32 bits, discard the upper bits.- Throws:
java.io.IOException
-
readVarint64
public long readVarint64() throws java.io.IOException
- Throws:
java.io.IOException
-
readVarint64SlowPath
private long readVarint64SlowPath() throws java.io.IOException
- Throws:
java.io.IOException
-
readByte
private byte readByte() throws java.io.IOException
- Throws:
java.io.IOException
-
readLittleEndian32
private int readLittleEndian32() throws java.io.IOException
- Throws:
java.io.IOException
-
readLittleEndian64
private long readLittleEndian64() throws java.io.IOException
- Throws:
java.io.IOException
-
readLittleEndian32_NoCheck
private int readLittleEndian32_NoCheck()
-
readLittleEndian64_NoCheck
private long readLittleEndian64_NoCheck()
-
skipVarint
private void skipVarint() throws java.io.IOException
- Throws:
java.io.IOException
-
skipVarintSlowPath
private void skipVarintSlowPath() throws java.io.IOException
- Throws:
java.io.IOException
-
skipBytes
private void skipBytes(int size) throws java.io.IOException
- Throws:
java.io.IOException
-
skipGroup
private void skipGroup() throws java.io.IOException
- Throws:
java.io.IOException
-
requireBytes
private void requireBytes(int size) throws java.io.IOException
- Throws:
java.io.IOException
-
requireWireType
private void requireWireType(int requiredWireType) throws java.io.IOException
- Throws:
java.io.IOException
-
verifyPackedFixed64Length
private void verifyPackedFixed64Length(int bytes) throws java.io.IOException
- Throws:
java.io.IOException
-
verifyPackedFixed32Length
private void verifyPackedFixed32Length(int bytes) throws java.io.IOException
- Throws:
java.io.IOException
-
requirePosition
private void requirePosition(int expectedPosition) throws java.io.IOException
- Throws:
java.io.IOException
-
-