Package io.protostuff.runtime
Class IdStrategy
- java.lang.Object
-
- io.protostuff.runtime.IdStrategy
-
- Direct Known Subclasses:
DefaultIdStrategy
,NumericIdStrategy
public abstract class IdStrategy extends java.lang.Object
This base class handles all the IO for reading and writing polymorphic fields. When a field's type is polymorphic/dynamic (e.g interface/abstract/object), the type (id) needs to be written (ahead) before its value/content to be able to deserialize it correctly.The underlying impl will determine how the type (id) should be written.
An
IdStrategy
is standalone if theprimaryGroup
is not set.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static interface
IdStrategy.Factory
Responsible for instantiating customIdStrategy
impls.private static class
IdStrategy.PMapWrapper
static class
IdStrategy.UnknownTypeException
Thrown when a type is not known by the IdStrategy.(package private) static class
IdStrategy.Wrapper
-
Field Summary
-
Constructor Summary
Constructors Modifier Constructor Description protected
IdStrategy(int flags, IdStrategy primaryGroup, int groupId)
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description protected static <T> T
createMessageInstance(java.lang.Class<T> clazz)
protected abstract CollectionSchema.MessageFactory
getCollectionFactory(java.lang.Class<?> clazz)
Returns theCollectionSchema.MessageFactory
.abstract <T> Delegate<T>
getDelegate(java.lang.Class<? super T> typeClass)
Returns thedelegate
.abstract <T> HasDelegate<T>
getDelegateWrapper(java.lang.Class<? super T> typeClass)
Returns thedelegate
.protected abstract EnumIO<? extends java.lang.Enum<?>>
getEnumIO(java.lang.Class<?> enumClass)
Returns theEnumIO
.protected abstract MapSchema.MessageFactory
getMapFactory(java.lang.Class<?> clazz)
Returns theMapSchema.MessageFactory
.abstract <T> HasSchema<T>
getSchemaWrapper(java.lang.Class<T> typeClass, boolean create)
Returns theschema wrapper
.abstract boolean
isDelegateRegistered(java.lang.Class<?> typeClass)
Returns true if there is aDelegate
explicitly registered for thetypeClass
.abstract boolean
isRegistered(java.lang.Class<?> typeClass)
Returns true if thetypeClass
is explicitly registered.protected <T> Schema<T>
newSchema(java.lang.Class<T> typeClass)
Generates a schema from the given class.protected abstract java.lang.Class<?>
resolveArrayComponentTypeFrom(Input input, boolean mapped)
protected abstract java.lang.Class<?>
resolveClassFrom(Input input, boolean mapped, boolean array)
protected abstract CollectionSchema.MessageFactory
resolveCollectionFrom(Input input)
protected abstract <T> HasDelegate<T>
resolveDelegateFrom(Input input)
protected abstract EnumIO<?>
resolveEnumFrom(Input input)
protected abstract MapSchema.MessageFactory
resolveMapFrom(Input input)
protected abstract <T> HasSchema<T>
resolvePojoFrom(Input input, int fieldNumber)
protected abstract void
transferArrayId(Input input, Output output, int fieldNumber, boolean mapped)
protected abstract void
transferClassId(Input input, Output output, int fieldNumber, boolean mapped, boolean array)
protected abstract void
transferCollectionId(Input input, Output output, int fieldNumber)
protected abstract <T> HasDelegate<T>
transferDelegateId(Input input, Output output, int fieldNumber)
protected abstract void
transferEnumId(Input input, Output output, int fieldNumber)
protected abstract void
transferMapId(Input input, Output output, int fieldNumber)
protected abstract <T> HasSchema<T>
transferPojoId(Input input, Output output, int fieldNumber)
protected abstract <T> HasDelegate<T>
tryWriteDelegateIdTo(Output output, int fieldNumber, java.lang.Class<T> clazz)
If this method returns null, the clazz was not registered as a delegate.protected abstract <T> HasSchema<T>
tryWritePojoIdTo(Output output, int fieldNumber, java.lang.Class<T> clazz, boolean registered)
protected abstract void
writeArrayIdTo(Output output, java.lang.Class<?> componentType)
protected abstract void
writeClassIdTo(Output output, java.lang.Class<?> componentType, boolean array)
protected abstract void
writeCollectionIdTo(Output output, int fieldNumber, java.lang.Class<?> clazz)
protected abstract void
writeEnumIdTo(Output output, int fieldNumber, java.lang.Class<?> clazz)
protected abstract void
writeMapIdTo(Output output, int fieldNumber, java.lang.Class<?> clazz)
protected abstract <T> Schema<T>
writeMessageIdTo(Output output, int fieldNumber, Message<T> message)
protected abstract <T> HasSchema<T>
writePojoIdTo(Output output, int fieldNumber, java.lang.Class<T> clazz)
-
-
-
Field Detail
-
ENUMS_BY_NAME
public static final int ENUMS_BY_NAME
- See Also:
- Constant Field Values
-
AUTO_LOAD_POLYMORPHIC_CLASSES
public static final int AUTO_LOAD_POLYMORPHIC_CLASSES
- See Also:
- Constant Field Values
-
PRESERVE_NULL_ELEMENTS
public static final int PRESERVE_NULL_ELEMENTS
- See Also:
- Constant Field Values
-
MORPH_NON_FINAL_POJOS
public static final int MORPH_NON_FINAL_POJOS
- See Also:
- Constant Field Values
-
MORPH_COLLECTION_INTERFACES
public static final int MORPH_COLLECTION_INTERFACES
- See Also:
- Constant Field Values
-
MORPH_MAP_INTERFACES
public static final int MORPH_MAP_INTERFACES
- See Also:
- Constant Field Values
-
COLLECTION_SCHEMA_ON_REPEATED_FIELDS
public static final int COLLECTION_SCHEMA_ON_REPEATED_FIELDS
- See Also:
- Constant Field Values
-
POJO_SCHEMA_ON_COLLECTION_FIELDS
public static final int POJO_SCHEMA_ON_COLLECTION_FIELDS
- See Also:
- Constant Field Values
-
POJO_SCHEMA_ON_MAP_FIELDS
public static final int POJO_SCHEMA_ON_MAP_FIELDS
- See Also:
- Constant Field Values
-
DEFAULT_FLAGS
public static final int DEFAULT_FLAGS
-
flags
public final int flags
-
primaryGroup
public final IdStrategy primaryGroup
-
groupId
public final int groupId
-
preserveNull
final boolean preserveNull
-
POLYMORPHIC_POJO_ELEMENT_SCHEMA
final DerivativeSchema POLYMORPHIC_POJO_ELEMENT_SCHEMA
-
ARRAY_ELEMENT_SCHEMA
final ArraySchema ARRAY_ELEMENT_SCHEMA
-
NUMBER_ELEMENT_SCHEMA
final NumberSchema NUMBER_ELEMENT_SCHEMA
-
CLASS_ELEMENT_SCHEMA
final ClassSchema CLASS_ELEMENT_SCHEMA
-
POLYMORPHIC_ENUM_ELEMENT_SCHEMA
final PolymorphicEnumSchema POLYMORPHIC_ENUM_ELEMENT_SCHEMA
-
POLYMORPHIC_THROWABLE_ELEMENT_SCHEMA
final PolymorphicThrowableSchema POLYMORPHIC_THROWABLE_ELEMENT_SCHEMA
-
OBJECT_ELEMENT_SCHEMA
final ObjectSchema OBJECT_ELEMENT_SCHEMA
-
DYNAMIC_VALUE_SCHEMA
final Schema<java.lang.Object> DYNAMIC_VALUE_SCHEMA
-
DYNAMIC_VALUE_PIPE_SCHEMA
final Pipe.Schema<java.lang.Object> DYNAMIC_VALUE_PIPE_SCHEMA
-
COLLECTION_SCHEMA
final Schema<java.util.Collection<java.lang.Object>> COLLECTION_SCHEMA
-
COLLECTION_PIPE_SCHEMA
final Pipe.Schema<java.util.Collection<java.lang.Object>> COLLECTION_PIPE_SCHEMA
-
ARRAY_SCHEMA
final Schema<java.lang.Object> ARRAY_SCHEMA
-
ARRAY_PIPE_SCHEMA
final Pipe.Schema<java.lang.Object> ARRAY_PIPE_SCHEMA
-
MAP_SCHEMA
final Schema<java.util.Map<java.lang.Object,java.lang.Object>> MAP_SCHEMA
-
MAP_PIPE_SCHEMA
final Pipe.Schema<java.util.Map<java.lang.Object,java.lang.Object>> MAP_PIPE_SCHEMA
-
ENTRY_SCHEMA
final Schema<java.util.Map.Entry<java.lang.Object,java.lang.Object>> ENTRY_SCHEMA
-
ENTRY_PIPE_SCHEMA
final Pipe.Schema<java.util.Map.Entry<java.lang.Object,java.lang.Object>> ENTRY_PIPE_SCHEMA
-
OBJECT_SCHEMA
final Schema<java.lang.Object> OBJECT_SCHEMA
-
OBJECT_PIPE_SCHEMA
final Pipe.Schema<java.lang.Object> OBJECT_PIPE_SCHEMA
-
CLASS_SCHEMA
final Schema<java.lang.Object> CLASS_SCHEMA
-
CLASS_PIPE_SCHEMA
final Pipe.Schema<java.lang.Object> CLASS_PIPE_SCHEMA
-
POLYMORPHIC_COLLECTION_SCHEMA
final Schema<java.lang.Object> POLYMORPHIC_COLLECTION_SCHEMA
-
POLYMORPHIC_COLLECTION_PIPE_SCHEMA
final Pipe.Schema<java.lang.Object> POLYMORPHIC_COLLECTION_PIPE_SCHEMA
-
POLYMORPHIC_MAP_SCHEMA
final Schema<java.lang.Object> POLYMORPHIC_MAP_SCHEMA
-
POLYMORPHIC_MAP_PIPE_SCHEMA
final Pipe.Schema<java.lang.Object> POLYMORPHIC_MAP_PIPE_SCHEMA
-
ARRAY_BOOL_PRIMITIVE_SCHEMA
final ArraySchemas.BoolArray ARRAY_BOOL_PRIMITIVE_SCHEMA
-
ARRAY_BOOL_BOXED_SCHEMA
final ArraySchemas.BoolArray ARRAY_BOOL_BOXED_SCHEMA
-
ARRAY_BOOL_DERIVED_SCHEMA
final ArraySchemas.BoolArray ARRAY_BOOL_DERIVED_SCHEMA
-
ARRAY_CHAR_PRIMITIVE_SCHEMA
final ArraySchemas.CharArray ARRAY_CHAR_PRIMITIVE_SCHEMA
-
ARRAY_CHAR_BOXED_SCHEMA
final ArraySchemas.CharArray ARRAY_CHAR_BOXED_SCHEMA
-
ARRAY_CHAR_DERIVED_SCHEMA
final ArraySchemas.CharArray ARRAY_CHAR_DERIVED_SCHEMA
-
ARRAY_SHORT_PRIMITIVE_SCHEMA
final ArraySchemas.ShortArray ARRAY_SHORT_PRIMITIVE_SCHEMA
-
ARRAY_SHORT_BOXED_SCHEMA
final ArraySchemas.ShortArray ARRAY_SHORT_BOXED_SCHEMA
-
ARRAY_SHORT_DERIVED_SCHEMA
final ArraySchemas.ShortArray ARRAY_SHORT_DERIVED_SCHEMA
-
ARRAY_INT32_PRIMITIVE_SCHEMA
final ArraySchemas.Int32Array ARRAY_INT32_PRIMITIVE_SCHEMA
-
ARRAY_INT32_BOXED_SCHEMA
final ArraySchemas.Int32Array ARRAY_INT32_BOXED_SCHEMA
-
ARRAY_INT32_DERIVED_SCHEMA
final ArraySchemas.Int32Array ARRAY_INT32_DERIVED_SCHEMA
-
ARRAY_INT64_PRIMITIVE_SCHEMA
final ArraySchemas.Int64Array ARRAY_INT64_PRIMITIVE_SCHEMA
-
ARRAY_INT64_BOXED_SCHEMA
final ArraySchemas.Int64Array ARRAY_INT64_BOXED_SCHEMA
-
ARRAY_INT64_DERIVED_SCHEMA
final ArraySchemas.Int64Array ARRAY_INT64_DERIVED_SCHEMA
-
ARRAY_FLOAT_PRIMITIVE_SCHEMA
final ArraySchemas.FloatArray ARRAY_FLOAT_PRIMITIVE_SCHEMA
-
ARRAY_FLOAT_BOXED_SCHEMA
final ArraySchemas.FloatArray ARRAY_FLOAT_BOXED_SCHEMA
-
ARRAY_FLOAT_DERIVED_SCHEMA
final ArraySchemas.FloatArray ARRAY_FLOAT_DERIVED_SCHEMA
-
ARRAY_DOUBLE_PRIMITIVE_SCHEMA
final ArraySchemas.DoubleArray ARRAY_DOUBLE_PRIMITIVE_SCHEMA
-
ARRAY_DOUBLE_BOXED_SCHEMA
final ArraySchemas.DoubleArray ARRAY_DOUBLE_BOXED_SCHEMA
-
ARRAY_DOUBLE_DERIVED_SCHEMA
final ArraySchemas.DoubleArray ARRAY_DOUBLE_DERIVED_SCHEMA
-
ARRAY_STRING_SCHEMA
final ArraySchemas.StringArray ARRAY_STRING_SCHEMA
-
ARRAY_BYTESTRING_SCHEMA
final ArraySchemas.ByteStringArray ARRAY_BYTESTRING_SCHEMA
-
ARRAY_BYTEARRAY_SCHEMA
final ArraySchemas.ByteArrayArray ARRAY_BYTEARRAY_SCHEMA
-
ARRAY_BIGDECIMAL_SCHEMA
final ArraySchemas.BigDecimalArray ARRAY_BIGDECIMAL_SCHEMA
-
ARRAY_BIGINTEGER_SCHEMA
final ArraySchemas.BigIntegerArray ARRAY_BIGINTEGER_SCHEMA
-
ARRAY_DATE_SCHEMA
final ArraySchemas.DateArray ARRAY_DATE_SCHEMA
-
-
Constructor Detail
-
IdStrategy
protected IdStrategy(int flags, IdStrategy primaryGroup, int groupId)
-
-
Method Detail
-
newSchema
protected <T> Schema<T> newSchema(java.lang.Class<T> typeClass)
Generates a schema from the given class. If this strategy is part of a group, the existing fields of that group's schema will be re-used.
-
isDelegateRegistered
public abstract boolean isDelegateRegistered(java.lang.Class<?> typeClass)
Returns true if there is aDelegate
explicitly registered for thetypeClass
.
-
getDelegateWrapper
public abstract <T> HasDelegate<T> getDelegateWrapper(java.lang.Class<? super T> typeClass)
Returns thedelegate
.
-
getDelegate
public abstract <T> Delegate<T> getDelegate(java.lang.Class<? super T> typeClass)
Returns thedelegate
.
-
isRegistered
public abstract boolean isRegistered(java.lang.Class<?> typeClass)
Returns true if thetypeClass
is explicitly registered.
-
getSchemaWrapper
public abstract <T> HasSchema<T> getSchemaWrapper(java.lang.Class<T> typeClass, boolean create)
Returns theschema wrapper
. The caller is responsible that the typeClass is a pojo (e.g not an enum/array/etc).
-
getEnumIO
protected abstract EnumIO<? extends java.lang.Enum<?>> getEnumIO(java.lang.Class<?> enumClass)
Returns theEnumIO
. The callers (internal field factories) are responsible that the class provided is an enum class.
-
getCollectionFactory
protected abstract CollectionSchema.MessageFactory getCollectionFactory(java.lang.Class<?> clazz)
Returns theCollectionSchema.MessageFactory
. The callers (internal field factories) are responsible that the class provided implementsCollection
.
-
getMapFactory
protected abstract MapSchema.MessageFactory getMapFactory(java.lang.Class<?> clazz)
Returns theMapSchema.MessageFactory
. The callers (internal field factories}) are responsible that the class provided implementsMap
.
-
writeCollectionIdTo
protected abstract void writeCollectionIdTo(Output output, int fieldNumber, java.lang.Class<?> clazz) throws java.io.IOException
- Throws:
java.io.IOException
-
transferCollectionId
protected abstract void transferCollectionId(Input input, Output output, int fieldNumber) throws java.io.IOException
- Throws:
java.io.IOException
-
resolveCollectionFrom
protected abstract CollectionSchema.MessageFactory resolveCollectionFrom(Input input) throws java.io.IOException
- Throws:
java.io.IOException
-
writeMapIdTo
protected abstract void writeMapIdTo(Output output, int fieldNumber, java.lang.Class<?> clazz) throws java.io.IOException
- Throws:
java.io.IOException
-
transferMapId
protected abstract void transferMapId(Input input, Output output, int fieldNumber) throws java.io.IOException
- Throws:
java.io.IOException
-
resolveMapFrom
protected abstract MapSchema.MessageFactory resolveMapFrom(Input input) throws java.io.IOException
- Throws:
java.io.IOException
-
writeEnumIdTo
protected abstract void writeEnumIdTo(Output output, int fieldNumber, java.lang.Class<?> clazz) throws java.io.IOException
- Throws:
java.io.IOException
-
transferEnumId
protected abstract void transferEnumId(Input input, Output output, int fieldNumber) throws java.io.IOException
- Throws:
java.io.IOException
-
resolveEnumFrom
protected abstract EnumIO<?> resolveEnumFrom(Input input) throws java.io.IOException
- Throws:
java.io.IOException
-
tryWritePojoIdTo
protected abstract <T> HasSchema<T> tryWritePojoIdTo(Output output, int fieldNumber, java.lang.Class<T> clazz, boolean registered) throws java.io.IOException
- Throws:
java.io.IOException
-
writePojoIdTo
protected abstract <T> HasSchema<T> writePojoIdTo(Output output, int fieldNumber, java.lang.Class<T> clazz) throws java.io.IOException
- Throws:
java.io.IOException
-
transferPojoId
protected abstract <T> HasSchema<T> transferPojoId(Input input, Output output, int fieldNumber) throws java.io.IOException
- Throws:
java.io.IOException
-
resolvePojoFrom
protected abstract <T> HasSchema<T> resolvePojoFrom(Input input, int fieldNumber) throws java.io.IOException
- Throws:
java.io.IOException
-
writeMessageIdTo
protected abstract <T> Schema<T> writeMessageIdTo(Output output, int fieldNumber, Message<T> message) throws java.io.IOException
- Throws:
java.io.IOException
-
tryWriteDelegateIdTo
protected abstract <T> HasDelegate<T> tryWriteDelegateIdTo(Output output, int fieldNumber, java.lang.Class<T> clazz) throws java.io.IOException
If this method returns null, the clazz was not registered as a delegate.- Throws:
java.io.IOException
-
transferDelegateId
protected abstract <T> HasDelegate<T> transferDelegateId(Input input, Output output, int fieldNumber) throws java.io.IOException
- Throws:
java.io.IOException
-
resolveDelegateFrom
protected abstract <T> HasDelegate<T> resolveDelegateFrom(Input input) throws java.io.IOException
- Throws:
java.io.IOException
-
writeArrayIdTo
protected abstract void writeArrayIdTo(Output output, java.lang.Class<?> componentType) throws java.io.IOException
- Throws:
java.io.IOException
-
transferArrayId
protected abstract void transferArrayId(Input input, Output output, int fieldNumber, boolean mapped) throws java.io.IOException
- Throws:
java.io.IOException
-
resolveArrayComponentTypeFrom
protected abstract java.lang.Class<?> resolveArrayComponentTypeFrom(Input input, boolean mapped) throws java.io.IOException
- Throws:
java.io.IOException
-
writeClassIdTo
protected abstract void writeClassIdTo(Output output, java.lang.Class<?> componentType, boolean array) throws java.io.IOException
- Throws:
java.io.IOException
-
transferClassId
protected abstract void transferClassId(Input input, Output output, int fieldNumber, boolean mapped, boolean array) throws java.io.IOException
- Throws:
java.io.IOException
-
resolveClassFrom
protected abstract java.lang.Class<?> resolveClassFrom(Input input, boolean mapped, boolean array) throws java.io.IOException
- Throws:
java.io.IOException
-
createMessageInstance
protected static <T> T createMessageInstance(java.lang.Class<T> clazz)
-
-