From ec3f1c1ddd879ee713122e65d9fb44fa2941048f Mon Sep 17 00:00:00 2001 From: Ray Greenwell Date: Thu, 10 Aug 2006 18:02:48 +0000 Subject: [PATCH] Added a utility class for marshalling flash Objects. git-svn-id: svn+ssh://src.earth.threerings.net/narya/trunk@4315 542714f4-19e9-0310-aa3c-eee0fc999fb1 --- .../threerings/util/FlashObjectMarshaller.as | 30 +++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 src/as/com/threerings/util/FlashObjectMarshaller.as diff --git a/src/as/com/threerings/util/FlashObjectMarshaller.as b/src/as/com/threerings/util/FlashObjectMarshaller.as new file mode 100644 index 000000000..0626caf81 --- /dev/null +++ b/src/as/com/threerings/util/FlashObjectMarshaller.as @@ -0,0 +1,30 @@ +package com.threerings.util { + +import flash.net.ObjectEncoding; + +import flash.utils.ByteArray; +import flash.utils.Endian; + +/** + * Utility methods for transferring flash properties via + * the presents dobj system. + */ +public class FlashObjectMarshaller +{ + public static function encode (obj :Object) :ByteArray + { + var bytes :ByteArray = new ByteArray(); + bytes.endian = Endian.BIG_ENDIAN; + bytes.objectEncoding = ObjectEncoding.AMF3; + bytes.writeObject(obj); + return bytes; + } + + public static function decode (bytes :ByteArray) :Object + { + bytes.endian = Endian.BIG_ENDIAN; + bytes.objectEncoding = ObjectEncoding.AMF3; + return bytes.readObject(); + } +} +}