public abstract class DataType extends java.lang.Object implements java.lang.Comparable<DataType>
DataType
subclass which is responsible for serializing and
de-serializing 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 java.lang.String |
ARRAY_SUFFIX
A Type name ending in "[]" is an array.
|
protected static ClassType |
CLASS_TYPE
Used to serialize/de-serialize a Java class.
|
static java.nio.charset.Charset |
DEFAULT_CHARSET
eBus uses
StandardCharsets.UTF_8 to serialize and
de-serialize strings. |
protected static java.lang.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 java.lang.String |
INDENT
Use two blanks as generated retval indent.
|
protected static java.lang.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
1000 elements.
|
static int |
MAX_BIG_INTEGER_SIZE
A serialized
BigInteger may contain at most
64 bytes. |
static int |
MAX_CLASS_NAME_LENGTH
Maximum class name length is limited to 8192
characters.
|
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.
|
static int |
MAX_ZONE_ID_LENGTH
Zone identifier maximum allowed size is 30.
|
protected boolean |
mBuiltinFlag
This flag is
true if the data type is considered a
built-in type. |
protected java.lang.Class<?> |
mClass
The Java class represented by this data type.
|
protected java.lang.Object |
mDefaultValue
If a built-in type value is not specified, then set it
to this default value.
|
protected boolean |
mIsFixedSize
Set to
true if this data type is of fixed size
and false if not. |
protected int |
mSize
Number of bytes needed to represent this data type.
|
protected static java.util.Map<java.lang.String,java.lang.Class<?>> |
sClasses
Caches the Java class instance associated with a given
fully-qualified class name.
|
protected static java.util.List<java.lang.Class<? extends EMessageObject>> |
sCompiledClasses
Tracks which
EMessageObject classes are compiled. |
protected static java.util.Map<java.lang.String,java.lang.Integer> |
sTextTypes
Maps supported eBus text types (using class name) to
default maximum allowed size;
|
protected static StringType |
STRING_TYPE
Used by subclass for
String
serialization/de-serialization. |
protected static java.util.Map<java.lang.String,java.lang.Integer> |
sVariableTypes
Maps supported eBus variable-sized types (using class
name) to default maximum allowed size.
|
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(java.lang.Class<?> jClass,
boolean builtinFlag,
int size,
java.lang.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,
java.lang.String fieldName,
java.lang.String indent,
java.util.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,
java.lang.String fieldName,
java.lang.String indent,
java.util.Formatter output)
Adds the Java retval used to serialize the named field to
a
ByteBuffer . |
java.lang.Class<?> |
dataClass()
Returns the associated Java class.
|
java.lang.String |
dataClassName()
Returns the Java class name.
|
java.lang.Object |
defaultValue()
Returns the default value for this type.
|
abstract java.lang.Object |
deserialize(MessageType.MessageField field,
java.nio.ByteBuffer buffer)
Returns the de-serialized object in
buffer . |
boolean |
equals(java.lang.Object o)
Returns
true if o is not
null , is an instance of DataType
and has the same Java class. |
static java.util.List<MultiKey2<java.lang.String,DataType>> |
fields(java.lang.Class<? extends EMessageObject> mc)
Returns the specified message class or field class
field name, data type pairs.
|
protected static java.nio.charset.Charset |
findCharset(java.lang.String name)
Returns the character set with the given name.
|
static DataType |
findType(java.lang.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 |
isBoolean()
Returns
true if this data type is either
a boolean primitive or Boolean class. |
static boolean |
isBoolean(java.lang.Class<?> dataClass)
Returns
true if the given data class is either
boolean or Boolean . |
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 |
isField()
Returns
true if this message type is for an
EField and false if for an
EMessage . |
boolean |
isFixedSize()
Returns
true if this field has a fixed size and
false if this field has a variable size. |
boolean |
isInstance(java.lang.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. |
protected static int |
maxAllowedTextSize(MessageType.MessageField field,
java.lang.Class<?> fieldClass)
Returns maximum allowed text field size.
|
static java.util.List<java.lang.Class<? extends EReplyMessage>> |
replyClasses(java.lang.String[] args)
Returns the reply classes associated with a request
message class via the
EReplyInfo annotation. |
abstract void |
serialize(java.lang.Object o,
MessageType.MessageField field,
java.nio.ByteBuffer buffer)
Serializes
o to the given buffer . |
int |
size()
Returns the data type size in bytes.
|
java.lang.String |
toString()
Returns the data type's Java class name.
|
public static final int MAX_ARRAY_SIZE
public static final int MAX_BIG_INTEGER_SIZE
BigInteger
may contain at most
64 bytes.public static final int MAX_CLASS_NAME_LENGTH
public static final int MAX_FILE_NAME_LENGTH
public static final int MAX_STRING_LENGTH
public static final int MAX_ZONE_ID_LENGTH
public static final int MAX_FIELDS
public static final java.nio.charset.Charset DEFAULT_CHARSET
StandardCharsets.UTF_8
to serialize and
de-serialize strings.public static final java.lang.String ARRAY_SUFFIX
public static final int VARIABLE_SIZE
Integer.MAX_VALUE
.protected static final int FIELD_MASK_SIZE
protected static final java.lang.String EMPTY_STRING
protected static final java.lang.String INDENT
protected static final java.lang.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 java.util.Map<java.lang.String,java.lang.Class<?>> sClasses
protected static final java.util.List<java.lang.Class<? extends EMessageObject>> sCompiledClasses
EMessageObject
classes are compiled.protected static final java.util.Map<java.lang.String,java.lang.Integer> sTextTypes
protected static final java.util.Map<java.lang.String,java.lang.Integer> sVariableTypes
protected java.lang.Class<?> mClass
protected final boolean mBuiltinFlag
true
if the data type is considered a
built-in type.protected final int mSize
protected final boolean mIsFixedSize
true
if this data type is of fixed size
and false
if not.protected final java.lang.Object mDefaultValue
null
for all other
types.protected DataType(java.lang.Class<?> jClass, boolean builtinFlag, int size, java.lang.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(@Nullable java.lang.Object o, @Nullable MessageType.MessageField field, java.nio.ByteBuffer buffer)
o
to the given buffer
.o
- serialize this object.field
- serialize this message field. Will be
null
when serializing message root.buffer
- serialize o
to this buffer.java.nio.BufferOverflowException
- if serializing o
overruns buffer
's
available capacity.@Nullable public abstract java.lang.Object deserialize(@Nullable MessageType.MessageField field, java.nio.ByteBuffer buffer) throws ValidationException
buffer
.field
- de-serialize this message field. Will be
null
when de-serializing message root.buffer
- de-serialize the object from this
ByteBuffer
.null
.DeserializeException
- if buffer
contains corrupted contents which cannot
be de-serialized into the target Java type.java.nio.BufferUnderflowException
- if buffer
contains fewer bytes than needed to
completely de-serialize the object.ValidationException
- if buffer
contains an invalid eBus message.protected abstract void createSerializer(MessageType.MessageField field, java.lang.String fieldName, java.lang.String indent, java.util.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, java.lang.String fieldName, java.lang.String indent, java.util.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 java.lang.Comparable<DataType>
dataType
- compare to this data type.findType
.public boolean equals(java.lang.Object o)
true
if o
is not
null
, is an instance of DataType
and has the same Java class. Otherwise returns
false
.equals
in class java.lang.Object
o
- compare against this object.true
if o
is not
null
, is an instance of DataType
and has the same Java class. Otherwise returns
false
.public int hashCode()
hashCode
in class java.lang.Object
public java.lang.String toString()
toString
in class java.lang.Object
public boolean isInstance(java.lang.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 java.lang.Class<?> dataClass()
public java.lang.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 isBoolean()
true
if this data type is either
a boolean
primitive or Boolean
class.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 final boolean isField()
true
if this message type is for an
EField
and false
if for an
EMessage
.true
if the underlying type is an
EField
.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 boolean isFixedSize()
true
if this field has a fixed size and
false
if this field has a variable size.true
if field is fixed size.public final java.lang.Object defaultValue()
null
.public static DataType findType(java.lang.Class<?> jClass) throws InvalidMessageException
DataType
for jClass
. Throws either an
IllegalArgumentException
or
InvalidMessageException
if this cannot be done.jClass
- A Java class instance.java.lang.IllegalArgumentException
- if jClass
is an unsupported eBus message type.InvalidMessageException
- if jClass
is an EMessageObject
with an
invalid message layout.public static boolean isBoolean(java.lang.Class<?> dataClass)
true
if the given data class is either
boolean
or Boolean
.dataClass
- check if this is a boolean type.true
if dataClass
is a boolean
type.public static java.util.List<MultiKey2<java.lang.String,DataType>> fields(java.lang.Class<? extends EMessageObject> mc) throws InvalidMessageException
mc
- find the fields for this EMessage
or
EField
class.mc
field name, data type pairs.java.lang.IllegalArgumentException
- if mc
is null
.InvalidMessageException
- if mc
is an invalid eBus message.public static java.util.List<java.lang.Class<? extends EReplyMessage>> replyClasses(java.lang.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.protected static java.nio.charset.Charset findCharset(java.lang.String name)
name
is not valid, then returns DEFAULT_CHARSET
.name
- character set name.protected static int maxAllowedTextSize(MessageType.MessageField field, java.lang.Class<?> fieldClass)
field
- retrieve maximum allowed size from this field.fieldClass
- field data type class.Copyright © 2001 - 2024. Charles W. Rapp. All rights reserved.