com.threerings.io
Class FieldMarshaller

java.lang.Object
  extended by com.threerings.io.FieldMarshaller
Direct Known Subclasses:
FieldMarshaller.MethodFieldMarshaller, FieldMarshaller.StreamerMarshaller

public abstract class FieldMarshaller
extends Object

Used to read and write a single field of a Streamable instance.


Nested Class Summary
protected static class FieldMarshaller.MethodFieldMarshaller
          Uses custom accessor methods to read and write a field.
protected static class FieldMarshaller.StreamerMarshaller
          Used to marshall and unmarshall classes for which we have a basic Streamer.
 
Field Summary
protected static FieldMarshaller _internMarshaller
          The field marshaller for pooled strings.
protected static Map<Class<?>,FieldMarshaller> _marshallers
          Contains a mapping from field type to field marshaller instance for that type.
protected  String _type
           
protected static Class<?>[] READER_ARGS
          Defines the signature to a custom field reader method.
protected static Class<?>[] WRITER_ARGS
          Defines the signature to a custom field writer method.
 
Constructor Summary
FieldMarshaller()
           
FieldMarshaller(String type)
           
 
Method Summary
protected static Map<Class<?>,FieldMarshaller> createMarshallers()
          Creates and returns a mapping for all known field marshaller types.
static FieldMarshaller getFieldMarshaller(Field field)
          Returns a field marshaller appropriate for the supplied field or null if no marshaller exists for the type contained by the field in question.
static String getReaderMethodName(String field)
          Returns the name of the custom reader method which will be used if it exists to stream a field with the supplied name.
static String getWriterMethodName(String field)
          Returns the name of the custom writer method which will be used if it exists to stream a field with the supplied name.
abstract  void readField(Field field, Object target, ObjectInputStream in)
          Reads the contents of the supplied field from the supplied stream and sets it in the supplied object.
 String toString()
           
protected static boolean useFieldAccessors()
          Returns true if we should use the generated field marshaller methods that allow us to work around our inability to read and write protected and private fields of a Streamable.
abstract  void writeField(Field field, Object source, ObjectOutputStream out)
          Writes the contents of the supplied field in the supplied object to the supplied stream.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

_type

protected final String _type

_marshallers

protected static Map<Class<?>,FieldMarshaller> _marshallers
Contains a mapping from field type to field marshaller instance for that type.


_internMarshaller

protected static FieldMarshaller _internMarshaller
The field marshaller for pooled strings.


READER_ARGS

protected static final Class<?>[] READER_ARGS
Defines the signature to a custom field reader method.


WRITER_ARGS

protected static final Class<?>[] WRITER_ARGS
Defines the signature to a custom field writer method.

Constructor Detail

FieldMarshaller

public FieldMarshaller()

FieldMarshaller

public FieldMarshaller(String type)
Method Detail

readField

public abstract void readField(Field field,
                               Object target,
                               ObjectInputStream in)
                        throws Exception
Reads the contents of the supplied field from the supplied stream and sets it in the supplied object.

Throws:
Exception

writeField

public abstract void writeField(Field field,
                                Object source,
                                ObjectOutputStream out)
                         throws Exception
Writes the contents of the supplied field in the supplied object to the supplied stream.

Throws:
Exception

toString

public String toString()
Overrides:
toString in class Object

getFieldMarshaller

public static FieldMarshaller getFieldMarshaller(Field field)
Returns a field marshaller appropriate for the supplied field or null if no marshaller exists for the type contained by the field in question.


getReaderMethodName

public static final String getReaderMethodName(String field)
Returns the name of the custom reader method which will be used if it exists to stream a field with the supplied name.


getWriterMethodName

public static final String getWriterMethodName(String field)
Returns the name of the custom writer method which will be used if it exists to stream a field with the supplied name.


useFieldAccessors

protected static boolean useFieldAccessors()
Returns true if we should use the generated field marshaller methods that allow us to work around our inability to read and write protected and private fields of a Streamable.


createMarshallers

protected static Map<Class<?>,FieldMarshaller> createMarshallers()
Creates and returns a mapping for all known field marshaller types.