This was moved to ezgame/util and renamed the EZObjectMarshaller.
git-svn-id: svn+ssh://src.earth.threerings.net/narya/trunk@4339 542714f4-19e9-0310-aa3c-eee0fc999fb1
This commit is contained in:
@@ -1,64 +0,0 @@
|
||||
package com.threerings.util {
|
||||
|
||||
import flash.net.ObjectEncoding;
|
||||
|
||||
import flash.system.ApplicationDomain;
|
||||
|
||||
import flash.utils.ByteArray;
|
||||
import flash.utils.Endian;
|
||||
|
||||
import com.threerings.io.TypedArray;
|
||||
|
||||
/**
|
||||
* Utility methods for transferring flash properties via
|
||||
* the presents dobj system.
|
||||
*/
|
||||
public class FlashObjectMarshaller
|
||||
{
|
||||
public static function encode (
|
||||
obj :Object, encodeArrayElements :Boolean = true) :Object
|
||||
{
|
||||
if (obj == null) {
|
||||
return null;
|
||||
}
|
||||
if (encodeArrayElements && obj is Array) {
|
||||
var src :Array = (obj as Array);
|
||||
var dest :TypedArray = TypedArray.create(ByteArray);
|
||||
for each (var o :Object in src) {
|
||||
dest.push(encode(o, false));
|
||||
}
|
||||
return dest;
|
||||
}
|
||||
|
||||
// TODO: Our own encoding, that takes into account
|
||||
// the ApplicationDomain
|
||||
var bytes :ByteArray = new ByteArray();
|
||||
bytes.endian = Endian.BIG_ENDIAN;
|
||||
bytes.objectEncoding = ObjectEncoding.AMF3;
|
||||
bytes.writeObject(obj);
|
||||
return bytes;
|
||||
}
|
||||
|
||||
public static function decode (encoded :Object) :Object
|
||||
{
|
||||
if (encoded == null) {
|
||||
return null;
|
||||
}
|
||||
if (encoded is TypedArray) {
|
||||
var src :TypedArray = (encoded as TypedArray);
|
||||
var dest :Array = [];
|
||||
for each (var b :ByteArray in src) {
|
||||
dest.push(decode(b));
|
||||
}
|
||||
return dest;
|
||||
}
|
||||
var bytes :ByteArray = (encoded as ByteArray);
|
||||
|
||||
// TODO: Our own decoding, that takes into account
|
||||
// the ApplicationDomain
|
||||
bytes.endian = Endian.BIG_ENDIAN;
|
||||
bytes.objectEncoding = ObjectEncoding.AMF3;
|
||||
return bytes.readObject();
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user