public abstract class DataType extends Object implements Comparable<DataType>
DataType
subclass which is responsible for serializing and
deserializing field values. Both binary and text serialization
is supported. This class maintains a Java class-to-DataType
instance map. Thus for each
EField class, there is only one
data type instance used for serialization. The data type
instances are created only as needed and only once.| Modifier and Type | Field and Description |
|---|---|
protected static InetAddressType |
ADDRESS_TYPE
The Internet address type is used to serialize and
de-serialize the address portion of the socket address.
|
static String |
ARRAY_SUFFIX
A Type name ending in "[]" is an array.
|
static Charset |
CHARSET
eBus uses
StandardCharsets.UTF_8 to serialize and
de-serialize strings. |
protected static ClassType |
CLASS_TYPE
Used to serialize/de-serialize a Java class.
|
protected static String |
EMPTY_STRING
The default return value for text serialization is an
empty string ("").
|
protected static int |
FIELD_MASK_SIZE
The field mask is a 4-byte, signed integer.
|
protected static String |
INDENT
Use two blanks as generated retval indent.
|
protected static String |
INDENT1
A four blank indent used for fields.
|
protected static MessageKeyType |
KEY_TYPE
Used to serialize/de-serialize an eBus message key.
|
static int |
MAX_ARRAY_SIZE
An array or collection data type may contain at most
1,000 elements.
|
static int |
MAX_FIELDS
A message object may have at most 31 fields.
|
static int |
MAX_FILE_NAME_LENGTH
The maximum file name length is 1,024 characters.
|
static int |
MAX_STRING_LENGTH
Strings may be at most 1,024 characters.
|
protected boolean |
mBuiltinFlag
This flag is
true if the data type is considered a
built-in type. |
protected Class<?> |
mClass
The Java class represented by this data type.
|
protected Object |
mDefaultValue
If a built-in type value is not specified, then set it
to this default value.
|
protected int |
mSize
Number of bytes needed to represent this data type.
|
protected static Map<String,Class<?>> |
sClasses
Caches the Java class instance associated with a given
fully-qualified class name.
|
protected static List<Class<? extends EMessageObject>> |
sCompiledClasses
Tracks which
EMessageObject classes are compiled. |
protected static StringType |
STRING_TYPE
Used by subclass for
String
serialization/de-serialization. |
static int |
VARIABLE_SIZE
When a data type's size is variable then set the size
to
Integer.MAX_VALUE. |
| Modifier | Constructor and Description |
|---|---|
protected |
DataType(Class<?> jClass,
boolean builtinFlag,
int size,
Object defaultValue)
Set this data type Java class type.
|
| Modifier and Type | Method and Description |
|---|---|
int |
compareTo(DataType dataType)
Returns an integer value < zero, zero or > 0 if
this data type is <, equals or >
findType. |
protected abstract void |
createDeserializer(MessageType.MessageField field,
String fieldName,
String indent,
Formatter output,
boolean useBuilder)
Adds the Java retval used to de-serialize the named field
from a
ByteBuffer. |
protected abstract void |
createSerializer(MessageType.MessageField field,
String fieldName,
String indent,
Formatter output)
Adds the Java retval used to serialize the named field to
a
ByteBuffer. |
Class<?> |
dataClass()
Returns the associated Java class.
|
String |
dataClassName()
Returns the Java class name.
|
Object |
defaultValue()
Returns the default value for this type.
|
abstract Object |
deserialize(ByteBuffer buffer)
Returns the deserialized object in
buffer. |
boolean |
equals(Object o)
Returns
true if o is not
null, is an instance of DataType
and has the same Java class. |
static List<MultiKey2<String,DataType>> |
fields(Class<? extends EMessageObject> mc)
Returns the specified message class or field class
field name, data type pairs.
|
protected static Charset |
findCharset(String name)
Returns the character set with the given name.
|
static DataType |
findType(Class<?> jClass)
Returns the data type object associated with the class.
|
int |
hashCode()
Returns the data type's hash retval based on the class type.
|
boolean |
isArray()
Returns
true if this data type is an array and
false otherwise. |
boolean |
isBuiltin()
Returns
true if this data type is considered an
eBus built-in type and false otherwise. |
boolean |
isEnum()
Returns
true if this is an enum data type and
false otherwise. |
boolean |
isInstance(Object o)
Returns
true if o is of the
proper type and false otherwise. |
boolean |
isLocalOnly()
Returns
true if this message type is local-only
and false if this message type may be transmitted
to remote eBus applications. |
boolean |
isMessage()
Returns
true if this message type is for an
EMessage and false if for an
EField. |
boolean |
isPrimitive()
Returns
true if this data type is for a
Java primitive type and false otherwise. |
static List<Class<? extends EReplyMessage>> |
replyClasses(String[] args)
Returns the reply classes associated with a request
message class via the
EReplyInfo annotation. |
abstract void |
serialize(Object o,
ByteBuffer buffer)
Serializes
o to the given buffer. |
int |
size()
Returns the data type size in bytes.
|
String |
toString()
Returns the data type's Java class name.
|
public static final int MAX_ARRAY_SIZE
public static final int MAX_STRING_LENGTH
public static final int MAX_FILE_NAME_LENGTH
public static final int MAX_FIELDS
public static final Charset CHARSET
StandardCharsets.UTF_8 to serialize and
de-serialize strings.public static final String ARRAY_SUFFIX
public static final int VARIABLE_SIZE
Integer.MAX_VALUE.protected static final int FIELD_MASK_SIZE
protected static final String EMPTY_STRING
protected static final String INDENT
protected static final String INDENT1
protected static final StringType STRING_TYPE
String
serialization/de-serialization.protected static final InetAddressType ADDRESS_TYPE
protected static final ClassType CLASS_TYPE
protected static final MessageKeyType KEY_TYPE
protected static final Map<String,Class<?>> sClasses
protected static final List<Class<? extends EMessageObject>> sCompiledClasses
EMessageObject classes are compiled.protected transient Class<?> mClass
protected final boolean mBuiltinFlag
true if the data type is considered a
built-in type.protected final int mSize
protected final Object mDefaultValue
null for all other
types.protected DataType(Class<?> jClass, boolean builtinFlag, int size, Object defaultValue)
jClass - the Java associated Java class.builtinFlag - true if this data type is a
built-in type.size - data type size in bytes.defaultValue - the default value for this type.public abstract void serialize(Object o, ByteBuffer buffer) throws BufferOverflowException
o to the given buffer.o - serialize this object.buffer - serialize o to this buffer.BufferOverflowException - if serializing o overruns buffer's
available capacity.public abstract Object deserialize(ByteBuffer buffer) throws BufferUnderflowException, ValidationException
buffer.buffer - Deserialize the object from this
ByteBuffer.BufferUnderflowException - if buffer contains fewer bytes than needed to
completely deserialize the object.ValidationException - if buffer contains an invalid eBus message.protected abstract void createSerializer(MessageType.MessageField field, String fieldName, String indent, Formatter output)
ByteBuffer.field - message field.fieldName - the message field name.indent - indent the retval by this amount.output - write the retval to this formatter.protected abstract void createDeserializer(MessageType.MessageField field, String fieldName, String indent, Formatter output, boolean useBuilder)
ByteBuffer. Store the result into a
message/field builder if useBuilder is
true and into a local field otherwise.field - message field.fieldName - fully-qualified message field name.indent - indent the retval by this amount.output - write the retval to this formatter.useBuilder - if true then fieldName
is a builder method name; otherwise a local variable.public int compareTo(DataType dataType)
findType.
The comparison is based on the class name.compareTo in interface Comparable<DataType>dataType - compare to this data type.findType.public boolean equals(Object o)
true if o is not
null, is an instance of DataType
and has the same Java class. Otherwise returns
false.public int hashCode()
public String toString()
public boolean isInstance(Object o)
true if o is of the
proper type and false otherwise.o - check this object's type.true if o is of the
proper type and false otherwise.public final Class<?> dataClass()
public String dataClassName()
public final boolean isArray()
true if this data type is an array and
false otherwise.true if the data type is an array.public final boolean isBuiltin()
true if this data type is considered an
eBus built-in type and false otherwise.true if this is an eBus built-in type.public final boolean isPrimitive()
true if this data type is for a
Java primitive type and false otherwise.true if this is a Java primitive type.public final boolean isEnum()
true if this is an enum data type and
false otherwise.true if this is an enum data type.public final boolean isMessage()
true if this message type is for an
EMessage and false if for an
EField.true if the underlying type is an
EMessage.public boolean isLocalOnly()
true if this message type is local-only
and false if this message type may be transmitted
to remote eBus applications.true if this is a local-only message
object.public final int size()
VARIABLE_SIZE if the type size is variable.public final Object defaultValue()
null.public static DataType findType(Class<?> jClass) throws IllegalArgumentException, InvalidMessageException
DataType for jClass. Throws either an
IllegalArgumentException or
InvalidMessageException if this cannot be done.jClass - A Java class instance.IllegalArgumentException - if jClass is an unsupported eBus message type.InvalidMessageException - if jClass is an EMessageObject with an
invalid message layout.public static List<MultiKey2<String,DataType>> fields(Class<? extends EMessageObject> mc) throws IllegalArgumentException, InvalidMessageException
mc - find the fields for this EMessage or
EField class.mc field name, data type pairs.IllegalArgumentException - if mc is null.InvalidMessageException - if mc is an invalid eBus message.public static List<Class<? extends EReplyMessage>> replyClasses(String[] args)
EReplyInfo annotation. This
method is called by compiled request message class to
initialize the
private static final Class[] REPLY_CLASSES field.args - single element array containing the message
class name.Copyright © 2019. All rights reserved.