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.StringERROR_TAG_VALUEprivate FieldMap<T>fieldMapRuntimeEnv.Instantiator<T>instantiatorstatic intMAX_TAG_VALUEstatic intMIN_TAG_FOR_HASH_FIELD_MAPstatic intMIN_TAG_VALUEprivate static java.util.Set<java.lang.String>NO_EXCLUSIONSprivate Pipe.Schema<T>pipeSchemaprivate 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 voidfill(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)intgetFieldCount()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.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.booleanisInitialized(T message)Always returns true, everything is optional.static booleanisRegistered(java.lang.Class<?> typeClass)Returns true if thetypeClasswas not lazily created.static booleanisRegistered(java.lang.Class<?> typeClass, IdStrategy strategy)Returns true if thetypeClasswas not lazily created.static <T> booleanmap(java.lang.Class<? super T> baseClass, java.lang.Class<T> typeClass)Maps thebaseClassto a specific non-interface/non-abstracttypeClassand registers it (this must be done on application startup).voidmergeFrom(Input input, T message)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.TnewMessage()Creates the message/object tied to this schema.private booleanpreferHashFieldMap(java.util.Collection<Field<T>> fields, int lastFieldNumber)static <T> booleanregister(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> booleanregister(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.voidwriteTo(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 thebaseClassto a specific non-interface/non-abstracttypeClassand registers it (this must be done on application startup).With this approach, there is no overhead of writing the type metadata if a
baseClassfield is serialized.Returns true if the baseClass does not exist.
NOTE: This is only supported when
RuntimeEnv.ID_STRATEGYisDefaultIdStrategy.- Throws:
java.lang.IllegalArgumentException- if thetypeClassis 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_STRATEGYisDefaultIdStrategy.
-
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_STRATEGYisDefaultIdStrategy.
-
isRegistered
public static boolean isRegistered(java.lang.Class<?> typeClass)
Returns true if thetypeClasswas not lazily created.Method overload for backwards compatibility.
-
isRegistered
public static boolean isRegistered(java.lang.Class<?> typeClass, IdStrategy strategy)Returns true if thetypeClasswas 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:
getFieldByNumberin interfaceFieldMap<T>
-
getFieldByName
public Field<T> getFieldByName(java.lang.String fieldName)
- Specified by:
getFieldByNamein interfaceFieldMap<T>
-
getFieldCount
public int getFieldCount()
- Specified by:
getFieldCountin interfaceFieldMap<T>
-
typeClass
public java.lang.Class<T> typeClass()
Description copied from interface:SchemaGets the class of the message.
-
messageName
public 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<T>
-
messageFullName
public 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<T>
-
getFieldName
public 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<T>
-
getFieldNumber
public 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<T>
-
mergeFrom
public final void mergeFrom(Input input, T message) throws java.io.IOException
Description copied from interface:SchemaDeserializes a message/object from theinput.
-
writeTo
public final void writeTo(Output output, T message) throws java.io.IOException
Description copied from interface:SchemaSerializes a message/object to theoutput.
-
isInitialized
public boolean isInitialized(T message)
Always returns true, everything is optional.- Specified by:
isInitializedin interfaceSchema<T>
-
newMessage
public T newMessage()
Description copied from interface:SchemaCreates the message/object tied to this schema.- Specified by:
newMessagein 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.
-
-