com.dyuproject.protostuff.runtime
Class EnumIO<E extends java.lang.Enum<E>>

java.lang.Object
  extended by com.dyuproject.protostuff.runtime.EnumIO<E>
Direct Known Subclasses:
EnumIO.ByName, EnumIO.ByNumber

public abstract class EnumIO<E extends java.lang.Enum<E>>
extends java.lang.Object

Determines how enums are serialized/deserialized. Default is BY_NUMBER. To enable BY_NAME, set the property "protostuff.runtime.enums_by_name=true".

Author:
David Yu
Date created:
Oct 20, 2010

Nested Class Summary
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
 java.lang.Class<E> enumClass
          The enum class.
 
Constructor Summary
EnumIO(java.lang.Class<E> enumClass)
           
 
Method Summary
 MapSchema.MessageFactory getEnumMapFactory()
          Returns the factory for an EnumMap (lazy).
 CollectionSchema.MessageFactory getEnumSetFactory()
          Returns the factory for an EnumSet (lazy).
<V> java.util.EnumMap<E,V>
newEnumMap()
          Returns an empty EnumMap.
 java.util.EnumSet<E> newEnumSet()
          Returns an empty EnumSet.
abstract  E readFrom(Input input)
          Read the enum from the input.
static void transfer(Pipe pipe, Input input, Output output, int number, boolean repeated)
          Transfers the Enum from the input to the output.
static void writeTo(Output output, int number, boolean repeated, java.lang.Enum<?> e)
          Writes the Enum to the output.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

enumClass

public final java.lang.Class<E extends java.lang.Enum<E>> enumClass
The enum class.

Constructor Detail

EnumIO

public EnumIO(java.lang.Class<E> enumClass)
Method Detail

writeTo

public static void writeTo(Output output,
                           int number,
                           boolean repeated,
                           java.lang.Enum<?> e)
                    throws java.io.IOException
Writes the Enum to the output.

Throws:
java.io.IOException

transfer

public static void transfer(Pipe pipe,
                            Input input,
                            Output output,
                            int number,
                            boolean repeated)
                     throws java.io.IOException
Transfers the Enum from the input to the output.

Throws:
java.io.IOException

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 empty EnumSet.


newEnumMap

public <V> java.util.EnumMap<E,V> newEnumMap()
Returns an empty EnumMap.


readFrom

public abstract E readFrom(Input input)
                                              throws java.io.IOException
Read the enum from the input.

Throws:
java.io.IOException


Copyright © 2009-2014. All Rights Reserved.