From 079269a82512d192eb3911dc86baf2dd170f7bc1 Mon Sep 17 00:00:00 2001 From: Mike Thomas Date: Tue, 8 Jun 2010 01:37:08 +0000 Subject: [PATCH] Handle short[]'s on the actionscript side of streaming. This gets a little ugly given the lack of a primitive short on the actionscript side... git-svn-id: svn+ssh://src.earth.threerings.net/narya/trunk@6071 542714f4-19e9-0310-aa3c-eee0fc999fb1 --- src/as/com/threerings/io/TypedArray.as | 18 ++++++++++++++++++ .../threerings/io/streamers/ArrayStreamer.as | 19 ++++++++++++++++++- 2 files changed, 36 insertions(+), 1 deletion(-) diff --git a/src/as/com/threerings/io/TypedArray.as b/src/as/com/threerings/io/TypedArray.as index 8cd6ee45a..4f65c54c5 100644 --- a/src/as/com/threerings/io/TypedArray.as +++ b/src/as/com/threerings/io/TypedArray.as @@ -52,6 +52,12 @@ public dynamic class TypedArray extends Array return "[L" + cname + ";"; } + /** Because we have no actionscript type to check, we'll just handle this one manually. */ + public static function getJavaShortType () :String + { + return "[S"; + } + /** * A factory method to create a TypedArray for holding objects of the specified type. */ @@ -64,6 +70,18 @@ public dynamic class TypedArray extends Array return ta; } + /** + * A factory method to create a TypedArray for holding data meant as java shorts. + */ + public static function createShort (initialValues :Array = null) :TypedArray + { + var ta :TypedArray = new TypedArray(getJavaShortType()); + if (initialValues != null) { + ta.addAll(initialValues); + } + return ta; + } + /** * Create a TypedArray * diff --git a/src/as/com/threerings/io/streamers/ArrayStreamer.as b/src/as/com/threerings/io/streamers/ArrayStreamer.as index cbe003df9..5f4f5d1fe 100644 --- a/src/as/com/threerings/io/streamers/ArrayStreamer.as +++ b/src/as/com/threerings/io/streamers/ArrayStreamer.as @@ -65,6 +65,9 @@ public class ArrayStreamer extends Streamer } else if (secondChar === "Z") { _elementType = Boolean; + } else if (secondChar === "S") { + _elementType = PrimitiveShort; + } else { Log.getLog(this).warning("Other array types are not yet handled", "jname", jname); throw new Error("Don't know how to stream '" + jname + "' instances."); @@ -87,7 +90,11 @@ public class ArrayStreamer extends Streamer for (ii = 0; ii < arr.length; ii++) { out.writeInt(int(arr[ii])); } - + } else if (_elementType == PrimitiveShort) { + for (ii = 0; ii < arr.length; ii++) { + out.writeShort(int(arr[ii])); + } + } else if (_elementType == Boolean) { for (ii = 0; ii < arr.length; ii++) { out.writeBoolean(Boolean(arr[ii])); @@ -125,6 +132,11 @@ public class ArrayStreamer extends Streamer arr[ii] = ins.readInt(); } + } else if (_elementType == PrimitiveShort) { + for (ii = 0; ii < arr.length; ii++) { + arr[ii] = ins.readShort(); + } + } else if (_elementType == Boolean) { for (ii = 0; ii < arr.length; ii++) { arr[ii] = ins.readBoolean(); @@ -182,3 +194,8 @@ public class ArrayStreamer extends Streamer protected var _isFinal :Boolean; } } + +/** A class to represent that the data in question should be handled as a java primitive short. */ +class PrimitiveShort +{ +}