Package io.protostuff

Class MapSchema<K,​V>

  • All Implemented Interfaces:
    Schema<java.util.Map<K,​V>>
    Direct Known Subclasses:
    MessageMapSchema, StringMapSchema

    public abstract class MapSchema<K,​V>
    extends java.lang.Object
    implements Schema<java.util.Map<K,​V>>
    A schema for a Map. The key and value can be null (depending on the particular map impl).

    The default Map message created will be an instance of HashMap.

    • Field Detail

      • MESSAGE_FACTORIES_NAMES

        static final java.util.Set<java.lang.String> MESSAGE_FACTORIES_NAMES
        This is used by MapSchema.MessageFactories.accept(String) method. Rather than iterating enums in runtime which can be an expensive way to do, caching all the enums as static property will be a good way.
      • FIELD_NAME_ENTRY

        public static final java.lang.String FIELD_NAME_ENTRY
        The field name of the Map.Entry.
        See Also:
        Constant Field Values
      • FIELD_NAME_KEY

        public static final java.lang.String FIELD_NAME_KEY
        The field name of the key.
        See Also:
        Constant Field Values
      • FIELD_NAME_VALUE

        public static final java.lang.String FIELD_NAME_VALUE
        The field name of the value;
        See Also:
        Constant Field Values
      • pipeSchema

        public final Pipe.Schema<java.util.Map<K,​V>> pipeSchema
        The pipe schema of the Map.
      • entrySchema

        private final Schema<java.util.Map.Entry<K,​V>> entrySchema
      • entryPipeSchema

        private final Pipe.Schema<java.util.Map.Entry<K,​V>> entryPipeSchema
    • Method Detail

      • readKeyFrom

        protected abstract K readKeyFrom​(Input input,
                                         MapSchema.MapWrapper<K,​V> wrapper)
                                  throws java.io.IOException
        Reads the key from the input.

        The extra wrapper arg is internally used as an object placeholder during polymorhic deserialization.

        Throws:
        java.io.IOException
      • putValueFrom

        protected abstract void putValueFrom​(Input input,
                                             MapSchema.MapWrapper<K,​V> wrapper,
                                             K key)
                                      throws java.io.IOException
        Puts the entry(key and value), obtained from the input, into the MapWrapper.
        Throws:
        java.io.IOException
      • writeKeyTo

        protected abstract void writeKeyTo​(Output output,
                                           int fieldNumber,
                                           K value,
                                           boolean repeated)
                                    throws java.io.IOException
        Writes the key to the output.
        Throws:
        java.io.IOException
      • writeValueTo

        protected abstract void writeValueTo​(Output output,
                                             int fieldNumber,
                                             V value,
                                             boolean repeated)
                                      throws java.io.IOException
        Writes the value to the output.
        Throws:
        java.io.IOException
      • transferKey

        protected abstract void transferKey​(Pipe pipe,
                                            Input input,
                                            Output output,
                                            int number,
                                            boolean repeated)
                                     throws java.io.IOException
        Transfers the key from the input to the output.
        Throws:
        java.io.IOException
      • transferValue

        protected abstract void transferValue​(Pipe pipe,
                                              Input input,
                                              Output output,
                                              int number,
                                              boolean repeated)
                                       throws java.io.IOException
        Transfers the value from the input to the output.
        Throws:
        java.io.IOException
      • getFieldName

        public final java.lang.String getFieldName​(int number)
        Description copied from interface: Schema
        Gets the field name associated with the number. This is particularly useful when serializing to different formats (Eg. JSON). When using numeric field names:
         return String.valueOf(number);
         
        Specified by:
        getFieldName in interface Schema<K>
      • getFieldNumber

        public final int getFieldNumber​(java.lang.String name)
        Description copied from interface: Schema
        Gets the field number associated with the name. This is particularly useful when serializing to different formats (Eg. JSON). When using numeric field names:
         return Integer.parseInt(name);
         
        Specified by:
        getFieldNumber in interface Schema<K>
      • isInitialized

        public final boolean isInitialized​(java.util.Map<K,​V> map)
        Description copied from interface: Schema
        Returns true if there is no required field or if all the required fields are set.
        Specified by:
        isInitialized in interface Schema<K>
      • messageFullName

        public final java.lang.String messageFullName()
        Description copied from interface: Schema
        Returns the full name of the message tied to this schema. Allows custom schemas to provide a custom name other than typeClass().getName();
        Specified by:
        messageFullName in interface Schema<K>
      • messageName

        public final java.lang.String messageName()
        Description copied from interface: Schema
        Returns the simple name of the message tied to this schema. Allows custom schemas to provide a custom name other than typeClass().getSimpleName();
        Specified by:
        messageName in interface Schema<K>
      • typeClass

        public final java.lang.Class<? super java.util.Map<K,​V>> typeClass()
        Description copied from interface: Schema
        Gets the class of the message.
        Specified by:
        typeClass in interface Schema<K>
      • newMessage

        public final java.util.Map<K,​V> newMessage()
        Description copied from interface: Schema
        Creates the message/object tied to this schema.
        Specified by:
        newMessage in interface Schema<K>
      • mergeFrom

        public final void mergeFrom​(Input input,
                                    java.util.Map<K,​V> map)
                             throws java.io.IOException
        Description copied from interface: Schema
        Deserializes a message/object from the input.
        Specified by:
        mergeFrom in interface Schema<K>
        Throws:
        java.io.IOException
      • writeTo

        public final void writeTo​(Output output,
                                  java.util.Map<K,​V> map)
                           throws java.io.IOException
        Description copied from interface: Schema
        Serializes a message/object to the output.
        Specified by:
        writeTo in interface Schema<K>
        Throws:
        java.io.IOException