diff --git a/src/java/com/threerings/presents/io/Streamable.java b/src/java/com/threerings/presents/io/Streamable.java new file mode 100644 index 000000000..5b3a1f1d8 --- /dev/null +++ b/src/java/com/threerings/presents/io/Streamable.java @@ -0,0 +1,36 @@ +// +// $Id: Streamable.java,v 1.1 2001/08/16 03:25:14 mdb Exp $ + +package com.threerings.cocktail.cher.io; + +import java.io.IOException; +import java.io.DataInputStream; +import java.io.DataOutputStream; + +/** + * A streamable is an object that knows how to read and write itself on a + * stream. We are obliged to reimplement an object serialization framework + * rather than use the one provided by Java because we're interested in + * taking maximal advantage of situations where we know the types of + * objects that are being streamed and in those cases we avoid writing + * type information for the objects and only write the values. In other + * cases, we assign unique codes to object classes (see {@link + * TypedObject}) to minimize the network footprint of the serialized + * objects. + */ +public interface Streamable +{ + /** + * Writes all of the members of this object to the supplied data + * output stream. + */ + public void writeTo (DataOutputStream out) + throws IOException; + + /** + * Reads all of the members of this object in from the supplied data + * input stream. + */ + public void readFrom (DataInputStream in) + throws IOException; +} diff --git a/src/java/com/threerings/presents/io/TypedObject.java b/src/java/com/threerings/presents/io/TypedObject.java index 17abf934c..0ba3125fe 100644 --- a/src/java/com/threerings/presents/io/TypedObject.java +++ b/src/java/com/threerings/presents/io/TypedObject.java @@ -1,12 +1,8 @@ // -// $Id: TypedObject.java,v 1.3 2001/05/30 23:58:31 mdb Exp $ +// $Id: TypedObject.java,v 1.4 2001/08/16 03:25:14 mdb Exp $ package com.threerings.cocktail.cher.io; -import java.io.IOException; -import java.io.DataInputStream; -import java.io.DataOutputStream; - /** * A typed object is one that is associated with a particular type code. * The type code can be communicated on the wire and used by the receiving @@ -15,7 +11,7 @@ import java.io.DataOutputStream; * * @see TypedObjectFactory */ -public interface TypedObject +public interface TypedObject extends Streamable { /** * Each typed object class must associate itself with a type value via @@ -26,16 +22,4 @@ public interface TypedObject * @return The type code associated with this object. */ public short getType (); - - /** - * Each typed object class must be able to write itself to a stream. - */ - public void writeTo (DataOutputStream out) - throws IOException; - - /** - * Each typed object class must be able to read itself from a stream. - */ - public void readFrom (DataInputStream in) - throws IOException; }