Fixed some bugs with reading data back from the server, including
subtracting 4 from the length of the frame and fixing the reading of fields for which we have a basic streamer. git-svn-id: svn+ssh://src.earth.threerings.net/narya/trunk@3885 542714f4-19e9-0310-aa3c-eee0fc999fb1
This commit is contained in:
@@ -33,7 +33,12 @@ public class FrameReader extends EventDispatcher
|
|||||||
// all at once
|
// all at once
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
_length = _socket.readInt();
|
// the length specified is the length of the entire frame,
|
||||||
|
// including the length of the bytes used to encode the length.
|
||||||
|
// (I think this is pretty silly).
|
||||||
|
// So for our purposes we subtract 4 bytes so we know how much
|
||||||
|
// more data is in the frame.
|
||||||
|
_length = _socket.readInt() - HEADER_SIZE;
|
||||||
_curData = new ByteArray();
|
_curData = new ByteArray();
|
||||||
_curData.endian = Endian.BIG_ENDIAN;
|
_curData.endian = Endian.BIG_ENDIAN;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -84,7 +84,7 @@ public class ObjectInputStream
|
|||||||
readBareObjectImpl(obj, Streamer.getStreamer(obj));
|
readBareObjectImpl(obj, Streamer.getStreamer(obj));
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function readBareObjectImpl (obj :Object, streamer :Streamer) :void
|
internal function readBareObjectImpl (obj :Object, streamer :Streamer) :void
|
||||||
{
|
{
|
||||||
// streamable objects
|
// streamable objects
|
||||||
if (streamer == null) {
|
if (streamer == null) {
|
||||||
@@ -110,8 +110,10 @@ public class ObjectInputStream
|
|||||||
//throws IOError
|
//throws IOError
|
||||||
{
|
{
|
||||||
if (readBoolean()) {
|
if (readBoolean()) {
|
||||||
var obj :Object = new clazz();
|
var streamer :Streamer = Streamer.getStreamerByClass(clazz);
|
||||||
return readBareObject(obj);
|
var obj :Object = streamer.createObject(this);
|
||||||
|
streamer.readObject(obj, this);
|
||||||
|
return obj;
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -14,37 +14,30 @@ import com.threerings.io.streamers.StringStreamer;
|
|||||||
|
|
||||||
public class Streamer
|
public class Streamer
|
||||||
{
|
{
|
||||||
/*
|
|
||||||
public static function getStreamer (className :String) :Streamer
|
|
||||||
//throws IOError
|
|
||||||
{
|
|
||||||
if (_streamerMap == null) {
|
|
||||||
createStreamers();
|
|
||||||
}
|
|
||||||
|
|
||||||
var streamer :Streamer = _streamerMap[className];
|
|
||||||
if (streamer == null) {
|
|
||||||
streamer = new Streamer(className);
|
|
||||||
_streamerMap[className] = streamer;
|
|
||||||
}
|
|
||||||
|
|
||||||
return streamer;
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
|
|
||||||
public static function getStreamer (obj :Object) :Streamer
|
public static function getStreamer (obj :Object) :Streamer
|
||||||
{
|
{
|
||||||
if (obj is Streamable) {
|
if (obj is Streamable) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (_streamers == null) {
|
initStreamers();
|
||||||
createStreamers();
|
|
||||||
|
for each (var streamer :Streamer in _streamers) {
|
||||||
|
if (streamer.isStreamerFor(obj)) {
|
||||||
|
return streamer;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
for (var ii :int = 0; ii < _streamers.length; ii++) {
|
return undefined;
|
||||||
if (_streamers[ii].isStreamerFor(obj)) {
|
}
|
||||||
return _streamers[ii];
|
|
||||||
|
public static function getStreamerByClass (clazz :Class) :Streamer
|
||||||
|
{
|
||||||
|
initStreamers();
|
||||||
|
|
||||||
|
for each (var streamer :Streamer in _streamers) {
|
||||||
|
if (streamer._targ == clazz) {
|
||||||
|
return streamer;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -53,13 +46,11 @@ public class Streamer
|
|||||||
|
|
||||||
public static function getStreamerByJavaName (jname :String) :Streamer
|
public static function getStreamerByJavaName (jname :String) :Streamer
|
||||||
{
|
{
|
||||||
if (_streamers == null) {
|
initStreamers();
|
||||||
createStreamers();
|
|
||||||
}
|
|
||||||
|
|
||||||
for (var ii :int = 0; ii < _streamers.length; ii++) {
|
for each (var streamer :Streamer in _streamers) {
|
||||||
if (_streamers[ii].getJavaClassName() === jname) {
|
if (streamer.getJavaClassName() === jname) {
|
||||||
return _streamers[ii];
|
return streamer;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -116,21 +107,21 @@ public class Streamer
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates our streamers table map and registers streamers for
|
* Initialize our streamers. This cannot simply be done statically
|
||||||
* basic types.
|
* because we cannot instantiate a subclass when this class is still
|
||||||
|
* being created. Fucking actionscript.
|
||||||
*/
|
*/
|
||||||
protected static function createStreamers () :void
|
private static function initStreamers () :void
|
||||||
{
|
{
|
||||||
_streamers = new Array();
|
if (_streamers == null) {
|
||||||
|
_streamers = [
|
||||||
// add our default streamers
|
new StringStreamer(),
|
||||||
_streamers.push(
|
new IntStreamer(),
|
||||||
new StringStreamer(),
|
new NumberStreamer(),
|
||||||
new IntStreamer(),
|
new ArrayStreamer(),
|
||||||
new NumberStreamer(),
|
new ByteArrayStreamer()
|
||||||
new ArrayStreamer(),
|
];
|
||||||
new ByteArrayStreamer()
|
}
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
protected var _targ :Class;
|
protected var _targ :Class;
|
||||||
|
|||||||
@@ -133,6 +133,8 @@ public class Communicator
|
|||||||
{
|
{
|
||||||
// convert the frame data into a message from the server
|
// convert the frame data into a message from the server
|
||||||
var frameData :ByteArray = event.getFrameData();
|
var frameData :ByteArray = event.getFrameData();
|
||||||
|
//trace("length of in frame: " + frameData.length);
|
||||||
|
//trace("inBuffer: " + Util.bytesToString(frameData));
|
||||||
_inStream.setSource(frameData);
|
_inStream.setSource(frameData);
|
||||||
var msg :DownstreamMessage =
|
var msg :DownstreamMessage =
|
||||||
(_inStream.readObject() as DownstreamMessage);
|
(_inStream.readObject() as DownstreamMessage);
|
||||||
|
|||||||
Reference in New Issue
Block a user