It doesn't get much simpler than this: objects that desire to be
streamable and that don't have funky requirements can simply extend SimpleStreamableObject and magically have their public fields streamed for them as well as have a useful default implementation of toString(). My tired fingers are thanking me already. git-svn-id: svn+ssh://src.earth.threerings.net/narya/trunk@917 542714f4-19e9-0310-aa3c-eee0fc999fb1
This commit is contained in:
@@ -0,0 +1,45 @@
|
||||
//
|
||||
// $Id: SimpleStreamableObject.java,v 1.1 2002/02/02 08:48:03 mdb Exp $
|
||||
|
||||
package com.threerings.presents.io;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.DataInputStream;
|
||||
import java.io.DataOutputStream;
|
||||
|
||||
import com.samskivert.util.StringUtil;
|
||||
|
||||
/**
|
||||
* A simple streamable object uses the {@link Marshaller} class to stream
|
||||
* its fields and provides a simple mechanism for objects to make
|
||||
* themselves streamable without having to write any code. They simply
|
||||
* declare all fields to be streamed as public data members (marking
|
||||
* public fields as <code>transient</code> that should not be streamed)
|
||||
* and ensure that the fields are all valid streamable types (see {@link
|
||||
* FieldMarshallerRegistry}).
|
||||
*/
|
||||
public class SimpleStreamableObject
|
||||
implements Streamable
|
||||
{
|
||||
// documentation inherited from interface
|
||||
public void writeTo (DataOutputStream out)
|
||||
throws IOException
|
||||
{
|
||||
Marshaller.writeObject(out, this);
|
||||
}
|
||||
|
||||
// documentation inherited from interface
|
||||
public void readFrom (DataInputStream in)
|
||||
throws IOException
|
||||
{
|
||||
Marshaller.readObject(in, this);
|
||||
}
|
||||
|
||||
/**
|
||||
* Generates a string representation of this instance.
|
||||
*/
|
||||
public String toString ()
|
||||
{
|
||||
return StringUtil.fieldsToString(this);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user