Interface UnknownFieldSet

  • All Superinterfaces:
    Serializable
    All Known Implementing Classes:
    UnknownFieldSetImpl

    public interface UnknownFieldSet
    extends Serializable
    UnknownFieldSet keeps track of fields seen during parsing of a protocol message but whose field numbers are not recognized by the user provided marshallers (are never requested by them). This usually occurs when new fields are added to a message type and then messages containing those fields are read by old versions of software that was built before the new fields were added.

    This is also used to handle the case when fields are requested in a different order than they were written to the stream (lowers performance but still works). In this case all fields that are encountered while parsing the stream up to the point where the requested field is finally encountered are cached/buffered in this data structure.

    Instances of UnknownFieldSet are never to be created by the user. They will be created by the library and handed over to the message marshaller via the UnknownFieldSetHandler mechanism. Instances are serializable according to Java serialization.

    Since:
    1.0
    Author:
    [email protected]
    • Method Summary

      All Methods Instance Methods Abstract Methods 
      Modifier and Type Method Description
      <A> A consumeTag​(int tag)
      Reads and removes a field value from the set.
      boolean hasTag​(int tag)
      Checks if a tag is present.
      boolean isEmpty()
      Checks if there are any fields in this set.
      void putVarintField​(int tag, int value)
      Convenience method for merging a new field containing a single varint value.
      void readAllFields​(TagReader input)
      Parse an entire message from input and merge its fields into this set.
      boolean readSingleField​(int tag, TagReader input)
      Parse a single field from input and merge it into this set.
      void writeTo​(TagWriter output)
      Writes all fields from this set to the output stream.
    • Method Detail

      • isEmpty

        boolean isEmpty()
        Checks if there are any fields in this set.
      • readAllFields

        void readAllFields​(TagReader input)
                    throws IOException
        Parse an entire message from input and merge its fields into this set.
        Throws:
        IOException
      • readSingleField

        boolean readSingleField​(int tag,
                                TagReader input)
                         throws IOException
        Parse a single field from input and merge it into this set.
        Parameters:
        tag - The field's tag number, which was already parsed (tag contains both field id and wire type).
        Returns:
        false if the tag is an end group tag.
        Throws:
        IOException
      • putVarintField

        void putVarintField​(int tag,
                            int value)
        Convenience method for merging a new field containing a single varint value. This is used in particular when an unknown enum value is encountered.
        Parameters:
        tag - the field tag (containing both field id and wire type).
      • consumeTag

        <A> A consumeTag​(int tag)
        Reads and removes a field value from the set. The field is specified as a tag value composed of the numeric id of the field and the wire type. It's possible that the tag has repeated values; in that case the first one is returned.
        Type Parameters:
        A - The expected type of the tag value.
        Parameters:
        tag - the field tag (containing both field id and wire type).
        Returns:
        the first seen value or null if the tag was not found.
      • hasTag

        boolean hasTag​(int tag)
        Checks if a tag is present.
        Parameters:
        tag - the field tag (containing both field id and wire type).
        Returns:
        true if present, false otherwise