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 +{ +}