Package io.protostuff
Class MapSchema<K,V>
- java.lang.Object
-
- io.protostuff.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 aMap. The key and value can be null (depending on the particular map impl).The default
Mapmessage created will be an instance ofHashMap.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classMapSchema.MapWrapper<K,V>AMap.Entryw/c wraps aMap.static classMapSchema.MessageFactoriesA message factory for standardMapimplementations.static interfaceMapSchema.MessageFactoryCreates newMapmessages.
-
Field Summary
Fields Modifier and Type Field Description private Pipe.Schema<java.util.Map.Entry<K,V>>entryPipeSchemaprivate Schema<java.util.Map.Entry<K,V>>entrySchemastatic java.lang.StringFIELD_NAME_ENTRYThe field name of the Map.Entry.static java.lang.StringFIELD_NAME_KEYThe field name of the key.static java.lang.StringFIELD_NAME_VALUEThe field name of the value;(package private) static java.util.Set<java.lang.String>MESSAGE_FACTORIES_NAMESThis is used byMapSchema.MessageFactories.accept(String)method.MapSchema.MessageFactorymessageFactoryFactory for creatingMapmessages.Pipe.Schema<java.util.Map<K,V>>pipeSchemaThe pipe schema of theMap.
-
Constructor Summary
Constructors Constructor Description MapSchema()MapSchema(MapSchema.MessageFactory messageFactory)
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description java.lang.StringgetFieldName(int number)Gets the field name associated with the number.intgetFieldNumber(java.lang.String name)Gets the field number associated with the name.booleanisInitialized(java.util.Map<K,V> map)Returns true if there is no required field or if all the required fields are set.voidmergeFrom(Input input, java.util.Map<K,V> map)Deserializes a message/object from theinput.java.lang.StringmessageFullName()Returns the full name of the message tied to this schema.java.lang.StringmessageName()Returns the simple name of the message tied to this schema.java.util.Map<K,V>newMessage()Creates the message/object tied to this schema.protected abstract voidputValueFrom(Input input, MapSchema.MapWrapper<K,V> wrapper, K key)Puts the entry(key and value), obtained from the input, into theMapWrapper.protected abstract KreadKeyFrom(Input input, MapSchema.MapWrapper<K,V> wrapper)Reads the key from the input.protected abstract voidtransferKey(Pipe pipe, Input input, Output output, int number, boolean repeated)Transfers the key from the input to the output.protected abstract voidtransferValue(Pipe pipe, Input input, Output output, int number, boolean repeated)Transfers the value from the input to the output.java.lang.Class<? super java.util.Map<K,V>>typeClass()Gets the class of the message.protected abstract voidwriteKeyTo(Output output, int fieldNumber, K value, boolean repeated)Writes the key to the output.voidwriteTo(Output output, java.util.Map<K,V> map)Serializes a message/object to theoutput.protected abstract voidwriteValueTo(Output output, int fieldNumber, V value, boolean repeated)Writes the value to the output.
-
-
-
Field Detail
-
MESSAGE_FACTORIES_NAMES
static final java.util.Set<java.lang.String> MESSAGE_FACTORIES_NAMES
This is used byMapSchema.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
-
messageFactory
public final MapSchema.MessageFactory messageFactory
Factory for creatingMapmessages.
-
pipeSchema
public final Pipe.Schema<java.util.Map<K,V>> pipeSchema
The pipe schema of theMap.
-
entryPipeSchema
private final Pipe.Schema<java.util.Map.Entry<K,V>> entryPipeSchema
-
-
Constructor Detail
-
MapSchema
public MapSchema()
-
MapSchema
public MapSchema(MapSchema.MessageFactory messageFactory)
-
-
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 theMapWrapper.- 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:SchemaGets 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:
getFieldNamein interfaceSchema<K>
-
getFieldNumber
public final int getFieldNumber(java.lang.String name)
Description copied from interface:SchemaGets 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:
getFieldNumberin interfaceSchema<K>
-
isInitialized
public final boolean isInitialized(java.util.Map<K,V> map)
Description copied from interface:SchemaReturns true if there is no required field or if all the required fields are set.- Specified by:
isInitializedin interfaceSchema<K>
-
messageFullName
public final java.lang.String messageFullName()
Description copied from interface:SchemaReturns the full name of the message tied to this schema. Allows custom schemas to provide a custom name other than typeClass().getName();- Specified by:
messageFullNamein interfaceSchema<K>
-
messageName
public final java.lang.String messageName()
Description copied from interface:SchemaReturns the simple name of the message tied to this schema. Allows custom schemas to provide a custom name other than typeClass().getSimpleName();- Specified by:
messageNamein interfaceSchema<K>
-
typeClass
public final java.lang.Class<? super java.util.Map<K,V>> typeClass()
Description copied from interface:SchemaGets the class of the message.
-
newMessage
public final java.util.Map<K,V> newMessage()
Description copied from interface:SchemaCreates the message/object tied to this schema.- Specified by:
newMessagein interfaceSchema<K>
-
mergeFrom
public final void mergeFrom(Input input, java.util.Map<K,V> map) throws java.io.IOException
Description copied from interface:SchemaDeserializes a message/object from theinput.
-
-