Make writing List fields on Streamables possible from ActionScript again, and fix List reading and

writing in the code generated by GenActionScriptStreamableTask.



git-svn-id: svn+ssh://src.earth.threerings.net/narya/trunk@6199 542714f4-19e9-0310-aa3c-eee0fc999fb1
This commit is contained in:
Charlie Groves
2010-10-15 07:53:38 +00:00
parent 377fafae1e
commit aad715138c
10 changed files with 87 additions and 37 deletions
@@ -29,6 +29,7 @@ import com.threerings.io.SimpleStreamableObject;
import com.threerings.util.Long;
import com.threerings.io.TypedArray;
import flash.utils.ByteArray;
import com.threerings.io.streamers.ArrayStreamer;
// GENERATED PREAMBLE END
import com.threerings.util.Util;
@@ -64,6 +65,7 @@ public class ASStreamableSubset extends SimpleStreamableObject
bytes.writeByte(2);
bytes.writeByte(3);
ints = TypedArray.create(int, [1, 2, 3]);
strings = TypedArray.create(String, ["one", "two", "three"]);
}
public function equals (o :ASStreamableSubset) :Boolean
@@ -73,7 +75,8 @@ public class ASStreamableSubset extends SimpleStreamableObject
byte8 === o.byte8 && string1 === o.string1 && nullString1 === o.nullString1 &&
Util.equals(bools, o.bools) && Util.equals(bytes, o.bytes) &&
Util.equals(ints, o.ints) && Util.equals(nullBools, o.nullBools) &&
Util.equals(nullBytes, o.nullBytes) && Util.equals(nullInts, o.nullInts);
Util.equals(nullBytes, o.nullBytes) && Util.equals(nullInts, o.nullInts) &&
Util.equals(strings, o.strings) && Util.equals(nullStrings, o.nullStrings);
}
@@ -94,6 +97,8 @@ public class ASStreamableSubset extends SimpleStreamableObject
public var nullBools :TypedArray;
public var nullBytes :ByteArray;
public var nullInts :TypedArray;
public var strings :TypedArray;
public var nullStrings :TypedArray;
override public function readObject (ins :ObjectInputStream) :void
{
@@ -114,8 +119,10 @@ public class ASStreamableSubset extends SimpleStreamableObject
nullBools = ins.readField(TypedArray.getJavaType(Boolean));
nullBytes = ins.readField(ByteArray);
nullInts = ins.readField(TypedArray.getJavaType(int));
strings = ins.readField(ArrayStreamer.INSTANCE);
nullStrings = ins.readField(ArrayStreamer.INSTANCE);
}
override public function writeObject (out :ObjectOutputStream) :void
{
super.writeObject(out);
@@ -135,6 +142,8 @@ public class ASStreamableSubset extends SimpleStreamableObject
out.writeField(nullBools);
out.writeField(nullBytes);
out.writeField(nullInts);
out.writeField(strings, ArrayStreamer.INSTANCE);
out.writeField(nullStrings, ArrayStreamer.INSTANCE);
}
// GENERATED STREAMING END
@@ -31,6 +31,11 @@ import asunit.framework.TestCase;
public class StreamableTest extends TestCase
{
public function StreamableTest (name:String = null)
{
super(name);
}
public function testStreamingToSelf ():void
{
var sub:ASStreamableSubset = ASStreamableSubset.createWithJavaDefaults();
@@ -49,7 +54,8 @@ public class StreamableTest extends TestCase
var javaData:ByteArray = StringUtil.unhexlate(
"ffff0024636f6d2e746872656572696e67732e696f2e415353747265616d61626c65537562736574" +
"01000200000003000000000000000440a0000040180000000000000007080100036f6e6500010000" +
"000301000101000000030102030100000003000000010000000200000003000000");
"0003010001010000000301020301000000030000000100000002000000030000000100000003fffe" +
"00106a6176612e6c616e672e537472696e6700036f6e650002000374776f00020005746872656500");
var input:ObjectInputStream = new ObjectInputStream(javaData);
var read :ASStreamableSubset = input.readObject(ASStreamableSubset);
assertTrue(sub.equals(read));
@@ -22,8 +22,10 @@ package com.threerings.io;
//Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
import java.util.Arrays;
import java.util.List;
import com.google.common.base.Objects;
import com.google.common.collect.Lists;
public class ASStreamableSubset extends SimpleStreamableObject
{
@@ -47,6 +49,9 @@ public class ASStreamableSubset extends SimpleStreamableObject
public byte[] nullBytes;
public int[] nullInts;
public List<String> strings = Lists.newArrayList("one", "two", "three");
public List<String> nullStrings;
@Override
public boolean equals (Object other)
{
@@ -67,6 +72,10 @@ public class ASStreamableSubset extends SimpleStreamableObject
Arrays.equals(bools, ow.bools) && Arrays.equals(bytes, ow.bytes)
&& Arrays.equals(ints, ow.ints) &&
Arrays.equals(nullBools, ow.nullBools) && Arrays.equals(nullBytes, ow.nullBytes);
Arrays.equals(nullBools, ow.nullBools) && Arrays.equals(nullBytes, ow.nullBytes)
&& Arrays.equals(nullInts, ow.nullInts)
&&
Objects.equal(strings, ow.strings) && Objects.equal(nullStrings, ow.nullStrings);
}
}
@@ -345,11 +345,8 @@ public class StreamableTest
oout.writeObject(w);
byte[] data = bout.toByteArray();
// uncomment this and rerun the tests to generate an updated WIRE_DATA blob:
// String dstr = StringUtil.wordWrap(StringUtil.hexlate(data), 80);
// dstr = StringUtil.join(dstr.split("\n"), "\" +\n \"");
// System.out.println(" protected static final byte[] WIRE_DATA = " +
// "StringUtil.unhexlate(\n \"" + dstr + "\");");
// uncomment this and rerun the tests to generate an updated WIRE_DATA blob
// printWireData(w);
// oddly, JUnit doesn't like comparing byte arrays directly (this fails:
// assertEquals(WIRE_DATA, WIRE_DATA.clone())), but comparing strings is fine
@@ -360,6 +357,18 @@ public class StreamableTest
assertEquals(w, oin.readObject());
}
protected void printWireData (Object o)
throws IOException
{
ByteArrayOutputStream bout = new ByteArrayOutputStream();
ObjectOutputStream oout = new ObjectOutputStream(bout);
oout.writeObject(o);
String dstr = StringUtil.wordWrap(StringUtil.hexlate(bout.toByteArray()), 80);
dstr = StringUtil.join(dstr.split("\n"), "\" +\n \"");
System.out.println(" protected static final byte[] WIRE_DATA = "
+ "StringUtil.unhexlate(\n \"" + dstr + "\");");
}
@Test
public void testPostStreamingMutation ()
throws IOException, ClassNotFoundException