avm2: Implement Serialization for ByteArrayObject
This commit is contained in:
parent
b1149cd267
commit
69b09ab1ef
|
@ -73,6 +73,8 @@ pub fn serialize_value<'gc>(
|
||||||
.to_string(),
|
.to_string(),
|
||||||
true,
|
true,
|
||||||
))
|
))
|
||||||
|
} else if let Some(bytearray) = o.as_bytearray() {
|
||||||
|
Some(AmfValue::ByteArray(bytearray.bytes().to_vec()))
|
||||||
} else {
|
} else {
|
||||||
let is_object = o
|
let is_object = o
|
||||||
.instance_of()
|
.instance_of()
|
||||||
|
|
|
@ -0,0 +1,34 @@
|
||||||
|
package {
|
||||||
|
import flash.utils.ByteArray;
|
||||||
|
import flash.display.Sprite;
|
||||||
|
|
||||||
|
public class Test extends Sprite {
|
||||||
|
private function PrintByteArray(name: String, data:ByteArray):void {
|
||||||
|
var bytes: Array = []
|
||||||
|
for (var i: int = 0; i < data.length; i++) {
|
||||||
|
bytes.push(data.readUnsignedByte());
|
||||||
|
}
|
||||||
|
trace(name + ": " + bytes);
|
||||||
|
data.position = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function Test() {
|
||||||
|
|
||||||
|
var original:ByteArray = new ByteArray();
|
||||||
|
original.writeUTF("hello world");
|
||||||
|
original.position = 0;
|
||||||
|
|
||||||
|
PrintByteArray("Original", original);
|
||||||
|
|
||||||
|
var serialized:ByteArray = new ByteArray();
|
||||||
|
serialized.writeObject(original);
|
||||||
|
serialized.position = 0;
|
||||||
|
|
||||||
|
PrintByteArray("Serialized", serialized);
|
||||||
|
|
||||||
|
var readBack:ByteArray = serialized.readObject();
|
||||||
|
|
||||||
|
PrintByteArray("ReadBack", readBack);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,3 @@
|
||||||
|
Original: 0,11,104,101,108,108,111,32,119,111,114,108,100
|
||||||
|
Serialized: 12,27,0,11,104,101,108,108,111,32,119,111,114,108,100
|
||||||
|
ReadBack: 0,11,104,101,108,108,111,32,119,111,114,108,100
|
Binary file not shown.
|
@ -0,0 +1 @@
|
||||||
|
num_frames = 1
|
Loading…
Reference in New Issue