Some more progress.
I still need to work on the Streaming, but I've figured out how to do a bit of introspection which will be necessary when streaming an array. Started working on the client classes, did ClientObserver and SessionObserver stuff using flash's event notification system. git-svn-id: svn+ssh://src.earth.threerings.net/narya/trunk@3846 542714f4-19e9-0310-aa3c-eee0fc999fb1
This commit is contained in:
@@ -0,0 +1,41 @@
|
||||
package com.threerings.io.streamers {
|
||||
|
||||
import com.threerings.io.ObjectInputStream;
|
||||
import com.threerings.io.ObjectOutputStream;
|
||||
import com.threerings.io.Streamer;
|
||||
|
||||
/**
|
||||
* A Streamer for Array objects.
|
||||
*/
|
||||
public class ArrayStreamer extends Streamer
|
||||
{
|
||||
public function ArrayStreamer ()
|
||||
{
|
||||
super(Array);
|
||||
}
|
||||
|
||||
public override function createObject (ins :ObjectInputStream) :*
|
||||
{
|
||||
return new Array(ins.readInt());
|
||||
}
|
||||
|
||||
public override function writeObject (obj :*, out :ObjectOutputStream,
|
||||
useWriter :Boolean) :void
|
||||
{
|
||||
var arr :Array = (obj as Array);
|
||||
out.writeInt(arr.length);
|
||||
for (var ii :int = 0; ii < arr.length; ii++) {
|
||||
out.writeObject(arr[ii]);
|
||||
}
|
||||
}
|
||||
|
||||
public override function readObject (obj :*, ins :ObjectInputStream,
|
||||
useReader :Boolean) :void
|
||||
{
|
||||
var arr :Array = (obj as Array);
|
||||
for (var ii :int = 0; ii < arr.length; ii++) {
|
||||
arr[ii] = ins.readObject();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,41 @@
|
||||
package com.threerings.io.streamers {
|
||||
|
||||
import flash.util.ByteArray;
|
||||
|
||||
import com.threerings.io.ObjectInputStream;
|
||||
import com.threerings.io.ObjectOutputStream;
|
||||
import com.threerings.io.Streamer;
|
||||
|
||||
/**
|
||||
* A Streamer for ByteArray objects.
|
||||
*/
|
||||
public class ByteArrayStreamer extends Streamer
|
||||
{
|
||||
public function ByteArrayStreamer ()
|
||||
{
|
||||
super(ByteArray);
|
||||
}
|
||||
|
||||
public override function createObject (ins :ObjectInputStream) :*
|
||||
{
|
||||
var bytes :ByteArray = new ByteArray();
|
||||
bytes.length = ins.readInt();
|
||||
return bytes;
|
||||
}
|
||||
|
||||
public override function writeObject (obj :*, out :ObjectOutputStream,
|
||||
useWriter :Boolean) :void
|
||||
{
|
||||
var bytes :ByteArray = (obj as ByteArray);
|
||||
out.writeInt(bytes.length);
|
||||
out.writeBytes(bytes);
|
||||
}
|
||||
|
||||
public override function readObject (obj :*, ins :ObjectInputStream,
|
||||
useReader :Boolean) :void
|
||||
{
|
||||
var bytes :ByteArray = (obj as ByteArray);
|
||||
ins.readBytes(bytes, 0, bytes.length);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
package com.threerings.io.streamers {
|
||||
|
||||
import com.threerings.io.ObjectInputStream;
|
||||
import com.threerings.io.ObjectOutputStream;
|
||||
import com.threerings.io.Streamer;
|
||||
|
||||
/**
|
||||
* A Streamer for int objects.
|
||||
*/
|
||||
public class IntStreamer extends Streamer
|
||||
{
|
||||
public function IntStreamer ()
|
||||
{
|
||||
super(int);
|
||||
}
|
||||
|
||||
public override function createObject (ins :ObjectInputStream) :*
|
||||
{
|
||||
return ins.readInt();
|
||||
}
|
||||
|
||||
public override function writeObject (obj :*, out :ObjectOutputStream,
|
||||
useWriter :Boolean) :void
|
||||
{
|
||||
var i :int = (obj as int);
|
||||
out.writeInt(i);
|
||||
}
|
||||
|
||||
public override function readObject (obj :*, ins :ObjectInputStream,
|
||||
useReader :Boolean) :void
|
||||
{
|
||||
// nothing here, the int is fully read in createObject()
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
package com.threerings.io.streamers {
|
||||
|
||||
import com.threerings.io.ObjectInputStream;
|
||||
import com.threerings.io.ObjectOutputStream;
|
||||
import com.threerings.io.Streamer;
|
||||
|
||||
/**
|
||||
* A Streamer for Number objects.
|
||||
*/
|
||||
public class NumberStreamer extends Streamer
|
||||
{
|
||||
public function NumberStreamer ()
|
||||
{
|
||||
super(Number);
|
||||
}
|
||||
|
||||
public override function createObject (ins :ObjectInputStream) :*
|
||||
{
|
||||
return ins.readDouble();
|
||||
}
|
||||
|
||||
public override function writeObject (obj :*, out :ObjectOutputStream,
|
||||
useWriter :Boolean) :void
|
||||
{
|
||||
var n :Number = (obj as Number);
|
||||
out.writeDouble(n);
|
||||
}
|
||||
|
||||
public override function readObject (obj :*, ins :ObjectInputStream,
|
||||
useReader :Boolean) :void
|
||||
{
|
||||
// nothing here, the Number is fully read in createObject()
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
package com.threerings.io.streamers {
|
||||
|
||||
import com.threerings.io.ObjectInputStream;
|
||||
import com.threerings.io.ObjectOutputStream;
|
||||
import com.threerings.io.Streamer;
|
||||
|
||||
/**
|
||||
* A Streamer for String objects.
|
||||
*/
|
||||
public class StringStreamer extends Streamer
|
||||
{
|
||||
public function StringStreamer ()
|
||||
{
|
||||
super(String);
|
||||
}
|
||||
|
||||
public override function createObject (ins :ObjectInputStream) :*
|
||||
{
|
||||
return ins.readUTF();
|
||||
}
|
||||
|
||||
public override function writeObject (obj :*, out :ObjectOutputStream,
|
||||
useWriter :Boolean) :void
|
||||
{
|
||||
var s :String = (obj as String);
|
||||
out.writeUTF(s);
|
||||
}
|
||||
|
||||
public override function readObject (obj :*, ins :ObjectInputStream,
|
||||
useReader :Boolean) :void
|
||||
{
|
||||
// nothing here, the String is fully read in createObject()
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user