Package io.protostuff

Class MapSchema<K,V>

java.lang.Object
io.protostuff.MapSchema<K,V>
All Implemented Interfaces:
Schema<Map<K,V>>
Direct Known Subclasses:
MessageMapSchema, StringMapSchema

public abstract class MapSchema<K,V> extends Object implements Schema<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 Details

  • Constructor Details

  • Method Details

    • readKeyFrom

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

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

      Throws:
      IOException
    • putValueFrom

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

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

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

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

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

      public final 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(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(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 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 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 Class<? super 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 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, Map<K,V> map) throws IOException
      Description copied from interface: Schema
      Deserializes a message/object from the input.
      Specified by:
      mergeFrom in interface Schema<K>
      Throws:
      IOException
    • writeTo

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