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
Map
message created will be an instance ofHashMap
.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
MapSchema.MapWrapper<K,V>
AMap.Entry
w/c wraps aMap
.static class
MapSchema.MessageFactories
A message factory for standardMap
implementations.static interface
MapSchema.MessageFactory
Creates newMap
messages.
-
Field Summary
Fields Modifier and Type Field Description private Pipe.Schema<java.util.Map.Entry<K,V>>
entryPipeSchema
private Schema<java.util.Map.Entry<K,V>>
entrySchema
static java.lang.String
FIELD_NAME_ENTRY
The field name of the Map.Entry.static java.lang.String
FIELD_NAME_KEY
The field name of the key.static java.lang.String
FIELD_NAME_VALUE
The field name of the value;(package private) static java.util.Set<java.lang.String>
MESSAGE_FACTORIES_NAMES
This is used byMapSchema.MessageFactories.accept(String)
method.MapSchema.MessageFactory
messageFactory
Factory for creatingMap
messages.Pipe.Schema<java.util.Map<K,V>>
pipeSchema
The 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.String
getFieldName(int number)
Gets the field name associated with the number.int
getFieldNumber(java.lang.String name)
Gets the field number associated with the name.boolean
isInitialized(java.util.Map<K,V> map)
Returns true if there is no required field or if all the required fields are set.void
mergeFrom(Input input, java.util.Map<K,V> map)
Deserializes a message/object from theinput
.java.lang.String
messageFullName()
Returns the full name of the message tied to this schema.java.lang.String
messageName()
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 void
putValueFrom(Input input, MapSchema.MapWrapper<K,V> wrapper, K key)
Puts the entry(key and value), obtained from the input, into theMapWrapper
.protected abstract K
readKeyFrom(Input input, MapSchema.MapWrapper<K,V> wrapper)
Reads the key from the input.protected abstract void
transferKey(Pipe pipe, Input input, Output output, int number, boolean repeated)
Transfers the key from the input to the output.protected abstract void
transferValue(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 void
writeKeyTo(Output output, int fieldNumber, K value, boolean repeated)
Writes the key to the output.void
writeTo(Output output, java.util.Map<K,V> map)
Serializes a message/object to theoutput
.protected abstract void
writeValueTo(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 creatingMap
messages.
-
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: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 interfaceSchema<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 interfaceSchema<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 interfaceSchema<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 interfaceSchema<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 interfaceSchema<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.
-
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 interfaceSchema<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 theinput
.
-
-