Need a field marshaller for Integer fields.
git-svn-id: svn+ssh://src.earth.threerings.net/narya/trunk@1272 542714f4-19e9-0310-aa3c-eee0fc999fb1
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
//
|
||||
// $Id: FieldMarshallerRegistry.java,v 1.14 2002/03/20 22:58:26 mdb Exp $
|
||||
// $Id: FieldMarshallerRegistry.java,v 1.15 2002/04/17 22:45:32 mdb Exp $
|
||||
|
||||
package com.threerings.presents.io;
|
||||
|
||||
@@ -92,6 +92,7 @@ public class FieldMarshallerRegistry
|
||||
registerMarshaller(ByteFieldMarshaller.class);
|
||||
registerMarshaller(ShortFieldMarshaller.class);
|
||||
registerMarshaller(IntFieldMarshaller.class);
|
||||
registerMarshaller(IntegerFieldMarshaller.class);
|
||||
registerMarshaller(LongFieldMarshaller.class);
|
||||
registerMarshaller(FloatFieldMarshaller.class);
|
||||
registerMarshaller(DoubleFieldMarshaller.class);
|
||||
|
||||
@@ -0,0 +1,29 @@
|
||||
//
|
||||
// $Id: IntegerFieldMarshaller.java,v 1.1 2002/04/17 22:45:32 mdb Exp $
|
||||
|
||||
package com.threerings.presents.io;
|
||||
|
||||
import java.io.DataInputStream;
|
||||
import java.io.DataOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.lang.reflect.Field;
|
||||
|
||||
public class IntegerFieldMarshaller implements FieldMarshaller
|
||||
{
|
||||
/** This is the sort of field that we marshall. */
|
||||
public Integer prototype;
|
||||
|
||||
public void writeTo (DataOutputStream out, Field field, Object obj)
|
||||
throws IOException, IllegalAccessException
|
||||
{
|
||||
Integer value = (Integer)field.get(obj);
|
||||
// we convert null integers to zero
|
||||
out.writeInt((value == null) ? 0 : value.intValue());
|
||||
}
|
||||
|
||||
public void readFrom (DataInputStream in, Field field, Object obj)
|
||||
throws IOException, IllegalAccessException
|
||||
{
|
||||
field.set(obj, new Integer(in.readInt()));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user