From 59ad4a7955ece7da8bdb053a2ffdfd9b548c2e66 Mon Sep 17 00:00:00 2001 From: Michael Bayne Date: Thu, 2 Aug 2001 05:09:21 +0000 Subject: [PATCH] Added support for marshalling oid lists. git-svn-id: svn+ssh://src.earth.threerings.net/narya/trunk@147 542714f4-19e9-0310-aa3c-eee0fc999fb1 --- .../com/threerings/presents/dobj/OidList.java | 25 ++++++++++++- .../presents/io/OidListFieldMarshaller.java | 37 +++++++++++++++++++ 2 files changed, 61 insertions(+), 1 deletion(-) create mode 100644 src/java/com/threerings/presents/io/OidListFieldMarshaller.java diff --git a/src/java/com/threerings/presents/dobj/OidList.java b/src/java/com/threerings/presents/dobj/OidList.java index d3a2ceba1..07b915412 100644 --- a/src/java/com/threerings/presents/dobj/OidList.java +++ b/src/java/com/threerings/presents/dobj/OidList.java @@ -1,8 +1,12 @@ // -// $Id: OidList.java,v 1.1 2001/07/21 01:06:48 mdb Exp $ +// $Id: OidList.java,v 1.2 2001/08/02 05:09:21 mdb Exp $ package com.threerings.cocktail.cher.dobj; +import java.io.DataInputStream; +import java.io.DataOutputStream; +import java.io.IOException; + /** * An oid list is used to store lists of object ids. The list will not * allow duplicate ids. This class is not synchronized, with the @@ -128,6 +132,25 @@ public class OidList _oids = oids; } + public void writeTo (DataOutputStream out) + throws IOException + { + out.writeInt(_size); + for (int i = 0; i < _size; i++) { + out.writeInt(_oids[i]); + } + } + + public void readFrom (DataInputStream in) + throws IOException + { + _size = in.readInt(); + _oids = new int[Math.max(DEFAULT_SIZE, _size*2)]; + for (int i = 0; i < _size; i++) { + _oids[i] = in.readInt(); + } + } + private int[] _oids; private int _size; diff --git a/src/java/com/threerings/presents/io/OidListFieldMarshaller.java b/src/java/com/threerings/presents/io/OidListFieldMarshaller.java new file mode 100644 index 000000000..71a98f084 --- /dev/null +++ b/src/java/com/threerings/presents/io/OidListFieldMarshaller.java @@ -0,0 +1,37 @@ +// +// $Id: OidListFieldMarshaller.java,v 1.1 2001/08/02 05:09:21 mdb Exp $ + +package com.threerings.cocktail.cher.dobj.io; + +import java.io.DataInputStream; +import java.io.DataOutputStream; +import java.io.IOException; +import java.lang.reflect.Field; + +import com.threerings.cocktail.cher.dobj.DObject; +import com.threerings.cocktail.cher.dobj.OidList; + +public class OidListFieldMarshaller implements FieldMarshaller +{ + /** This is the sort of field that we marshall. */ + public OidList prototype; + + public void writeTo (DataOutputStream out, Field field, DObject dobj) + throws IOException, IllegalAccessException + { + OidList value = (OidList)field.get(dobj); + // we convert null oid lists to empty oid lists + if (value == null) { + value = new OidList(); + } + value.writeTo(out); + } + + public void readFrom (DataInputStream in, Field field, DObject dobj) + throws IOException, IllegalAccessException + { + OidList value = new OidList(); + value.readFrom(in); + field.set(dobj, value); + } +}