Package io.protostuff.runtime
Class IdStrategy
java.lang.Object
io.protostuff.runtime.IdStrategy
- Direct Known Subclasses:
DefaultIdStrategy
,NumericIdStrategy
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 the primaryGroup
is not set.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic interface
Responsible for instantiating customIdStrategy
impls.private static final class
static class
Thrown when a type is not known by the IdStrategy.(package private) static final class
-
Field Summary
FieldsModifier and TypeFieldDescription(package private) final ArraySchemas.BigDecimalArray
(package private) final ArraySchemas.BigIntegerArray
(package private) final ArraySchemas.BoolArray
(package private) final ArraySchemas.BoolArray
(package private) final ArraySchemas.BoolArray
(package private) final ArraySchemas.ByteArrayArray
(package private) final ArraySchemas.ByteStringArray
(package private) final ArraySchemas.CharArray
(package private) final ArraySchemas.CharArray
(package private) final ArraySchemas.CharArray
(package private) final ArraySchemas.DateArray
(package private) final ArraySchemas.DoubleArray
(package private) final ArraySchemas.DoubleArray
(package private) final ArraySchemas.DoubleArray
(package private) final ArraySchema
(package private) final ArraySchemas.FloatArray
(package private) final ArraySchemas.FloatArray
(package private) final ArraySchemas.FloatArray
(package private) final ArraySchemas.Int32Array
(package private) final ArraySchemas.Int32Array
(package private) final ArraySchemas.Int32Array
(package private) final ArraySchemas.Int64Array
(package private) final ArraySchemas.Int64Array
(package private) final ArraySchemas.Int64Array
(package private) final Pipe.Schema
<Object> (package private) final ArraySchemas.ShortArray
(package private) final ArraySchemas.ShortArray
(package private) final ArraySchemas.ShortArray
(package private) final ArraySchemas.StringArray
static final int
(package private) final ClassSchema
(package private) final Pipe.Schema
<Object> (package private) final Pipe.Schema
<Collection<Object>> (package private) final Schema
<Collection<Object>> static final int
static final int
(package private) final Pipe.Schema
<Object> (package private) final Pipe.Schema
<Map.Entry<Object, Object>> static final int
final int
final int
(package private) final Pipe.Schema
<Map<Object, Object>> static final int
static final int
static final int
(package private) final NumberSchema
(package private) final ObjectSchema
(package private) final Pipe.Schema
<Object> static final int
static final int
(package private) final Pipe.Schema
<Object> (package private) final PolymorphicEnumSchema
(package private) final Pipe.Schema
<Object> (package private) final DerivativeSchema
(package private) final PolymorphicThrowableSchema
static final int
(package private) final boolean
final IdStrategy
-
Constructor Summary
ConstructorsModifierConstructorDescriptionprotected
IdStrategy
(int flags, IdStrategy primaryGroup, int groupId) -
Method Summary
Modifier and TypeMethodDescriptionprotected static <T> T
createMessageInstance
(Class<T> clazz) protected abstract CollectionSchema.MessageFactory
getCollectionFactory
(Class<?> clazz) Returns theCollectionSchema.MessageFactory
.abstract <T> Delegate
<T> getDelegate
(Class<? super T> typeClass) Returns thedelegate
.abstract <T> HasDelegate
<T> getDelegateWrapper
(Class<? super T> typeClass) Returns thedelegate
.Returns theEnumIO
.protected abstract MapSchema.MessageFactory
getMapFactory
(Class<?> clazz) Returns theMapSchema.MessageFactory
.abstract <T> HasSchema
<T> getSchemaWrapper
(Class<T> typeClass, boolean create) Returns theschema wrapper
.abstract boolean
isDelegateRegistered
(Class<?> typeClass) Returns true if there is aDelegate
explicitly registered for thetypeClass
.abstract boolean
isRegistered
(Class<?> typeClass) Returns true if thetypeClass
is explicitly registered.protected <T> Schema
<T> Generates a schema from the given class.protected abstract Class
<?> resolveArrayComponentTypeFrom
(Input input, boolean mapped) protected abstract 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, 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, Class<T> clazz, boolean registered) protected abstract void
writeArrayIdTo
(Output output, Class<?> componentType) protected abstract void
writeClassIdTo
(Output output, Class<?> componentType, boolean array) protected abstract void
writeCollectionIdTo
(Output output, int fieldNumber, Class<?> clazz) protected abstract void
writeEnumIdTo
(Output output, int fieldNumber, Class<?> clazz) protected abstract void
writeMapIdTo
(Output output, int fieldNumber, 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, Class<T> clazz)
-
Field Details
-
ENUMS_BY_NAME
public static final int ENUMS_BY_NAME- See Also:
-
AUTO_LOAD_POLYMORPHIC_CLASSES
public static final int AUTO_LOAD_POLYMORPHIC_CLASSES- See Also:
-
PRESERVE_NULL_ELEMENTS
public static final int PRESERVE_NULL_ELEMENTS- See Also:
-
MORPH_NON_FINAL_POJOS
public static final int MORPH_NON_FINAL_POJOS- See Also:
-
MORPH_COLLECTION_INTERFACES
public static final int MORPH_COLLECTION_INTERFACES- See Also:
-
MORPH_MAP_INTERFACES
public static final int MORPH_MAP_INTERFACES- See Also:
-
COLLECTION_SCHEMA_ON_REPEATED_FIELDS
public static final int COLLECTION_SCHEMA_ON_REPEATED_FIELDS- See Also:
-
POJO_SCHEMA_ON_COLLECTION_FIELDS
public static final int POJO_SCHEMA_ON_COLLECTION_FIELDS- See Also:
-
POJO_SCHEMA_ON_MAP_FIELDS
public static final int POJO_SCHEMA_ON_MAP_FIELDS- See Also:
-
DEFAULT_FLAGS
public static final int DEFAULT_FLAGS -
flags
public final int flags -
-
groupId
public final int groupId -
preserveNull
final boolean preserveNull -
POLYMORPHIC_POJO_ELEMENT_SCHEMA
-
ARRAY_ELEMENT_SCHEMA
-
NUMBER_ELEMENT_SCHEMA
-
CLASS_ELEMENT_SCHEMA
-
POLYMORPHIC_ENUM_ELEMENT_SCHEMA
-
POLYMORPHIC_THROWABLE_ELEMENT_SCHEMA
-
OBJECT_ELEMENT_SCHEMA
-
DYNAMIC_VALUE_SCHEMA
-
DYNAMIC_VALUE_PIPE_SCHEMA
-
COLLECTION_SCHEMA
-
COLLECTION_PIPE_SCHEMA
-
ARRAY_SCHEMA
-
ARRAY_PIPE_SCHEMA
-
MAP_SCHEMA
-
MAP_PIPE_SCHEMA
-
ENTRY_SCHEMA
-
ENTRY_PIPE_SCHEMA
-
OBJECT_SCHEMA
-
OBJECT_PIPE_SCHEMA
-
CLASS_SCHEMA
-
CLASS_PIPE_SCHEMA
-
POLYMORPHIC_COLLECTION_SCHEMA
-
POLYMORPHIC_COLLECTION_PIPE_SCHEMA
-
POLYMORPHIC_MAP_SCHEMA
-
POLYMORPHIC_MAP_PIPE_SCHEMA
-
ARRAY_BOOL_PRIMITIVE_SCHEMA
-
ARRAY_BOOL_BOXED_SCHEMA
-
ARRAY_BOOL_DERIVED_SCHEMA
-
ARRAY_CHAR_PRIMITIVE_SCHEMA
-
ARRAY_CHAR_BOXED_SCHEMA
-
ARRAY_CHAR_DERIVED_SCHEMA
-
ARRAY_SHORT_PRIMITIVE_SCHEMA
-
ARRAY_SHORT_BOXED_SCHEMA
-
ARRAY_SHORT_DERIVED_SCHEMA
-
ARRAY_INT32_PRIMITIVE_SCHEMA
-
ARRAY_INT32_BOXED_SCHEMA
-
ARRAY_INT32_DERIVED_SCHEMA
-
ARRAY_INT64_PRIMITIVE_SCHEMA
-
ARRAY_INT64_BOXED_SCHEMA
-
ARRAY_INT64_DERIVED_SCHEMA
-
ARRAY_FLOAT_PRIMITIVE_SCHEMA
-
ARRAY_FLOAT_BOXED_SCHEMA
-
ARRAY_FLOAT_DERIVED_SCHEMA
-
ARRAY_DOUBLE_PRIMITIVE_SCHEMA
-
ARRAY_DOUBLE_BOXED_SCHEMA
-
ARRAY_DOUBLE_DERIVED_SCHEMA
-
ARRAY_STRING_SCHEMA
-
ARRAY_BYTESTRING_SCHEMA
-
ARRAY_BYTEARRAY_SCHEMA
-
ARRAY_BIGDECIMAL_SCHEMA
-
ARRAY_BIGINTEGER_SCHEMA
-
ARRAY_DATE_SCHEMA
-
-
Constructor Details
-
IdStrategy
-
-
Method Details
-
newSchema
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
Returns true if there is aDelegate
explicitly registered for thetypeClass
. -
getDelegateWrapper
Returns thedelegate
. -
getDelegate
Returns thedelegate
. -
isRegistered
Returns true if thetypeClass
is explicitly registered. -
getSchemaWrapper
Returns theschema wrapper
. The caller is responsible that the typeClass is a pojo (e.g not an enum/array/etc). -
getEnumIO
Returns theEnumIO
. The callers (internal field factories) are responsible that the class provided is an enum class. -
getCollectionFactory
Returns theCollectionSchema.MessageFactory
. The callers (internal field factories) are responsible that the class provided implementsCollection
. -
getMapFactory
Returns theMapSchema.MessageFactory
. The callers (internal field factories}) are responsible that the class provided implementsMap
. -
writeCollectionIdTo
protected abstract void writeCollectionIdTo(Output output, int fieldNumber, Class<?> clazz) throws IOException - Throws:
IOException
-
transferCollectionId
protected abstract void transferCollectionId(Input input, Output output, int fieldNumber) throws IOException - Throws:
IOException
-
resolveCollectionFrom
protected abstract CollectionSchema.MessageFactory resolveCollectionFrom(Input input) throws IOException - Throws:
IOException
-
writeMapIdTo
protected abstract void writeMapIdTo(Output output, int fieldNumber, Class<?> clazz) throws IOException - Throws:
IOException
-
transferMapId
protected abstract void transferMapId(Input input, Output output, int fieldNumber) throws IOException - Throws:
IOException
-
resolveMapFrom
- Throws:
IOException
-
writeEnumIdTo
protected abstract void writeEnumIdTo(Output output, int fieldNumber, Class<?> clazz) throws IOException - Throws:
IOException
-
transferEnumId
protected abstract void transferEnumId(Input input, Output output, int fieldNumber) throws IOException - Throws:
IOException
-
resolveEnumFrom
- Throws:
IOException
-
tryWritePojoIdTo
protected abstract <T> HasSchema<T> tryWritePojoIdTo(Output output, int fieldNumber, Class<T> clazz, boolean registered) throws IOException - Throws:
IOException
-
writePojoIdTo
protected abstract <T> HasSchema<T> writePojoIdTo(Output output, int fieldNumber, Class<T> clazz) throws IOException - Throws:
IOException
-
transferPojoId
protected abstract <T> HasSchema<T> transferPojoId(Input input, Output output, int fieldNumber) throws IOException - Throws:
IOException
-
resolvePojoFrom
protected abstract <T> HasSchema<T> resolvePojoFrom(Input input, int fieldNumber) throws IOException - Throws:
IOException
-
writeMessageIdTo
protected abstract <T> Schema<T> writeMessageIdTo(Output output, int fieldNumber, Message<T> message) throws IOException - Throws:
IOException
-
tryWriteDelegateIdTo
protected abstract <T> HasDelegate<T> tryWriteDelegateIdTo(Output output, int fieldNumber, Class<T> clazz) throws IOException If this method returns null, the clazz was not registered as a delegate.- Throws:
IOException
-
transferDelegateId
protected abstract <T> HasDelegate<T> transferDelegateId(Input input, Output output, int fieldNumber) throws IOException - Throws:
IOException
-
resolveDelegateFrom
- Throws:
IOException
-
writeArrayIdTo
- Throws:
IOException
-
transferArrayId
protected abstract void transferArrayId(Input input, Output output, int fieldNumber, boolean mapped) throws IOException - Throws:
IOException
-
resolveArrayComponentTypeFrom
protected abstract Class<?> resolveArrayComponentTypeFrom(Input input, boolean mapped) throws IOException - Throws:
IOException
-
writeClassIdTo
protected abstract void writeClassIdTo(Output output, Class<?> componentType, boolean array) throws IOException - Throws:
IOException
-
transferClassId
protected abstract void transferClassId(Input input, Output output, int fieldNumber, boolean mapped, boolean array) throws IOException - Throws:
IOException
-
resolveClassFrom
protected abstract Class<?> resolveClassFrom(Input input, boolean mapped, boolean array) throws IOException - Throws:
IOException
-
createMessageInstance
-