Added a field marshaller for string array fields.
git-svn-id: svn+ssh://src.earth.threerings.net/narya/trunk@466 542714f4-19e9-0310-aa3c-eee0fc999fb1
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
//
|
||||
// $Id: FieldMarshallerRegistry.java,v 1.8 2001/10/12 20:11:53 mdb Exp $
|
||||
// $Id: FieldMarshallerRegistry.java,v 1.9 2001/10/17 02:48:11 mdb Exp $
|
||||
|
||||
package com.threerings.presents.dobj.io;
|
||||
|
||||
@@ -84,6 +84,7 @@ public class FieldMarshallerRegistry
|
||||
registerMarshaller(FloatFieldMarshaller.class);
|
||||
registerMarshaller(DoubleFieldMarshaller.class);
|
||||
registerMarshaller(StringFieldMarshaller.class);
|
||||
registerMarshaller(StringArrayFieldMarshaller.class);
|
||||
registerMarshaller(OidListFieldMarshaller.class);
|
||||
registerMarshaller(DSetFieldMarshaller.class);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,43 @@
|
||||
//
|
||||
// $Id: StringArrayFieldMarshaller.java,v 1.1 2001/10/17 02:48:11 mdb Exp $
|
||||
|
||||
package com.threerings.presents.dobj.io;
|
||||
|
||||
import java.io.DataInputStream;
|
||||
import java.io.DataOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.lang.reflect.Field;
|
||||
|
||||
import com.threerings.presents.dobj.DObject;
|
||||
|
||||
public class StringArrayFieldMarshaller implements FieldMarshaller
|
||||
{
|
||||
/** This is the sort of field that we marshall. */
|
||||
public String[] prototype;
|
||||
|
||||
public void writeTo (DataOutputStream out, Field field, DObject dobj)
|
||||
throws IOException, IllegalAccessException
|
||||
{
|
||||
String[] value = (String[])field.get(dobj);
|
||||
// we convert null string arrays to zero length arrays
|
||||
if (value == null) {
|
||||
out.writeInt(0);
|
||||
|
||||
} else {
|
||||
out.writeInt(value.length);
|
||||
for (int i = 0; i < value.length; i++) {
|
||||
out.writeUTF(value[i]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void readFrom (DataInputStream in, Field field, DObject dobj)
|
||||
throws IOException, IllegalAccessException
|
||||
{
|
||||
String[] value = new String[in.readInt()];
|
||||
for (int i = 0; i < value.length; i++) {
|
||||
value[i] = in.readUTF();
|
||||
}
|
||||
field.set(dobj, value);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user