Marshall and unmarshall arrays in a standard way.
git-svn-id: svn+ssh://src.earth.threerings.net/narya/trunk@4336 542714f4-19e9-0310-aa3c-eee0fc999fb1
This commit is contained in:
@@ -7,17 +7,28 @@ import flash.system.ApplicationDomain;
|
|||||||
import flash.utils.ByteArray;
|
import flash.utils.ByteArray;
|
||||||
import flash.utils.Endian;
|
import flash.utils.Endian;
|
||||||
|
|
||||||
|
import com.threerings.io.TypedArray;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Utility methods for transferring flash properties via
|
* Utility methods for transferring flash properties via
|
||||||
* the presents dobj system.
|
* the presents dobj system.
|
||||||
*/
|
*/
|
||||||
public class FlashObjectMarshaller
|
public class FlashObjectMarshaller
|
||||||
{
|
{
|
||||||
public static function encode (obj :Object) :ByteArray
|
public static function encode (
|
||||||
|
obj :Object, keepArrays :Boolean = false) :Object
|
||||||
{
|
{
|
||||||
if (obj == null) {
|
if (obj == null) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
if (!keepArrays && 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, true));
|
||||||
|
}
|
||||||
|
return dest;
|
||||||
|
}
|
||||||
|
|
||||||
// TODO: Our own encoding, that takes into account
|
// TODO: Our own encoding, that takes into account
|
||||||
// the ApplicationDomain
|
// the ApplicationDomain
|
||||||
@@ -28,11 +39,20 @@ public class FlashObjectMarshaller
|
|||||||
return bytes;
|
return bytes;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function decode (bytes :ByteArray) :Object
|
public static function decode (encoded :Object) :Object
|
||||||
{
|
{
|
||||||
if (bytes == null) {
|
if (encoded == null) {
|
||||||
return 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
|
// TODO: Our own decoding, that takes into account
|
||||||
// the ApplicationDomain
|
// the ApplicationDomain
|
||||||
|
|||||||
Reference in New Issue
Block a user