Class FieldSet<T extends FieldSet.FieldDescriptorLite<T>>

    • Constructor Detail

      • FieldSet

        private FieldSet()
        Construct a new FieldSet.
      • FieldSet

        private FieldSet​(boolean dummy)
        Construct an empty FieldSet. This is only used to initialize DEFAULT_INSTANCE.
      • FieldSet

        private FieldSet​(SmallSortedMap<T,​java.lang.Object> fields)
    • Method Detail

      • isEmpty

        boolean isEmpty()
        Returns true if empty, false otherwise.
      • makeImmutable

        public void makeImmutable()
        Make this FieldSet immutable from this point forward.
      • isImmutable

        public boolean isImmutable()
        Returns whether the FieldSet is immutable. This is true if it is the emptySet() or if makeImmutable() were called.
        Returns:
        whether the FieldSet is immutable.
      • equals

        public boolean equals​(java.lang.Object o)
        Overrides:
        equals in class java.lang.Object
      • hashCode

        public int hashCode()
        Overrides:
        hashCode in class java.lang.Object
      • clone

        public FieldSet<T> clone()
        Clones the FieldSet. The returned FieldSet will be mutable even if the original FieldSet was immutable.
        Overrides:
        clone in class java.lang.Object
        Returns:
        the newly cloned FieldSet
      • getAllFields

        public java.util.Map<T,​java.lang.Object> getAllFields()
        Get a simple map containing all the fields.
      • cloneFieldEntry

        private static <T extends FieldSet.FieldDescriptorLite<T>> void cloneFieldEntry​(java.util.Map<T,​java.lang.Object> map,
                                                                                        java.util.Map.Entry<T,​java.lang.Object> entry,
                                                                                        boolean copyList)
      • iterator

        public java.util.Iterator<java.util.Map.Entry<T,​java.lang.Object>> iterator()
        Get an iterator to the field map. This iterator should not be leaked out of the protobuf library as it is not protected from mutation when fields is not immutable.
      • descendingIterator

        java.util.Iterator<java.util.Map.Entry<T,​java.lang.Object>> descendingIterator()
        Get an iterator over the fields in the map in descending (i.e. reverse) order. This iterator should not be leaked out of the protobuf library as it is not protected from mutation when fields is not immutable.
      • verifyType

        private void verifyType​(WireFormat.FieldType type,
                                java.lang.Object value)
        Verifies that the given object is of the correct type to be a valid value for the given field. (For repeated fields, this checks if the object is the right type to be one element of the field.)
        Throws:
        java.lang.IllegalArgumentException - The value is not of the right type.
      • isValidType

        private static boolean isValidType​(WireFormat.FieldType type,
                                           java.lang.Object value)
      • isInitialized

        public boolean isInitialized()
        See MessageLiteOrBuilder.isInitialized(). Note: Since FieldSet itself does not have any way of knowing about required fields that aren't actually present in the set, it is up to the caller to check that all required fields are present.
      • isInitialized

        private static <T extends FieldSet.FieldDescriptorLite<T>> boolean isInitialized​(java.util.Map.Entry<T,​java.lang.Object> entry)
      • getWireFormatForFieldType

        static int getWireFormatForFieldType​(WireFormat.FieldType type,
                                             boolean isPacked)
        Given a field type, return the wire type.
        Returns:
        One of the WIRETYPE_ constants defined in WireFormat.
      • cloneIfMutable

        private static java.lang.Object cloneIfMutable​(java.lang.Object value)
      • mergeFromField

        private void mergeFromField​(java.util.Map.Entry<T,​java.lang.Object> entry)
      • readPrimitiveField

        public static java.lang.Object readPrimitiveField​(CodedInputStream input,
                                                          WireFormat.FieldType type,
                                                          boolean checkUtf8)
                                                   throws java.io.IOException
        Read a field of any primitive type for immutable messages from a CodedInputStream. Enums, groups, and embedded messages are not handled by this method.
        Parameters:
        input - The stream from which to read.
        type - Declared type of the field.
        checkUtf8 - When true, check that the input is valid utf8.
        Returns:
        An object representing the field's value, of the exact type which would be returned by MessageOrBuilder.getField(Descriptors.FieldDescriptor) for this field.
        Throws:
        java.io.IOException
      • writeMessageSetTo

        private void writeMessageSetTo​(java.util.Map.Entry<T,​java.lang.Object> entry,
                                       CodedOutputStream output)
                                throws java.io.IOException
        Throws:
        java.io.IOException
      • writeElement

        static void writeElement​(CodedOutputStream output,
                                 WireFormat.FieldType type,
                                 int number,
                                 java.lang.Object value)
                          throws java.io.IOException
        Write a single tag-value pair to the stream.
        Parameters:
        output - The output stream.
        type - The field's type.
        number - The field's number.
        value - Object representing the field's value. Must be of the exact type which would be returned by MessageOrBuilder.getField(Descriptors.FieldDescriptor) for this field.
        Throws:
        java.io.IOException
      • writeElementNoTag

        static void writeElementNoTag​(CodedOutputStream output,
                                      WireFormat.FieldType type,
                                      java.lang.Object value)
                               throws java.io.IOException
        Write a field of arbitrary type, without its tag, to the stream.
        Parameters:
        output - The output stream.
        type - The field's type.
        value - Object representing the field's value. Must be of the exact type which would be returned by MessageOrBuilder.getField(Descriptors.FieldDescriptor) for this field.
        Throws:
        java.io.IOException
      • getMessageSetSerializedSize

        public int getMessageSetSerializedSize()
        Like getSerializedSize() but uses MessageSet wire format.
      • getMessageSetSerializedSize

        private int getMessageSetSerializedSize​(java.util.Map.Entry<T,​java.lang.Object> entry)
      • computeElementSize

        static int computeElementSize​(WireFormat.FieldType type,
                                      int number,
                                      java.lang.Object value)
        Compute the number of bytes that would be needed to encode a single tag/value pair of arbitrary type.
        Parameters:
        type - The field's type.
        number - The field's number.
        value - Object representing the field's value. Must be of the exact type which would be returned by MessageOrBuilder.getField(Descriptors.FieldDescriptor) for this field.
      • computeElementSizeNoTag

        static int computeElementSizeNoTag​(WireFormat.FieldType type,
                                           java.lang.Object value)
        Compute the number of bytes that would be needed to encode a particular value of arbitrary type, excluding tag.
        Parameters:
        type - The field's type.
        value - Object representing the field's value. Must be of the exact type which would be returned by MessageOrBuilder.getField(Descriptors.FieldDescriptor) for this field.
      • computeFieldSize

        public static int computeFieldSize​(FieldSet.FieldDescriptorLite<?> descriptor,
                                           java.lang.Object value)
        Compute the number of bytes needed to encode a particular field.