Class CodedInputStreamReader

java.lang.Object
com.google.protobuf.CodedInputStreamReader
All Implemented Interfaces:
Reader

@CheckReturnValue @ExperimentalApi final class CodedInputStreamReader extends Object implements Reader
An adapter between the Reader interface and CodedInputStream.
  • Field Details

    • FIXED32_MULTIPLE_MASK

      private static final int FIXED32_MULTIPLE_MASK
      See Also:
    • FIXED64_MULTIPLE_MASK

      private static final int FIXED64_MULTIPLE_MASK
      See Also:
    • NEXT_TAG_UNSET

      private static final int NEXT_TAG_UNSET
      See Also:
    • input

      private final CodedInputStream input
    • tag

      private int tag
    • endGroupTag

      private int endGroupTag
    • nextTag

      private int nextTag
  • Constructor Details

    • CodedInputStreamReader

      private CodedInputStreamReader(CodedInputStream input)
  • Method Details

    • forCodedInput

      public static CodedInputStreamReader forCodedInput(CodedInputStream input)
    • shouldDiscardUnknownFields

      public boolean shouldDiscardUnknownFields()
      Specified by:
      shouldDiscardUnknownFields in interface Reader
    • getFieldNumber

      public int getFieldNumber() throws IOException
      Description copied from interface: Reader
      Gets 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.

      Specified by:
      getFieldNumber in interface Reader
      Returns:
      the current field number or Reader.READ_DONE if the end of input has been reached.
      Throws:
      IOException
    • getTag

      public int getTag()
      Description copied from interface: Reader
      Gets the wire tag of the current field.
      Specified by:
      getTag in interface Reader
      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 IOException
      Description copied from interface: Reader
      Skips the current field and advances the reader to the next field.
      Specified by:
      skipField in interface Reader
      Returns:
      true if there are more fields or false if the end of input has been reached.
      Throws:
      IOException
    • requireWireType

      private void requireWireType(int requiredWireType) throws IOException
      Throws:
      IOException
    • readDouble

      public double readDouble() throws IOException
      Description copied from interface: Reader
      Reads and returns the next field of type DOUBLE and advances the reader to the next field.
      Specified by:
      readDouble in interface Reader
      Throws:
      IOException
    • readFloat

      public float readFloat() throws IOException
      Description copied from interface: Reader
      Reads and returns the next field of type FLOAT and advances the reader to the next field.
      Specified by:
      readFloat in interface Reader
      Throws:
      IOException
    • readUInt64

      public long readUInt64() throws IOException
      Description copied from interface: Reader
      Reads and returns the next field of type UINT64 and advances the reader to the next field.
      Specified by:
      readUInt64 in interface Reader
      Throws:
      IOException
    • readInt64

      public long readInt64() throws IOException
      Description copied from interface: Reader
      Reads and returns the next field of type INT64 and advances the reader to the next field.
      Specified by:
      readInt64 in interface Reader
      Throws:
      IOException
    • readInt32

      public int readInt32() throws IOException
      Description copied from interface: Reader
      Reads and returns the next field of type INT32 and advances the reader to the next field.
      Specified by:
      readInt32 in interface Reader
      Throws:
      IOException
    • readFixed64

      public long readFixed64() throws IOException
      Description copied from interface: Reader
      Reads and returns the next field of type FIXED64 and advances the reader to the next field.
      Specified by:
      readFixed64 in interface Reader
      Throws:
      IOException
    • readFixed32

      public int readFixed32() throws IOException
      Description copied from interface: Reader
      Reads and returns the next field of type FIXED32 and advances the reader to the next field.
      Specified by:
      readFixed32 in interface Reader
      Throws:
      IOException
    • readBool

      public boolean readBool() throws IOException
      Description copied from interface: Reader
      Reads and returns the next field of type BOOL and advances the reader to the next field.
      Specified by:
      readBool in interface Reader
      Throws:
      IOException
    • readString

      public String readString() throws IOException
      Description copied from interface: Reader
      Reads and returns the next field of type STRING 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.
      Specified by:
      readString in interface Reader
      Throws:
      IOException
    • readStringRequireUtf8

      public String readStringRequireUtf8() throws IOException
      Description copied from interface: Reader
      Reads and returns the next field of type STRING and advances the reader to the next field. If the stream contains malformed UTF-8, throw exception InvalidProtocolBufferException.
      Specified by:
      readStringRequireUtf8 in interface Reader
      Throws:
      IOException
    • readMessage

      public <T> T readMessage(Class<T> clazz, ExtensionRegistryLite extensionRegistry) throws IOException
      Description copied from interface: Reader
      Reads and returns the next field of type MESSAGE and advances the reader to the next field.
      Specified by:
      readMessage in interface Reader
      Throws:
      IOException
    • readMessageBySchemaWithCheck

      public <T> T readMessageBySchemaWithCheck(Schema<T> schema, ExtensionRegistryLite extensionRegistry) throws IOException
      Specified by:
      readMessageBySchemaWithCheck in interface Reader
      Throws:
      IOException
    • readGroup

      @Deprecated public <T> T readGroup(Class<T> clazz, ExtensionRegistryLite extensionRegistry) throws IOException
      Deprecated.
      Description copied from interface: Reader
      Reads and returns the next field of type GROUP and advances the reader to the next field.
      Specified by:
      readGroup in interface Reader
      Throws:
      IOException
    • readGroupBySchemaWithCheck

      @Deprecated public <T> T readGroupBySchemaWithCheck(Schema<T> schema, ExtensionRegistryLite extensionRegistry) throws IOException
      Deprecated.
      Specified by:
      readGroupBySchemaWithCheck in interface Reader
      Throws:
      IOException
    • mergeMessageField

      public <T> void mergeMessageField(T target, Schema<T> schema, ExtensionRegistryLite extensionRegistry) throws IOException
      Description copied from interface: Reader
      Read a message field from the wire format and merge the results into the given target.
      Specified by:
      mergeMessageField in interface Reader
      Throws:
      IOException
    • mergeMessageFieldInternal

      private <T> void mergeMessageFieldInternal(T target, Schema<T> schema, ExtensionRegistryLite extensionRegistry) throws IOException
      Throws:
      IOException
    • readMessage

      private <T> T readMessage(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: Reader
      Read a group field from the wire format and merge the results into the given target.
      Specified by:
      mergeGroupField in interface Reader
      Throws:
      IOException
    • mergeGroupFieldInternal

      private <T> void mergeGroupFieldInternal(T target, Schema<T> schema, ExtensionRegistryLite extensionRegistry) throws IOException
      Throws:
      IOException
    • readGroup

      private <T> T readGroup(Schema<T> schema, ExtensionRegistryLite extensionRegistry) throws IOException
      Throws:
      IOException
    • readBytes

      public ByteString readBytes() throws IOException
      Description copied from interface: Reader
      Reads and returns the next field of type BYTES and advances the reader to the next field.
      Specified by:
      readBytes in interface Reader
      Throws:
      IOException
    • readUInt32

      public int readUInt32() throws IOException
      Description copied from interface: Reader
      Reads and returns the next field of type UINT32 and advances the reader to the next field.
      Specified by:
      readUInt32 in interface Reader
      Throws:
      IOException
    • readEnum

      public int readEnum() throws IOException
      Description copied from interface: Reader
      Reads and returns the next field of type ENUM and advances the reader to the next field.
      Specified by:
      readEnum in interface Reader
      Throws:
      IOException
    • readSFixed32

      public int readSFixed32() throws IOException
      Description copied from interface: Reader
      Reads and returns the next field of type SFIXED32 and advances the reader to the next field.
      Specified by:
      readSFixed32 in interface Reader
      Throws:
      IOException
    • readSFixed64

      public long readSFixed64() throws IOException
      Description copied from interface: Reader
      Reads and returns the next field of type SFIXED64 and advances the reader to the next field.
      Specified by:
      readSFixed64 in interface Reader
      Throws:
      IOException
    • readSInt32

      public int readSInt32() throws IOException
      Description copied from interface: Reader
      Reads and returns the next field of type SINT32 and advances the reader to the next field.
      Specified by:
      readSInt32 in interface Reader
      Throws:
      IOException
    • readSInt64

      public long readSInt64() throws IOException
      Description copied from interface: Reader
      Reads and returns the next field of type SINT64 and advances the reader to the next field.
      Specified by:
      readSInt64 in interface Reader
      Throws:
      IOException
    • readDoubleList

      public void readDoubleList(List<Double> target) throws IOException
      Description copied from interface: Reader
      Reads the next field of type DOUBLE_LIST or DOUBLE_LIST_PACKED and advances the reader to the next field.
      Specified by:
      readDoubleList in interface Reader
      Parameters:
      target - the list that will receive the read values.
      Throws:
      IOException
    • readFloatList

      public void readFloatList(List<Float> target) throws IOException
      Description copied from interface: Reader
      Reads the next field of type FLOAT_LIST or FLOAT_LIST_PACKED and advances the reader to the next field.
      Specified by:
      readFloatList in interface Reader
      Parameters:
      target - the list that will receive the read values.
      Throws:
      IOException
    • readUInt64List

      public void readUInt64List(List<Long> target) throws IOException
      Description copied from interface: Reader
      Reads the next field of type UINT64_LIST or UINT64_LIST_PACKED and advances the reader to the next field.
      Specified by:
      readUInt64List in interface Reader
      Parameters:
      target - the list that will receive the read values.
      Throws:
      IOException
    • readInt64List

      public void readInt64List(List<Long> target) throws IOException
      Description copied from interface: Reader
      Reads the next field of type INT64_LIST or INT64_LIST_PACKED and advances the reader to the next field.
      Specified by:
      readInt64List in interface Reader
      Parameters:
      target - the list that will receive the read values.
      Throws:
      IOException
    • readInt32List

      public void readInt32List(List<Integer> target) throws IOException
      Description copied from interface: Reader
      Reads the next field of type INT32_LIST or INT32_LIST_PACKED and advances the reader to the next field.
      Specified by:
      readInt32List in interface Reader
      Parameters:
      target - the list that will receive the read values.
      Throws:
      IOException
    • readFixed64List

      public void readFixed64List(List<Long> target) throws IOException
      Description copied from interface: Reader
      Reads the next field of type FIXED64_LIST or FIXED64_LIST_PACKED and advances the reader to the next field.
      Specified by:
      readFixed64List in interface Reader
      Parameters:
      target - the list that will receive the read values.
      Throws:
      IOException
    • readFixed32List

      public void readFixed32List(List<Integer> target) throws IOException
      Description copied from interface: Reader
      Reads the next field of type FIXED32_LIST or FIXED32_LIST_PACKED and advances the reader to the next field.
      Specified by:
      readFixed32List in interface Reader
      Parameters:
      target - the list that will receive the read values.
      Throws:
      IOException
    • readBoolList

      public void readBoolList(List<Boolean> target) throws IOException
      Description copied from interface: Reader
      Reads the next field of type BOOL_LIST or BOOL_LIST_PACKED and advances the reader to the next field.
      Specified by:
      readBoolList in interface Reader
      Parameters:
      target - the list that will receive the read values.
      Throws:
      IOException
    • readStringList

      public void readStringList(List<String> target) throws IOException
      Description copied from interface: Reader
      Reads the next field of type STRING_LIST and advances the reader to the next field.
      Specified by:
      readStringList in interface Reader
      Parameters:
      target - the list that will receive the read values.
      Throws:
      IOException
    • readStringListRequireUtf8

      public void readStringListRequireUtf8(List<String> target) throws IOException
      Description copied from interface: Reader
      Reads the next field of type STRING_LIST and advances the reader to the next field. If the stream contains malformed UTF-8, throw exception InvalidProtocolBufferException.
      Specified by:
      readStringListRequireUtf8 in interface Reader
      Parameters:
      target - the list that will receive the read values.
      Throws:
      IOException
    • readStringListInternal

      public void readStringListInternal(List<String> target, boolean requireUtf8) throws IOException
      Throws:
      IOException
    • readMessageList

      public <T> void readMessageList(List<T> target, Class<T> targetType, ExtensionRegistryLite extensionRegistry) throws IOException
      Specified by:
      readMessageList in interface Reader
      Throws:
      IOException
    • readMessageList

      public <T> void readMessageList(List<T> target, Schema<T> schema, ExtensionRegistryLite extensionRegistry) throws IOException
      Description copied from interface: Reader
      Reads the next field of type MESSAGE_LIST and advances the reader to the next field.
      Specified by:
      readMessageList in interface Reader
      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: Reader
      Reads the next field of type GROUP_LIST and advances the reader to the next field.
      Specified by:
      readGroupList in interface Reader
      Parameters:
      target - the list that will receive the read values.
      targetType - the type of the elements stored in the target list.
      Throws:
      IOException
    • readGroupList

      @Deprecated public <T> void readGroupList(List<T> target, Schema<T> schema, ExtensionRegistryLite extensionRegistry) throws IOException
      Deprecated.
      Specified by:
      readGroupList in interface Reader
      Throws:
      IOException
    • readBytesList

      public void readBytesList(List<ByteString> target) throws IOException
      Description copied from interface: Reader
      Reads the next field of type BYTES_LIST and advances the reader to the next field.
      Specified by:
      readBytesList in interface Reader
      Parameters:
      target - the list that will receive the read values.
      Throws:
      IOException
    • readUInt32List

      public void readUInt32List(List<Integer> target) throws IOException
      Description copied from interface: Reader
      Reads the next field of type UINT32_LIST or UINT32_LIST_PACKED and advances the reader to the next field.
      Specified by:
      readUInt32List in interface Reader
      Parameters:
      target - the list that will receive the read values.
      Throws:
      IOException
    • readEnumList

      public void readEnumList(List<Integer> target) throws IOException
      Description copied from interface: Reader
      Reads the next field of type ENUM_LIST or ENUM_LIST_PACKED and advances the reader to the next field.
      Specified by:
      readEnumList in interface Reader
      Parameters:
      target - the list that will receive the read values.
      Throws:
      IOException
    • readSFixed32List

      public void readSFixed32List(List<Integer> target) throws IOException
      Description copied from interface: Reader
      Reads the next field of type SFIXED32_LIST or SFIXED32_LIST_PACKED and advances the reader to the next field.
      Specified by:
      readSFixed32List in interface Reader
      Parameters:
      target - the list that will receive the read values.
      Throws:
      IOException
    • readSFixed64List

      public void readSFixed64List(List<Long> target) throws IOException
      Description copied from interface: Reader
      Reads the next field of type SFIXED64_LIST or SFIXED64_LIST_PACKED and advances the reader to the next field.
      Specified by:
      readSFixed64List in interface Reader
      Parameters:
      target - the list that will receive the read values.
      Throws:
      IOException
    • readSInt32List

      public void readSInt32List(List<Integer> target) throws IOException
      Description copied from interface: Reader
      Reads the next field of type SINT32_LIST or SINT32_LIST_PACKED and advances the reader to the next field.
      Specified by:
      readSInt32List in interface Reader
      Parameters:
      target - the list that will receive the read values.
      Throws:
      IOException
    • readSInt64List

      public void readSInt64List(List<Long> target) throws IOException
      Description copied from interface: Reader
      Reads the next field of type SINT64_LIST or SINT64_LIST_PACKED and advances the reader to the next field.
      Specified by:
      readSInt64List in interface Reader
      Parameters:
      target - the list that will receive the read values.
      Throws:
      IOException
    • verifyPackedFixed64Length

      private void verifyPackedFixed64Length(int bytes) throws IOException
      Throws:
      IOException
    • readMap

      public <K, V> void readMap(Map<K,V> target, MapEntryLite.Metadata<K,V> metadata, ExtensionRegistryLite extensionRegistry) throws IOException
      Description copied from interface: Reader
      Reads the next field of type MAP and advances the reader to the next field.
      Specified by:
      readMap in interface Reader
      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
    • verifyPackedFixed32Length

      private void verifyPackedFixed32Length(int bytes) throws IOException
      Throws:
      IOException
    • requirePosition

      private void requirePosition(int expectedPosition) throws IOException
      Throws:
      IOException