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
A
BinaryReader implementation that operates on a heap ByteBuffer. Uses only
safe operations on the underlying array.-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final byte[]private final booleanprivate intprivate final intprivate intprivate intprivate intFields inherited from interface com.google.protobuf.Reader
READ_DONE, TAG_UNKNOWN -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionintGets the field number for the current field being read.intgetTag()Gets the wire tag of the current field.intReturns the total number of bytes read so far from the input buffer.private booleanisAtEnd()<T> voidmergeGroupField(T target, Schema<T> schema, ExtensionRegistryLite extensionRegistry) Read a group field from the wire format and merge the results into the given target.<T> voidmergeMessageField(T target, Schema<T> schema, ExtensionRegistryLite extensionRegistry) Read a message field from the wire format and merge the results into the given target.booleanreadBool()Reads and returns the next field of typeBOOLand advances the reader to the next field.voidreadBoolList(List<Boolean> target) Reads the next field of typeBOOL_LISTorBOOL_LIST_PACKEDand advances the reader to the next field.private bytereadByte()Reads and returns the next field of typeBYTESand advances the reader to the next field.voidreadBytesList(List<ByteString> target) Reads the next field of typeBYTES_LISTand advances the reader to the next field.doubleReads and returns the next field of typeDOUBLEand advances the reader to the next field.voidreadDoubleList(List<Double> target) Reads the next field of typeDOUBLE_LISTorDOUBLE_LIST_PACKEDand advances the reader to the next field.intreadEnum()Reads and returns the next field of typeENUMand advances the reader to the next field.voidreadEnumList(List<Integer> target) Reads the next field of typeENUM_LISTorENUM_LIST_PACKEDand advances the reader to the next field.private ObjectreadField(WireFormat.FieldType fieldType, Class<?> messageType, ExtensionRegistryLite extensionRegistry) intReads and returns the next field of typeFIXED32and advances the reader to the next field.voidreadFixed32List(List<Integer> target) Reads the next field of typeFIXED32_LISTorFIXED32_LIST_PACKEDand advances the reader to the next field.longReads and returns the next field of typeFIXED64and advances the reader to the next field.voidreadFixed64List(List<Long> target) Reads the next field of typeFIXED64_LISTorFIXED64_LIST_PACKEDand advances the reader to the next field.floatReads and returns the next field of typeFLOATand advances the reader to the next field.voidreadFloatList(List<Float> target) Reads the next field of typeFLOAT_LISTorFLOAT_LIST_PACKEDand advances the reader to the next field.private <T> TreadGroup(Schema<T> schema, ExtensionRegistryLite extensionRegistry) <T> TreadGroup(Class<T> clazz, ExtensionRegistryLite extensionRegistry) Deprecated.<T> TreadGroupBySchemaWithCheck(Schema<T> schema, ExtensionRegistryLite extensionRegistry) Deprecated.<T> voidreadGroupList(List<T> target, Schema<T> schema, ExtensionRegistryLite extensionRegistry) Deprecated.<T> voidreadGroupList(List<T> target, Class<T> targetType, ExtensionRegistryLite extensionRegistry) Deprecated.intReads and returns the next field of typeINT32and advances the reader to the next field.voidreadInt32List(List<Integer> target) Reads the next field of typeINT32_LISTorINT32_LIST_PACKEDand advances the reader to the next field.longReads and returns the next field of typeINT64and advances the reader to the next field.voidreadInt64List(List<Long> target) Reads the next field of typeINT64_LISTorINT64_LIST_PACKEDand advances the reader to the next field.private intprivate intprivate longprivate long<K,V> void readMap(Map<K, V> target, MapEntryLite.Metadata<K, V> metadata, ExtensionRegistryLite extensionRegistry) Reads the next field of typeMAPand advances the reader to the next field.private <T> TreadMessage(Schema<T> schema, ExtensionRegistryLite extensionRegistry) <T> TreadMessage(Class<T> clazz, ExtensionRegistryLite extensionRegistry) Reads and returns the next field of typeMESSAGEand advances the reader to the next field.<T> TreadMessageBySchemaWithCheck(Schema<T> schema, ExtensionRegistryLite extensionRegistry) <T> voidreadMessageList(List<T> target, Schema<T> schema, ExtensionRegistryLite extensionRegistry) Reads the next field of typeMESSAGE_LISTand advances the reader to the next field.<T> voidreadMessageList(List<T> target, Class<T> targetType, ExtensionRegistryLite extensionRegistry) intReads and returns the next field of typeSFIXED32and advances the reader to the next field.voidreadSFixed32List(List<Integer> target) Reads the next field of typeSFIXED32_LISTorSFIXED32_LIST_PACKEDand advances the reader to the next field.longReads and returns the next field of typeSFIXED64and advances the reader to the next field.voidreadSFixed64List(List<Long> target) Reads the next field of typeSFIXED64_LISTorSFIXED64_LIST_PACKEDand advances the reader to the next field.intReads and returns the next field of typeSINT32and advances the reader to the next field.voidreadSInt32List(List<Integer> target) Reads the next field of typeSINT32_LISTorSINT32_LIST_PACKEDand advances the reader to the next field.longReads and returns the next field of typeSINT64and advances the reader to the next field.voidreadSInt64List(List<Long> target) Reads the next field of typeSINT64_LISTorSINT64_LIST_PACKEDand advances the reader to the next field.Reads and returns the next field of typeSTRINGand advances the reader to the next field.readStringInternal(boolean requireUtf8) voidreadStringList(List<String> target) Reads the next field of typeSTRING_LISTand advances the reader to the next field.voidreadStringListInternal(List<String> target, boolean requireUtf8) voidreadStringListRequireUtf8(List<String> target) Reads the next field of typeSTRING_LISTand advances the reader to the next field.Reads and returns the next field of typeSTRINGand advances the reader to the next field.intReads and returns the next field of typeUINT32and advances the reader to the next field.voidreadUInt32List(List<Integer> target) Reads the next field of typeUINT32_LISTorUINT32_LIST_PACKEDand advances the reader to the next field.longReads and returns the next field of typeUINT64and advances the reader to the next field.voidreadUInt64List(List<Long> target) Reads the next field of typeUINT64_LISTorUINT64_LIST_PACKEDand advances the reader to the next field.private intRead a raw Varint from the stream.longprivate longprivate voidrequireBytes(int size) private voidrequirePosition(int expectedPosition) private voidrequireWireType(int requiredWireType) private voidskipBytes(int size) booleanSkips the current field and advances the reader to the next field.private voidprivate voidprivate voidprivate voidverifyPackedFixed32Length(int bytes) private voidverifyPackedFixed64Length(int bytes) Methods inherited from class com.google.protobuf.BinaryReader
newInstance, shouldDiscardUnknownFields
-
Field Details
-
bufferIsImmutable
private final boolean bufferIsImmutable -
buffer
private final byte[] buffer -
pos
private int pos -
initialPos
private final int initialPos -
limit
private int limit -
tag
private int tag -
endGroupTag
private int endGroupTag
-
-
Constructor Details
-
SafeHeapReader
-
-
Method Details
-
isAtEnd
private boolean isAtEnd() -
getTotalBytesRead
public int getTotalBytesRead()Description copied from class:BinaryReaderReturns the total number of bytes read so far from the input buffer.- Specified by:
getTotalBytesReadin classBinaryReader
-
getFieldNumber
Description copied from interface:ReaderGets the field number for the current field being read.TODO: Rename it to make it more explicit about the side effect on the underlying buffer.
- Returns:
- the current field number or
Reader.READ_DONEif the end of input has been reached. - Throws:
IOException
-
getTag
public int getTag()Description copied from interface:ReaderGets the wire tag of the current field.- Returns:
- the current wire tag or
Reader.TAG_UNKNOWNif the reader does not know the tag of the current field.
-
skipField
Description copied from interface:ReaderSkips the current field and advances the reader to the next field.- Returns:
trueif there are more fields orfalseif the end of input has been reached.- Throws:
IOException
-
readDouble
Description copied from interface:ReaderReads and returns the next field of typeDOUBLEand advances the reader to the next field.- Throws:
IOException
-
readFloat
Description copied from interface:ReaderReads and returns the next field of typeFLOATand advances the reader to the next field.- Throws:
IOException
-
readUInt64
Description copied from interface:ReaderReads and returns the next field of typeUINT64and advances the reader to the next field.- Throws:
IOException
-
readInt64
Description copied from interface:ReaderReads and returns the next field of typeINT64and advances the reader to the next field.- Throws:
IOException
-
readInt32
Description copied from interface:ReaderReads and returns the next field of typeINT32and advances the reader to the next field.- Throws:
IOException
-
readFixed64
Description copied from interface:ReaderReads and returns the next field of typeFIXED64and advances the reader to the next field.- Throws:
IOException
-
readFixed32
Description copied from interface:ReaderReads and returns the next field of typeFIXED32and advances the reader to the next field.- Throws:
IOException
-
readBool
Description copied from interface:ReaderReads and returns the next field of typeBOOLand advances the reader to the next field.- Throws:
IOException
-
readString
Description copied from interface:ReaderReads and returns the next field of typeSTRINGand 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:
IOException
-
readStringRequireUtf8
Description copied from interface:ReaderReads and returns the next field of typeSTRINGand advances the reader to the next field. If the stream contains malformed UTF-8, throw exceptionInvalidProtocolBufferException.- Throws:
IOException
-
readStringInternal
- Throws:
IOException
-
readMessage
public <T> T readMessage(Class<T> clazz, ExtensionRegistryLite extensionRegistry) throws IOException Description copied from interface:ReaderReads and returns the next field of typeMESSAGEand advances the reader to the next field.- Throws:
IOException
-
readMessageBySchemaWithCheck
public <T> T readMessageBySchemaWithCheck(Schema<T> schema, ExtensionRegistryLite extensionRegistry) throws IOException - Throws:
IOException
-
readMessage
private <T> T readMessage(Schema<T> schema, ExtensionRegistryLite extensionRegistry) throws IOException - Throws:
IOException
-
mergeMessageField
public <T> void mergeMessageField(T target, Schema<T> schema, ExtensionRegistryLite extensionRegistry) throws IOException Description copied from interface:ReaderRead a message field from the wire format and merge the results into the given target.- Throws:
IOException
-
readGroup
@Deprecated public <T> T readGroup(Class<T> clazz, ExtensionRegistryLite extensionRegistry) throws IOException Deprecated.Description copied from interface:ReaderReads and returns the next field of typeGROUPand advances the reader to the next field.- Throws:
IOException
-
readGroupBySchemaWithCheck
@Deprecated public <T> T readGroupBySchemaWithCheck(Schema<T> schema, ExtensionRegistryLite extensionRegistry) throws IOException Deprecated.- Throws:
IOException
-
readGroup
private <T> T readGroup(Schema<T> schema, ExtensionRegistryLite extensionRegistry) throws IOException - Throws:
IOException
-
mergeGroupField
public <T> void mergeGroupField(T target, Schema<T> schema, ExtensionRegistryLite extensionRegistry) throws IOException Description copied from interface:ReaderRead a group field from the wire format and merge the results into the given target.- Throws:
IOException
-
readBytes
Description copied from interface:ReaderReads and returns the next field of typeBYTESand advances the reader to the next field.- Throws:
IOException
-
readUInt32
Description copied from interface:ReaderReads and returns the next field of typeUINT32and advances the reader to the next field.- Throws:
IOException
-
readEnum
Description copied from interface:ReaderReads and returns the next field of typeENUMand advances the reader to the next field.- Throws:
IOException
-
readSFixed32
Description copied from interface:ReaderReads and returns the next field of typeSFIXED32and advances the reader to the next field.- Throws:
IOException
-
readSFixed64
Description copied from interface:ReaderReads and returns the next field of typeSFIXED64and advances the reader to the next field.- Throws:
IOException
-
readSInt32
Description copied from interface:ReaderReads and returns the next field of typeSINT32and advances the reader to the next field.- Throws:
IOException
-
readSInt64
Description copied from interface:ReaderReads and returns the next field of typeSINT64and advances the reader to the next field.- Throws:
IOException
-
readDoubleList
Description copied from interface:ReaderReads the next field of typeDOUBLE_LISTorDOUBLE_LIST_PACKEDand advances the reader to the next field.- Parameters:
target- the list that will receive the read values.- Throws:
IOException
-
readFloatList
Description copied from interface:ReaderReads the next field of typeFLOAT_LISTorFLOAT_LIST_PACKEDand advances the reader to the next field.- Parameters:
target- the list that will receive the read values.- Throws:
IOException
-
readUInt64List
Description copied from interface:ReaderReads the next field of typeUINT64_LISTorUINT64_LIST_PACKEDand advances the reader to the next field.- Parameters:
target- the list that will receive the read values.- Throws:
IOException
-
readInt64List
Description copied from interface:ReaderReads the next field of typeINT64_LISTorINT64_LIST_PACKEDand advances the reader to the next field.- Parameters:
target- the list that will receive the read values.- Throws:
IOException
-
readInt32List
Description copied from interface:ReaderReads the next field of typeINT32_LISTorINT32_LIST_PACKEDand advances the reader to the next field.- Parameters:
target- the list that will receive the read values.- Throws:
IOException
-
readFixed64List
Description copied from interface:ReaderReads the next field of typeFIXED64_LISTorFIXED64_LIST_PACKEDand advances the reader to the next field.- Parameters:
target- the list that will receive the read values.- Throws:
IOException
-
readFixed32List
Description copied from interface:ReaderReads the next field of typeFIXED32_LISTorFIXED32_LIST_PACKEDand advances the reader to the next field.- Parameters:
target- the list that will receive the read values.- Throws:
IOException
-
readBoolList
Description copied from interface:ReaderReads the next field of typeBOOL_LISTorBOOL_LIST_PACKEDand advances the reader to the next field.- Parameters:
target- the list that will receive the read values.- Throws:
IOException
-
readStringList
Description copied from interface:ReaderReads the next field of typeSTRING_LISTand advances the reader to the next field.- Parameters:
target- the list that will receive the read values.- Throws:
IOException
-
readStringListRequireUtf8
Description copied from interface:ReaderReads the next field of typeSTRING_LISTand 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:
IOException
-
readStringListInternal
- Throws:
IOException
-
readMessageList
public <T> void readMessageList(List<T> target, Class<T> targetType, ExtensionRegistryLite extensionRegistry) throws IOException - Throws:
IOException
-
readMessageList
public <T> void readMessageList(List<T> target, Schema<T> schema, ExtensionRegistryLite extensionRegistry) throws IOException Description copied from interface:ReaderReads the next field of typeMESSAGE_LISTand advances the reader to the next field.- Parameters:
target- the list that will receive the read values.- Throws:
IOException
-
readGroupList
@Deprecated public <T> void readGroupList(List<T> target, Class<T> targetType, ExtensionRegistryLite extensionRegistry) throws IOException Deprecated.Description copied from interface:ReaderReads the next field of typeGROUP_LISTand 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 thetargetlist.- Throws:
IOException
-
readGroupList
@Deprecated public <T> void readGroupList(List<T> target, Schema<T> schema, ExtensionRegistryLite extensionRegistry) throws IOException Deprecated.- Throws:
IOException
-
readBytesList
Description copied from interface:ReaderReads the next field of typeBYTES_LISTand advances the reader to the next field.- Parameters:
target- the list that will receive the read values.- Throws:
IOException
-
readUInt32List
Description copied from interface:ReaderReads the next field of typeUINT32_LISTorUINT32_LIST_PACKEDand advances the reader to the next field.- Parameters:
target- the list that will receive the read values.- Throws:
IOException
-
readEnumList
Description copied from interface:ReaderReads the next field of typeENUM_LISTorENUM_LIST_PACKEDand advances the reader to the next field.- Parameters:
target- the list that will receive the read values.- Throws:
IOException
-
readSFixed32List
Description copied from interface:ReaderReads the next field of typeSFIXED32_LISTorSFIXED32_LIST_PACKEDand advances the reader to the next field.- Parameters:
target- the list that will receive the read values.- Throws:
IOException
-
readSFixed64List
Description copied from interface:ReaderReads the next field of typeSFIXED64_LISTorSFIXED64_LIST_PACKEDand advances the reader to the next field.- Parameters:
target- the list that will receive the read values.- Throws:
IOException
-
readSInt32List
Description copied from interface:ReaderReads the next field of typeSINT32_LISTorSINT32_LIST_PACKEDand advances the reader to the next field.- Parameters:
target- the list that will receive the read values.- Throws:
IOException
-
readSInt64List
Description copied from interface:ReaderReads the next field of typeSINT64_LISTorSINT64_LIST_PACKEDand advances the reader to the next field.- Parameters:
target- the list that will receive the read values.- Throws:
IOException
-
readMap
public <K,V> void readMap(Map<K, V> target, MapEntryLite.Metadata<K, throws IOExceptionV> metadata, ExtensionRegistryLite extensionRegistry) Description copied from interface:ReaderReads the next field of typeMAPand 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:
IOException
-
readField
private Object readField(WireFormat.FieldType fieldType, Class<?> messageType, ExtensionRegistryLite extensionRegistry) throws IOException - Throws:
IOException
-
readVarint32
Read a raw Varint from the stream. If larger than 32 bits, discard the upper bits.- Throws:
IOException
-
readVarint64
- Throws:
IOException
-
readVarint64SlowPath
- Throws:
IOException
-
readByte
- Throws:
IOException
-
readLittleEndian32
- Throws:
IOException
-
readLittleEndian64
- Throws:
IOException
-
readLittleEndian32_NoCheck
private int readLittleEndian32_NoCheck() -
readLittleEndian64_NoCheck
private long readLittleEndian64_NoCheck() -
skipVarint
- Throws:
IOException
-
skipVarintSlowPath
- Throws:
IOException
-
skipBytes
- Throws:
IOException
-
skipGroup
- Throws:
IOException
-
requireBytes
- Throws:
IOException
-
requireWireType
- Throws:
IOException
-
verifyPackedFixed64Length
- Throws:
IOException
-
verifyPackedFixed32Length
- Throws:
IOException
-
requirePosition
- Throws:
IOException
-