avm2: Implement Serialization for ByteArrayObject

This commit is contained in:
Niv.Kaminer 2023-06-23 01:31:43 +03:00 committed by Aaron Hill
parent b1149cd267
commit 69b09ab1ef
5 changed files with 40 additions and 0 deletions

View File

@ -73,6 +73,8 @@ pub fn serialize_value<'gc>(
.to_string(),
true,
))
} else if let Some(bytearray) = o.as_bytearray() {
Some(AmfValue::ByteArray(bytearray.bytes().to_vec()))
} else {
let is_object = o
.instance_of()

View File

@ -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);
}
}
}

View File

@ -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.

View File

@ -0,0 +1 @@
num_frames = 1