Add support for ActionScript Set streaming

git-svn-id: svn+ssh://src.earth.threerings.net/narya/trunk@6323 542714f4-19e9-0310-aa3c-eee0fc999fb1
This commit is contained in:
Tom Conkling
2010-12-01 03:00:52 +00:00
parent eb9e0db930
commit be72e5cdad
2 changed files with 16 additions and 0 deletions
@@ -33,6 +33,7 @@ import com.google.common.collect.Iterables;
import com.threerings.util.ActionScript;
import com.threerings.util.StreamableArrayList;
import com.threerings.util.StreamableHashMap;
import com.threerings.util.StreamableHashSet;
public class ActionScriptUtils
{
@@ -96,6 +97,9 @@ public class ActionScriptUtils
} else if (isNaiveList(type)) {
return "readField(ArrayStreamer.INSTANCE)";
} else if (isNaiveSet(type)) {
return "readField(SetStreamer.INSTANCE)";
} else if (type.isArray()) {
if (!type.getComponentType().isPrimitive()) {
return "readObject(TypedArray)";
@@ -156,6 +160,9 @@ public class ActionScriptUtils
} else if (isNaiveMap(type)) {
return "writeField(" + name + ", MapStreamer.INSTANCE)";
} else if (isNaiveSet(type)) {
return "writeField(" + name + ", SetStreamer.INSTANCE)";
} else {
return "writeObject(" + name + ")";
}
@@ -167,6 +174,11 @@ public class ActionScriptUtils
return Map.class.isAssignableFrom(type) && !type.equals(StreamableHashMap.class);
}
protected static boolean isNaiveSet (Class<?> type)
{
return Set.class.isAssignableFrom(type) && !type.equals(StreamableHashSet.class);
}
/** Returns if the given class is an implementation of List that doesn't know about Streaming */
protected static boolean isNaiveList (Class<?> type)
{
@@ -185,6 +197,8 @@ public class ActionScriptUtils
return "Array";
} else if (isNaiveMap(type)) {
return "com.threerings.util.Map";
} else if (isNaiveSet(type)) {
return "com.threerings.util.Set";
} else if (Integer.TYPE.equals(type) ||
Byte.TYPE.equals(type) ||
Short.TYPE.equals(type) ||
@@ -133,6 +133,8 @@ public class GenActionScriptStreamableTask extends GenTask
imports.add("com.threerings.io.streamers.ArrayStreamer");
} else if (Map.class.isAssignableFrom(f.getType())) {
imports.add("com.threerings.io.streamers.MapStreamer");
} else if (Set.class.isAssignableFrom(f.getType())) {
imports.add("com.threerings.io.streamers.SetStreamer");
}
reader = ActionScriptUtils.toReadObject(f.getType());
writer = ActionScriptUtils.toWriteObject(f.getType(), name);