diff --git a/src/java/com/threerings/presents/io/FieldMarshallerRegistry.java b/src/java/com/threerings/presents/io/FieldMarshallerRegistry.java index 9181b48fb..81e4bbbb1 100644 --- a/src/java/com/threerings/presents/io/FieldMarshallerRegistry.java +++ b/src/java/com/threerings/presents/io/FieldMarshallerRegistry.java @@ -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); } diff --git a/src/java/com/threerings/presents/io/StringArrayFieldMarshaller.java b/src/java/com/threerings/presents/io/StringArrayFieldMarshaller.java new file mode 100644 index 000000000..aa71d59cf --- /dev/null +++ b/src/java/com/threerings/presents/io/StringArrayFieldMarshaller.java @@ -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); + } +}