Package io.protostuff.runtime
Class EnumIO<E extends java.lang.Enum<E>>
- java.lang.Object
-
- io.protostuff.runtime.EnumIO<E>
-
- All Implemented Interfaces:
PolymorphicSchema.Factory
- Direct Known Subclasses:
EnumIO.ByName
,EnumIO.ByNumber
public abstract class EnumIO<E extends java.lang.Enum<E>> extends java.lang.Object implements PolymorphicSchema.Factory
Determines how enums are serialized/deserialized. Default is BY_NUMBER. To enable BY_NAME, set the property "protostuff.runtime.enums_by_name=true".
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
EnumIO.ByName<E extends java.lang.Enum<E>>
Reads the enum by its name.static class
EnumIO.ByNumber<E extends java.lang.Enum<E>>
Reads the enum by its number.
-
Field Summary
Fields Modifier and Type Field Description private static java.lang.reflect.Field
__elementTypeFromEnumSet
private static java.lang.reflect.Field
__keyTypeFromEnumMap
private java.lang.String[]
alias
java.lang.Class<E>
enumClass
The enum class.private MapSchema.MessageFactory
enumMapFactory
private CollectionSchema.MessageFactory
enumSetFactory
ArraySchemas.Base
genericElementSchema
IdStrategy
strategy
private int[]
tag
private java.util.Map<java.lang.String,E>
valueByAliasMap
private java.util.Map<java.lang.Integer,E>
valueByTagMap
-
Constructor Summary
Constructors Constructor Description EnumIO(java.lang.Class<E> enumClass, IdStrategy strategy)
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description java.lang.String
getAlias(java.lang.Enum<?> element)
E
getByAlias(java.lang.String alias)
E
getByTag(int tag)
(package private) static java.lang.Class<?>
getElementTypeFromEnumSet(java.lang.Object enumSet)
Retrieves the enum key type from the EnumMap via reflection.MapSchema.MessageFactory
getEnumMapFactory()
Returns the factory for an EnumMap (lazy).CollectionSchema.MessageFactory
getEnumSetFactory()
Returns the factory for an EnumSet (lazy).(package private) static java.lang.Class<?>
getKeyTypeFromEnumMap(java.lang.Object enumMap)
Retrieves the enum key type from the EnumMap via reflection.int
getTag(java.lang.Enum<?> element)
(package private) static EnumIO<? extends java.lang.Enum<?>>
newEnumIO(java.lang.Class<?> enumClass, IdStrategy strategy)
<V> java.util.EnumMap<E,V>
newEnumMap()
Returns an emptyEnumMap
.private static <E extends java.lang.Enum<E>>
MapSchema.MessageFactorynewEnumMapFactory(EnumIO<E> eio)
java.util.EnumSet<E>
newEnumSet()
Returns an emptyEnumSet
.private static <E extends java.lang.Enum<E>>
CollectionSchema.MessageFactorynewEnumSetFactory(EnumIO<E> eio)
PolymorphicSchema
newSchema(java.lang.Class<?> typeClass, IdStrategy strategy, PolymorphicSchema.Handler handler)
abstract E
readFrom(Input input)
Read the enum from the input.static void
transfer(Pipe pipe, Input input, Output output, int number, boolean repeated, IdStrategy strategy)
Transfers theEnum
from the input to the output.void
writeTo(Output output, int number, boolean repeated, java.lang.Enum<?> e)
Writes theEnum
to the output.
-
-
-
Field Detail
-
__keyTypeFromEnumMap
private static final java.lang.reflect.Field __keyTypeFromEnumMap
-
__elementTypeFromEnumSet
private static final java.lang.reflect.Field __elementTypeFromEnumSet
-
strategy
public final IdStrategy strategy
-
genericElementSchema
public final ArraySchemas.Base genericElementSchema
-
enumSetFactory
private volatile CollectionSchema.MessageFactory enumSetFactory
-
enumMapFactory
private volatile MapSchema.MessageFactory enumMapFactory
-
alias
private final java.lang.String[] alias
-
tag
private final int[] tag
-
valueByAliasMap
private final java.util.Map<java.lang.String,E extends java.lang.Enum<E>> valueByAliasMap
-
-
Constructor Detail
-
EnumIO
public EnumIO(java.lang.Class<E> enumClass, IdStrategy strategy)
-
-
Method Detail
-
getKeyTypeFromEnumMap
static java.lang.Class<?> getKeyTypeFromEnumMap(java.lang.Object enumMap)
Retrieves the enum key type from the EnumMap via reflection. This is used byObjectSchema
.
-
getElementTypeFromEnumSet
static java.lang.Class<?> getElementTypeFromEnumSet(java.lang.Object enumSet)
Retrieves the enum key type from the EnumMap via reflection. This is used byObjectSchema
.
-
newEnumIO
static EnumIO<? extends java.lang.Enum<?>> newEnumIO(java.lang.Class<?> enumClass, IdStrategy strategy)
-
writeTo
public void writeTo(Output output, int number, boolean repeated, java.lang.Enum<?> e) throws java.io.IOException
Writes theEnum
to the output.- Throws:
java.io.IOException
-
transfer
public static void transfer(Pipe pipe, Input input, Output output, int number, boolean repeated, IdStrategy strategy) throws java.io.IOException
Transfers theEnum
from the input to the output.- Throws:
java.io.IOException
-
newEnumSetFactory
private static <E extends java.lang.Enum<E>> CollectionSchema.MessageFactory newEnumSetFactory(EnumIO<E> eio)
-
newEnumMapFactory
private static <E extends java.lang.Enum<E>> MapSchema.MessageFactory newEnumMapFactory(EnumIO<E> eio)
-
newSchema
public PolymorphicSchema newSchema(java.lang.Class<?> typeClass, IdStrategy strategy, PolymorphicSchema.Handler handler)
- Specified by:
newSchema
in interfacePolymorphicSchema.Factory
-
getTag
public int getTag(java.lang.Enum<?> element)
-
getAlias
public java.lang.String getAlias(java.lang.Enum<?> element)
-
getByTag
public E getByTag(int tag)
-
getByAlias
public E getByAlias(java.lang.String alias)
-
getEnumSetFactory
public CollectionSchema.MessageFactory getEnumSetFactory()
Returns the factory for an EnumSet (lazy).
-
getEnumMapFactory
public MapSchema.MessageFactory getEnumMapFactory()
Returns the factory for an EnumMap (lazy).
-
newEnumSet
public java.util.EnumSet<E> newEnumSet()
Returns an emptyEnumSet
.
-
newEnumMap
public <V> java.util.EnumMap<E,V> newEnumMap()
Returns an emptyEnumMap
.
-
-