Package io.protostuff.runtime
Class RuntimeSchema<T>
- java.lang.Object
-
- io.protostuff.runtime.RuntimeSchema<T>
-
-
Field Summary
Fields Modifier and Type Field Description static java.lang.String
ERROR_TAG_VALUE
private FieldMap<T>
fieldMap
RuntimeEnv.Instantiator<T>
instantiator
static int
MAX_TAG_VALUE
static int
MIN_TAG_FOR_HASH_FIELD_MAP
static int
MIN_TAG_VALUE
private static java.util.Set<java.lang.String>
NO_EXCLUSIONS
private Pipe.Schema<T>
pipeSchema
private java.lang.Class<T>
typeClass
-
Constructor Summary
Constructors Constructor Description RuntimeSchema(java.lang.Class<T> typeClass, java.util.Collection<Field<T>> fields, RuntimeEnv.Instantiator<T> instantiator)
RuntimeSchema(java.lang.Class<T> typeClass, java.util.Collection<Field<T>> fields, java.lang.reflect.Constructor<T> constructor)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description private FieldMap<T>
createFieldMap(java.util.Collection<Field<T>> fields)
static <T> RuntimeSchema<T>
createFrom(java.lang.Class<T> typeClass)
Generates a schema from the given class.static <T> RuntimeSchema<T>
createFrom(java.lang.Class<T> typeClass, IdStrategy strategy)
Generates a schema from the given class.static <T> RuntimeSchema<T>
createFrom(java.lang.Class<T> typeClass, java.lang.String[] exclusions, IdStrategy strategy)
Generates a schema from the given class with the exclusion of certain fields.static <T> RuntimeSchema<T>
createFrom(java.lang.Class<T> typeClass, java.util.Map<java.lang.String,java.lang.String> declaredFields, IdStrategy strategy)
Generates a schema from the given class with the declared fields (inclusive) based from the given Map.static <T> RuntimeSchema<T>
createFrom(java.lang.Class<T> typeClass, java.util.Set<java.lang.String> exclusions, IdStrategy strategy)
Generates a schema from the given class with the exclusion of certain fields.(package private) static void
fill(java.util.Map<java.lang.String,java.lang.reflect.Field> fieldMap, java.lang.Class<?> typeClass)
(package private) static java.util.Map<java.lang.String,java.lang.reflect.Field>
findInstanceFields(java.lang.Class<?> typeClass)
Field<T>
getFieldByName(java.lang.String fieldName)
Field<T>
getFieldByNumber(int n)
int
getFieldCount()
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.java.util.List<Field<T>>
getFields()
Pipe.Schema<T>
getPipeSchema()
Returns the pipe schema linked to this.static <T> Schema<T>
getSchema(java.lang.Class<T> typeClass)
Gets the schema that was either registered or lazily initialized at runtime.static <T> Schema<T>
getSchema(java.lang.Class<T> typeClass, IdStrategy strategy)
Gets the schema that was either registered or lazily initialized at runtime.(package private) static <T> HasSchema<T>
getSchemaWrapper(java.lang.Class<T> typeClass)
Returns the schema wrapper.(package private) static <T> HasSchema<T>
getSchemaWrapper(java.lang.Class<T> typeClass, IdStrategy strategy)
Returns the schema wrapper.boolean
isInitialized(T message)
Always returns true, everything is optional.static boolean
isRegistered(java.lang.Class<?> typeClass)
Returns true if thetypeClass
was not lazily created.static boolean
isRegistered(java.lang.Class<?> typeClass, IdStrategy strategy)
Returns true if thetypeClass
was not lazily created.static <T> boolean
map(java.lang.Class<? super T> baseClass, java.lang.Class<T> typeClass)
Maps thebaseClass
to a specific non-interface/non-abstracttypeClass
and registers it (this must be done on application startup).void
mergeFrom(Input input, T message)
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.T
newMessage()
Creates the message/object tied to this schema.private boolean
preferHashFieldMap(java.util.Collection<Field<T>> fields, int lastFieldNumber)
static <T> boolean
register(java.lang.Class<T> typeClass)
Returns true if this there is no existing one or the same schema has already been registered (this must be done on application startup).static <T> boolean
register(java.lang.Class<T> typeClass, Schema<T> schema)
Returns true if this there is no existing one or the same schema has already been registered (this must be done on application startup).(package private) static <T> Pipe.Schema<T>
resolvePipeSchema(Schema<T> schema, java.lang.Class<? super T> clazz, boolean throwIfNone)
Invoked only when applications are having pipe io operations.java.lang.Class<T>
typeClass()
Gets the class of the message.void
writeTo(Output output, T message)
Serializes a message/object to theoutput
.
-
-
-
Field Detail
-
MIN_TAG_VALUE
public static final int MIN_TAG_VALUE
- See Also:
- Constant Field Values
-
MAX_TAG_VALUE
public static final int MAX_TAG_VALUE
- See Also:
- Constant Field Values
-
ERROR_TAG_VALUE
public static final java.lang.String ERROR_TAG_VALUE
- See Also:
- Constant Field Values
-
NO_EXCLUSIONS
private static final java.util.Set<java.lang.String> NO_EXCLUSIONS
-
MIN_TAG_FOR_HASH_FIELD_MAP
public static final int MIN_TAG_FOR_HASH_FIELD_MAP
- See Also:
- Constant Field Values
-
pipeSchema
private final Pipe.Schema<T> pipeSchema
-
typeClass
private final java.lang.Class<T> typeClass
-
instantiator
public final RuntimeEnv.Instantiator<T> instantiator
-
-
Constructor Detail
-
RuntimeSchema
public RuntimeSchema(java.lang.Class<T> typeClass, java.util.Collection<Field<T>> fields, java.lang.reflect.Constructor<T> constructor)
-
RuntimeSchema
public RuntimeSchema(java.lang.Class<T> typeClass, java.util.Collection<Field<T>> fields, RuntimeEnv.Instantiator<T> instantiator)
-
-
Method Detail
-
map
public static <T> boolean map(java.lang.Class<? super T> baseClass, java.lang.Class<T> typeClass)
Maps thebaseClass
to a specific non-interface/non-abstracttypeClass
and registers it (this must be done on application startup).With this approach, there is no overhead of writing the type metadata if a
baseClass
field is serialized.Returns true if the baseClass does not exist.
NOTE: This is only supported when
RuntimeEnv.ID_STRATEGY
isDefaultIdStrategy
.- Throws:
java.lang.IllegalArgumentException
- if thetypeClass
is an interface or an abstract class.
-
register
public static <T> boolean register(java.lang.Class<T> typeClass, Schema<T> schema)
Returns true if this there is no existing one or the same schema has already been registered (this must be done on application startup).NOTE: This is only supported when
RuntimeEnv.ID_STRATEGY
isDefaultIdStrategy
.
-
register
public static <T> boolean register(java.lang.Class<T> typeClass)
Returns true if this there is no existing one or the same schema has already been registered (this must be done on application startup).NOTE: This is only supported when
RuntimeEnv.ID_STRATEGY
isDefaultIdStrategy
.
-
isRegistered
public static boolean isRegistered(java.lang.Class<?> typeClass)
Returns true if thetypeClass
was not lazily created.Method overload for backwards compatibility.
-
isRegistered
public static boolean isRegistered(java.lang.Class<?> typeClass, IdStrategy strategy)
Returns true if thetypeClass
was not lazily created.
-
getSchema
public static <T> Schema<T> getSchema(java.lang.Class<T> typeClass)
Gets the schema that was either registered or lazily initialized at runtime.Method overload for backwards compatibility.
-
getSchema
public static <T> Schema<T> getSchema(java.lang.Class<T> typeClass, IdStrategy strategy)
Gets the schema that was either registered or lazily initialized at runtime.
-
getSchemaWrapper
static <T> HasSchema<T> getSchemaWrapper(java.lang.Class<T> typeClass)
Returns the schema wrapper.Method overload for backwards compatibility.
-
getSchemaWrapper
static <T> HasSchema<T> getSchemaWrapper(java.lang.Class<T> typeClass, IdStrategy strategy)
Returns the schema wrapper.
-
createFrom
public static <T> RuntimeSchema<T> createFrom(java.lang.Class<T> typeClass)
Generates a schema from the given class.Method overload for backwards compatibility.
-
createFrom
public static <T> RuntimeSchema<T> createFrom(java.lang.Class<T> typeClass, IdStrategy strategy)
Generates a schema from the given class.
-
createFrom
public static <T> RuntimeSchema<T> createFrom(java.lang.Class<T> typeClass, java.lang.String[] exclusions, IdStrategy strategy)
Generates a schema from the given class with the exclusion of certain fields.
-
createFrom
public static <T> RuntimeSchema<T> createFrom(java.lang.Class<T> typeClass, java.util.Set<java.lang.String> exclusions, IdStrategy strategy)
Generates a schema from the given class with the exclusion of certain fields.
-
createFrom
public static <T> RuntimeSchema<T> createFrom(java.lang.Class<T> typeClass, java.util.Map<java.lang.String,java.lang.String> declaredFields, IdStrategy strategy)
Generates a schema from the given class with the declared fields (inclusive) based from the given Map. The value of a the Map's entry will be the name used for the field (which enables aliasing).
-
findInstanceFields
static java.util.Map<java.lang.String,java.lang.reflect.Field> findInstanceFields(java.lang.Class<?> typeClass)
-
fill
static void fill(java.util.Map<java.lang.String,java.lang.reflect.Field> fieldMap, java.lang.Class<?> typeClass)
-
preferHashFieldMap
private boolean preferHashFieldMap(java.util.Collection<Field<T>> fields, int lastFieldNumber)
-
getPipeSchema
public Pipe.Schema<T> getPipeSchema()
Returns the pipe schema linked to this.
-
getFieldByNumber
public Field<T> getFieldByNumber(int n)
- Specified by:
getFieldByNumber
in interfaceFieldMap<T>
-
getFieldByName
public Field<T> getFieldByName(java.lang.String fieldName)
- Specified by:
getFieldByName
in interfaceFieldMap<T>
-
getFieldCount
public int getFieldCount()
- Specified by:
getFieldCount
in interfaceFieldMap<T>
-
typeClass
public java.lang.Class<T> typeClass()
Description copied from interface:Schema
Gets the class of the message.
-
messageName
public 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<T>
-
messageFullName
public 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<T>
-
getFieldName
public 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<T>
-
getFieldNumber
public 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<T>
-
mergeFrom
public final void mergeFrom(Input input, T message) throws java.io.IOException
Description copied from interface:Schema
Deserializes a message/object from theinput
.
-
writeTo
public final void writeTo(Output output, T message) throws java.io.IOException
Description copied from interface:Schema
Serializes a message/object to theoutput
.
-
isInitialized
public boolean isInitialized(T message)
Always returns true, everything is optional.- Specified by:
isInitialized
in interfaceSchema<T>
-
newMessage
public T newMessage()
Description copied from interface:Schema
Creates the message/object tied to this schema.- Specified by:
newMessage
in interfaceSchema<T>
-
resolvePipeSchema
static <T> Pipe.Schema<T> resolvePipeSchema(Schema<T> schema, java.lang.Class<? super T> clazz, boolean throwIfNone)
Invoked only when applications are having pipe io operations.
-
-