Added support for null Streamable fields.
git-svn-id: svn+ssh://src.earth.threerings.net/narya/trunk@1029 542714f4-19e9-0310-aa3c-eee0fc999fb1
This commit is contained in:
@@ -1,5 +1,5 @@
|
|||||||
//
|
//
|
||||||
// $Id: StreamableFieldMarshaller.java,v 1.3 2002/02/01 23:32:37 mdb Exp $
|
// $Id: StreamableFieldMarshaller.java,v 1.4 2002/02/19 03:30:55 mdb Exp $
|
||||||
|
|
||||||
package com.threerings.presents.io;
|
package com.threerings.presents.io;
|
||||||
|
|
||||||
@@ -18,20 +18,29 @@ public class StreamableFieldMarshaller implements FieldMarshaller
|
|||||||
Streamable value = (Streamable)field.get(obj);
|
Streamable value = (Streamable)field.get(obj);
|
||||||
// we freak out if our streamable is null
|
// we freak out if our streamable is null
|
||||||
if (value == null) {
|
if (value == null) {
|
||||||
throw new IllegalAccessException(
|
out.writeByte(0);
|
||||||
"No streamable instance to marshall!");
|
} else {
|
||||||
|
out.writeByte(1);
|
||||||
|
value.writeTo(out);
|
||||||
}
|
}
|
||||||
value.writeTo(out);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void readFrom (DataInputStream in, Field field, Object obj)
|
public void readFrom (DataInputStream in, Field field, Object obj)
|
||||||
throws IOException, IllegalAccessException
|
throws IOException, IllegalAccessException
|
||||||
{
|
{
|
||||||
try {
|
try {
|
||||||
// create a new instance into which to unmarshall the field
|
byte isNull = in.readByte();
|
||||||
Streamable value = (Streamable)field.getType().newInstance();
|
Streamable value = null;
|
||||||
// unserialize it
|
|
||||||
value.readFrom(in);
|
// instantiate and unserialize the streamable if we actually
|
||||||
|
// have a value
|
||||||
|
if (isNull == 1) {
|
||||||
|
// create a new instance into which to unmarshall the field
|
||||||
|
value = (Streamable)field.getType().newInstance();
|
||||||
|
// unserialize it
|
||||||
|
value.readFrom(in);
|
||||||
|
}
|
||||||
|
|
||||||
// and set the value in the object
|
// and set the value in the object
|
||||||
field.set(obj, value);
|
field.set(obj, value);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user