Package net.sf.eBus.messages.type
Class EnumType
- java.lang.Object
-
- net.sf.eBus.messages.type.DataType
-
- net.sf.eBus.messages.type.EnumType
-
- All Implemented Interfaces:
java.lang.Comparable<DataType>
public final class EnumType extends DataType
Provides binary serialization/de-serialization ofjava.lang.Enum
instances.- Author:
- Charles Rapp
-
-
Field Summary
Fields Modifier and Type Field Description static int
BYTES
Anenum
requires 2 bytes for encoding.-
Fields inherited from class net.sf.eBus.messages.type.DataType
ADDRESS_TYPE, ARRAY_SUFFIX, CLASS_TYPE, DEFAULT_CHARSET, EMPTY_STRING, FIELD_MASK_SIZE, INDENT, INDENT1, KEY_TYPE, MAX_ARRAY_SIZE, MAX_BIG_INTEGER_SIZE, MAX_CLASS_NAME_LENGTH, MAX_FIELDS, MAX_FILE_NAME_LENGTH, MAX_STRING_LENGTH, MAX_ZONE_ID_LENGTH, mBuiltinFlag, mClass, mDefaultValue, mIsFixedSize, mSize, sClasses, sCompiledClasses, sTextTypes, STRING_TYPE, sVariableTypes, VARIABLE_SIZE
-
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected void
createDeserializer(MessageType.MessageField field, java.lang.String fieldName, java.lang.String indent, java.util.Formatter output, boolean useBuilder)
Generates the code to de-serialize the enum instance from aByteBuffer
based on the enum ordinal value.protected void
createSerializer(MessageType.MessageField field, java.lang.String fieldName, java.lang.String indent, java.util.Formatter output)
Adds the Java code used to serialize the enum ordinal value to aByteBuffer
.java.lang.Object
deserialize(MessageType.MessageField field, java.nio.ByteBuffer buffer)
Returns the de-serializedEnum
inbuffer
.boolean
isInstance(java.lang.Object o)
Returnstrue
ifo
is a non-null
enum instance andfalse
otherwise.void
serialize(java.lang.Object o, MessageType.MessageField field, java.nio.ByteBuffer buffer)
Serializes thisEnum
ordinal to the givenbuffer
.-
Methods inherited from class net.sf.eBus.messages.type.DataType
compareTo, dataClass, dataClassName, defaultValue, equals, fields, findCharset, findType, hashCode, isArray, isBoolean, isBoolean, isBuiltin, isEnum, isField, isFixedSize, isLocalOnly, isMessage, isPrimitive, maxAllowedTextSize, replyClasses, size, toString
-
-
-
-
Field Detail
-
BYTES
public static final int BYTES
Anenum
requires 2 bytes for encoding.- See Also:
- Constant Field Values
-
-
Method Detail
-
isInstance
public boolean isInstance(java.lang.Object o)
Returnstrue
ifo
is a non-null
enum instance andfalse
otherwise.- Overrides:
isInstance
in classDataType
- Parameters:
o
- Check this object's type.- Returns:
true
ifo
is a non-null
enum instance andfalse
otherwise.
-
serialize
public void serialize(java.lang.Object o, MessageType.MessageField field, java.nio.ByteBuffer buffer)
Serializes thisEnum
ordinal to the givenbuffer
.- Specified by:
serialize
in classDataType
- Parameters:
o
- AEnum
object. May benull
.field
- contains external information needed to serialize this message field.buffer
- serialize to this buffer.- Throws:
java.nio.BufferOverflowException
- ifbuffer
overflows.- See Also:
deserialize(net.sf.eBus.messages.type.MessageType.MessageField, java.nio.ByteBuffer)
-
deserialize
public java.lang.Object deserialize(MessageType.MessageField field, java.nio.ByteBuffer buffer)
Returns the de-serializedEnum
inbuffer
.- Specified by:
deserialize
in classDataType
- Parameters:
field
- contains information needed to de-serialize this message field.buffer
- de-serialize theEnum
object from thisByteBuffer
.- Returns:
- the de-serialized
Enum
. - Throws:
java.nio.BufferUnderflowException
- ifbuffer
contains an incomplete serialized enum.- See Also:
serialize(java.lang.Object, net.sf.eBus.messages.type.MessageType.MessageField, java.nio.ByteBuffer)
-
createSerializer
protected void createSerializer(MessageType.MessageField field, java.lang.String fieldName, java.lang.String indent, java.util.Formatter output)
Adds the Java code used to serialize the enum ordinal value to aByteBuffer
.- Specified by:
createSerializer
in classDataType
- Parameters:
field
- message field.fieldName
- the message field name.indent
- indent the code by this amount.output
- write the code to this formatter.
-
createDeserializer
protected void createDeserializer(MessageType.MessageField field, java.lang.String fieldName, java.lang.String indent, java.util.Formatter output, boolean useBuilder)
Generates the code to de-serialize the enum instance from aByteBuffer
based on the enum ordinal value.- Specified by:
createDeserializer
in classDataType
- Parameters:
field
- message field.fieldName
- store the de-serialized field in this name.indent
- indent the code by this amount.output
- append the code to this formatter.useBuilder
- iftrue
thenfieldName
is a builder method name; otherwise a local variable.
-
-