Added support for marshalling oid lists.
git-svn-id: svn+ssh://src.earth.threerings.net/narya/trunk@147 542714f4-19e9-0310-aa3c-eee0fc999fb1
This commit is contained in:
@@ -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;
|
||||
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user