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:
@@ -34,7 +34,7 @@ import com.threerings.util.Long;
|
||||
public class ObjectInputStream
|
||||
{
|
||||
/** Enables verbose object I/O debugging. */
|
||||
public static const DEBUG :Boolean = false;
|
||||
public static const DEBUG :Boolean = true;
|
||||
|
||||
public function ObjectInputStream (source :IDataInput = null, clientProps :Object = null)
|
||||
{
|
||||
@@ -172,7 +172,8 @@ public class ObjectInputStream
|
||||
* Called to read an Object of a known final type into a Streamable object.
|
||||
*
|
||||
* @param type either a String representing the java type,
|
||||
* or a Class object representing the actionscript type.
|
||||
* a Class representing the actionscript type,
|
||||
* or the Streamer to be used to read the field.
|
||||
*/
|
||||
public function readField (type :Object) :*
|
||||
//throws IOError
|
||||
@@ -181,13 +182,18 @@ public class ObjectInputStream
|
||||
return null;
|
||||
}
|
||||
|
||||
var jname :String = type as String;
|
||||
if (type is Class) {
|
||||
jname = Translations.getToServer(ClassUtil.getClassName(type));
|
||||
}
|
||||
var streamer :Streamer = Streamer.getStreamerByJavaName(jname);
|
||||
if (streamer == null) {
|
||||
throw new Error("Cannot field stream " + type);
|
||||
var streamer :Streamer;
|
||||
if (type is Streamer) {
|
||||
streamer = Streamer(type);
|
||||
} else {
|
||||
var jname :String = type as String;
|
||||
if (type is Class) {
|
||||
jname = Translations.getToServer(ClassUtil.getClassName(type));
|
||||
}
|
||||
streamer= Streamer.getStreamerByJavaName(jname);
|
||||
if (streamer == null) {
|
||||
throw new Error("Cannot field stream " + type);
|
||||
}
|
||||
}
|
||||
|
||||
var obj :Object = streamer.createObject(this);
|
||||
|
||||
@@ -86,10 +86,13 @@ public class ObjectOutputStream
|
||||
writeBareObjectImpl(obj, cmap.streamer);
|
||||
}
|
||||
|
||||
public function writeBareObject (obj :Object) :void
|
||||
public function writeBareObject (obj :Object, streamer :Streamer = null) :void
|
||||
//throws IOError
|
||||
{
|
||||
writeBareObjectImpl(obj, Streamer.getStreamer(obj));
|
||||
if (streamer == null) {
|
||||
streamer = Streamer.getStreamer(obj);
|
||||
}
|
||||
writeBareObjectImpl(obj, streamer);
|
||||
}
|
||||
|
||||
public function writeBareObjectImpl (obj :Object, streamer :Streamer) :void
|
||||
@@ -125,13 +128,13 @@ public class ObjectOutputStream
|
||||
* }
|
||||
* </listing>
|
||||
*/
|
||||
public function writeField (val :Object) :void
|
||||
public function writeField (val :Object, streamer :Streamer = null) :void
|
||||
//throws IOError
|
||||
{
|
||||
var b :Boolean = (val != null);
|
||||
writeBoolean(b);
|
||||
if (b) {
|
||||
writeBareObject(val);
|
||||
writeBareObject(val, streamer);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -217,7 +220,7 @@ public class ObjectOutputStream
|
||||
|
||||
/** The target DataOutput that we route things to. */
|
||||
protected var _targ :IDataOutput;
|
||||
|
||||
|
||||
/** A counter used to assign codes to streamed classes. */
|
||||
protected var _nextCode :int = 1;
|
||||
|
||||
|
||||
@@ -102,6 +102,7 @@ public class AuthRequest extends UpstreamMessage
|
||||
// if we fail here because the client is old, leave ourselves with a partially
|
||||
// initialized set of credentials, which the server will generally cope with by telling
|
||||
// the client it is out of date
|
||||
ioe.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -53,7 +53,7 @@ public class ClientResolver extends Invoker.Unit
|
||||
}
|
||||
|
||||
/**
|
||||
* Initiailizes this instance.
|
||||
* Initializes this instance.
|
||||
*
|
||||
* @param username the username of the user to be resolved.
|
||||
*/
|
||||
|
||||
@@ -95,6 +95,11 @@ public class GenActionScriptStreamableTask extends GenActionScriptTask
|
||||
{
|
||||
this.name = f.getName();
|
||||
this.simpleType = addImportAndGetShortType(f.getType(), true, imports);
|
||||
|
||||
// Reading and writing Lists uses ArrayStreamer.INSTANCE directly
|
||||
if (List.class.isAssignableFrom(f.getType())) {
|
||||
imports.add("com.threerings.io.streamers.ArrayStreamer");
|
||||
}
|
||||
this.reader = toReadObject(f.getType());
|
||||
this.writer = toWriteObject(f.getType(), name);
|
||||
}
|
||||
|
||||
@@ -25,6 +25,7 @@ import java.lang.reflect.Field;
|
||||
import java.lang.reflect.Modifier;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
import java.io.BufferedWriter;
|
||||
@@ -247,7 +248,7 @@ public class GenActionScriptTask extends GenTask
|
||||
if (needsActionScriptImport(type, isField)) {
|
||||
imports.add(full);
|
||||
}
|
||||
return getSimpleType(full);
|
||||
return Iterables.getLast(DOT_SPLITTER.split(full));
|
||||
}
|
||||
|
||||
protected static boolean needsActionScriptImport (Class<?> type, boolean isField)
|
||||
@@ -260,7 +261,7 @@ public class GenActionScriptTask extends GenTask
|
||||
|
||||
protected static String toActionScriptType (Class<?> type, boolean isField)
|
||||
{
|
||||
if (type.isArray()) {
|
||||
if (type.isArray() || List.class.isAssignableFrom(type)) {
|
||||
if (Byte.TYPE.equals(type.getComponentType())) {
|
||||
return "flash.utils.ByteArray";
|
||||
}
|
||||
@@ -290,6 +291,7 @@ public class GenActionScriptTask extends GenTask
|
||||
return "Boolean";
|
||||
}
|
||||
|
||||
// inner classes are not supported by ActionScript so we _
|
||||
return type.getName().replaceAll("\\$", "_");
|
||||
}
|
||||
|
||||
@@ -329,6 +331,9 @@ public class GenActionScriptTask extends GenTask
|
||||
} else if (type.equals(Double.TYPE)) {
|
||||
return "readDouble()";
|
||||
|
||||
} else if (List.class.isAssignableFrom(type)) {
|
||||
return "readField(ArrayStreamer.INSTANCE)";
|
||||
|
||||
} else if (type.isArray()) {
|
||||
if (!type.getComponentType().isPrimitive()) {
|
||||
return "readObject(TypedArray)";
|
||||
@@ -347,30 +352,23 @@ public class GenActionScriptTask extends GenTask
|
||||
}
|
||||
}
|
||||
} else {
|
||||
return "readObject(" + ActionScriptSource.toSimpleName(type.getName()) + ")";
|
||||
return "readObject(" + Iterables.getLast(DOT_SPLITTER.split(toActionScriptType(type, false))) + ")";
|
||||
}
|
||||
}
|
||||
|
||||
public static String getSimpleType(String fullType)
|
||||
{
|
||||
return Iterables.getLast(DOT_SPLITTER.split(fullType));
|
||||
}
|
||||
|
||||
public static String toWriteObject (Class<?> type, String name)
|
||||
{
|
||||
if (type.equals(Integer.class)) {
|
||||
return "writeObject(new Integer(" + name + "))";
|
||||
|
||||
} else if (type.equals(Long.class)) {
|
||||
return "writeField(" + name + ")";
|
||||
|
||||
} else if (type.equals(Boolean.TYPE)) {
|
||||
return "writeBoolean(" + name + ")";
|
||||
|
||||
} else if (type.equals(Byte.TYPE)) {
|
||||
return "writeByte(" + name + ")";
|
||||
|
||||
} else if (type.equals(Short.TYPE) || type.equals(Character.TYPE)) {
|
||||
} else if (type.equals(Short.TYPE) ||
|
||||
type.equals(Character.TYPE)) {
|
||||
return "writeShort(" + name + ")";
|
||||
|
||||
} else if (type.equals(Integer.TYPE)) {
|
||||
@@ -385,10 +383,14 @@ public class GenActionScriptTask extends GenTask
|
||||
} else if (type.equals(Double.TYPE)) {
|
||||
return "writeDouble(" + name + ")";
|
||||
|
||||
} else if (type.equals(String.class) ||
|
||||
} else if (type.equals(Long.class) ||
|
||||
type.equals(String.class) ||
|
||||
(type.isArray() && type.getComponentType().isPrimitive())) {
|
||||
return "writeField(" + name + ")";
|
||||
|
||||
} else if (List.class.isAssignableFrom(type)) {
|
||||
return "writeField(" + name + ", ArrayStreamer.INSTANCE)";
|
||||
|
||||
} else {
|
||||
return "writeObject(" + name + ")";
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user