So, these classes like Integer and langBoolean exist solely for
streaming to our java server, so let's just make them streamable directly. Does away with the need for custom Streamers. Also made them Hashable, in case we read a StreamableHashMap containing Integers as keys, for example. Less code is better code. (Why was BooleanStreamer added the other day? langBoolean was already Streamable and was already in Translations) git-svn-id: svn+ssh://src.earth.threerings.net/narya/trunk@5960 542714f4-19e9-0310-aa3c-eee0fc999fb1
This commit is contained in:
@@ -29,14 +29,9 @@ import com.threerings.util.ClassUtil;
|
||||
import com.threerings.util.Enum;
|
||||
|
||||
import com.threerings.io.streamers.ArrayStreamer;
|
||||
import com.threerings.io.streamers.BooleanStreamer;
|
||||
import com.threerings.io.streamers.ByteStreamer;
|
||||
import com.threerings.io.streamers.ByteArrayStreamer;
|
||||
import com.threerings.io.streamers.ByteEnumStreamer;
|
||||
import com.threerings.io.streamers.EnumStreamer;
|
||||
import com.threerings.io.streamers.FloatStreamer;
|
||||
import com.threerings.io.streamers.IntegerStreamer;
|
||||
import com.threerings.io.streamers.LongStreamer;
|
||||
import com.threerings.io.streamers.NumberStreamer;
|
||||
import com.threerings.io.streamers.StringStreamer;
|
||||
|
||||
@@ -147,8 +142,7 @@ public class Streamer
|
||||
}
|
||||
_byJName = new Dictionary();
|
||||
for each (var c :Class in
|
||||
[ StringStreamer, NumberStreamer, ByteStreamer, IntegerStreamer, LongStreamer,
|
||||
FloatStreamer, ArrayStreamer, ByteArrayStreamer, BooleanStreamer ]) {
|
||||
[ StringStreamer, NumberStreamer, ArrayStreamer, ByteArrayStreamer ]) {
|
||||
registerStreamer(Streamer(new c()));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -56,12 +56,13 @@ public class Translations
|
||||
// initialize some standard classes
|
||||
addTranslation("Object", "java.lang.Object");
|
||||
addTranslation("String", "java.lang.String");
|
||||
addTranslation("Array", "[Ljava.lang.Object;");
|
||||
addTranslation("flash.utils.ByteArray", "[B");
|
||||
addTranslation("com.threerings.util.langBoolean", "java.lang.Boolean");
|
||||
addTranslation("com.threerings.util.Byte", "java.lang.Byte");
|
||||
addTranslation("com.threerings.util.Short", "java.lang.Short");
|
||||
addTranslation("com.threerings.util.Integer", "java.lang.Integer");
|
||||
addTranslation("com.threerings.util.Long", "java.lang.Long");
|
||||
addTranslation("com.threerings.util.Float", "java.lang.Float");
|
||||
addTranslation("Array", "[Ljava.lang.Object;");
|
||||
addTranslation("flash.utils.ByteArray", "[B");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,55 +0,0 @@
|
||||
//
|
||||
// $Id$
|
||||
//
|
||||
// Narya library - tools for developing networked games
|
||||
// Copyright (C) 2002-2009 Three Rings Design, Inc., All Rights Reserved
|
||||
// http://www.threerings.net/code/narya/
|
||||
//
|
||||
// This library is free software; you can redistribute it and/or modify it
|
||||
// under the terms of the GNU Lesser General Public License as published
|
||||
// by the Free Software Foundation; either version 2.1 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// This library is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
// Lesser General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU Lesser General Public
|
||||
// License along with this library; if not, write to the Free Software
|
||||
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
|
||||
package com.threerings.io.streamers {
|
||||
|
||||
import com.threerings.util.langBoolean;
|
||||
|
||||
import com.threerings.io.ObjectInputStream;
|
||||
import com.threerings.io.ObjectOutputStream;
|
||||
import com.threerings.io.Streamer;
|
||||
|
||||
/**
|
||||
* A Streamer for Integer objects.
|
||||
*/
|
||||
public class BooleanStreamer extends Streamer
|
||||
{
|
||||
public function BooleanStreamer ()
|
||||
{
|
||||
super(langBoolean, "java.lang.Boolean");
|
||||
}
|
||||
|
||||
override public function createObject (ins :ObjectInputStream) :Object
|
||||
{
|
||||
return new langBoolean(ins.readBoolean());
|
||||
}
|
||||
|
||||
override public function writeObject (obj :Object, out :ObjectOutputStream) :void
|
||||
{
|
||||
out.writeBoolean((obj as langBoolean).value);
|
||||
}
|
||||
|
||||
override public function readObject (obj :Object, ins :ObjectInputStream) :void
|
||||
{
|
||||
// unneeded, done in createObject
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,56 +0,0 @@
|
||||
//
|
||||
// $Id$
|
||||
//
|
||||
// Narya library - tools for developing networked games
|
||||
// Copyright (C) 2002-2009 Three Rings Design, Inc., All Rights Reserved
|
||||
// http://www.threerings.net/code/narya/
|
||||
//
|
||||
// This library is free software; you can redistribute it and/or modify it
|
||||
// under the terms of the GNU Lesser General Public License as published
|
||||
// by the Free Software Foundation; either version 2.1 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// This library is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
// Lesser General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU Lesser General Public
|
||||
// License along with this library; if not, write to the Free Software
|
||||
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
|
||||
package com.threerings.io.streamers {
|
||||
|
||||
import com.threerings.util.Byte;
|
||||
|
||||
import com.threerings.io.ObjectInputStream;
|
||||
import com.threerings.io.ObjectOutputStream;
|
||||
import com.threerings.io.Streamer;
|
||||
|
||||
/**
|
||||
* A Streamer for Byte objects.
|
||||
*/
|
||||
public class ByteStreamer extends Streamer
|
||||
{
|
||||
public function ByteStreamer ()
|
||||
{
|
||||
super(Byte, "java.lang.Byte");
|
||||
}
|
||||
|
||||
override public function createObject (ins :ObjectInputStream) :Object
|
||||
{
|
||||
return new Byte(ins.readByte());
|
||||
}
|
||||
|
||||
override public function writeObject (obj :Object, out :ObjectOutputStream) :void
|
||||
{
|
||||
var byte :Byte = (obj as Byte);
|
||||
out.writeByte(byte.value);
|
||||
}
|
||||
|
||||
override public function readObject (obj :Object, ins :ObjectInputStream) :void
|
||||
{
|
||||
// unneeded, done in createObject
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,56 +0,0 @@
|
||||
//
|
||||
// $Id$
|
||||
//
|
||||
// Narya library - tools for developing networked games
|
||||
// Copyright (C) 2002-2009 Three Rings Design, Inc., All Rights Reserved
|
||||
// http://www.threerings.net/code/narya/
|
||||
//
|
||||
// This library is free software; you can redistribute it and/or modify it
|
||||
// under the terms of the GNU Lesser General Public License as published
|
||||
// by the Free Software Foundation; either version 2.1 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// This library is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
// Lesser General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU Lesser General Public
|
||||
// License along with this library; if not, write to the Free Software
|
||||
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
|
||||
package com.threerings.io.streamers {
|
||||
|
||||
import com.threerings.util.Float;
|
||||
|
||||
import com.threerings.io.ObjectInputStream;
|
||||
import com.threerings.io.ObjectOutputStream;
|
||||
import com.threerings.io.Streamer;
|
||||
|
||||
/**
|
||||
* A Streamer for Float objects.
|
||||
*/
|
||||
public class FloatStreamer extends Streamer
|
||||
{
|
||||
public function FloatStreamer ()
|
||||
{
|
||||
super(Float, "java.lang.Float");
|
||||
}
|
||||
|
||||
override public function createObject (ins :ObjectInputStream) :Object
|
||||
{
|
||||
return new Float(ins.readFloat());
|
||||
}
|
||||
|
||||
override public function writeObject (obj :Object, out :ObjectOutputStream) :void
|
||||
{
|
||||
var float :Float = (obj as Float);
|
||||
out.writeFloat(float.value);
|
||||
}
|
||||
|
||||
override public function readObject (obj :Object, ins :ObjectInputStream) :void
|
||||
{
|
||||
// unneeded, done in createObject
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,56 +0,0 @@
|
||||
//
|
||||
// $Id$
|
||||
//
|
||||
// Narya library - tools for developing networked games
|
||||
// Copyright (C) 2002-2009 Three Rings Design, Inc., All Rights Reserved
|
||||
// http://www.threerings.net/code/narya/
|
||||
//
|
||||
// This library is free software; you can redistribute it and/or modify it
|
||||
// under the terms of the GNU Lesser General Public License as published
|
||||
// by the Free Software Foundation; either version 2.1 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// This library is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
// Lesser General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU Lesser General Public
|
||||
// License along with this library; if not, write to the Free Software
|
||||
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
|
||||
package com.threerings.io.streamers {
|
||||
|
||||
import com.threerings.util.Integer;
|
||||
|
||||
import com.threerings.io.ObjectInputStream;
|
||||
import com.threerings.io.ObjectOutputStream;
|
||||
import com.threerings.io.Streamer;
|
||||
|
||||
/**
|
||||
* A Streamer for Integer objects.
|
||||
*/
|
||||
public class IntegerStreamer extends Streamer
|
||||
{
|
||||
public function IntegerStreamer ()
|
||||
{
|
||||
super(Integer, "java.lang.Integer");
|
||||
}
|
||||
|
||||
override public function createObject (ins :ObjectInputStream) :Object
|
||||
{
|
||||
return new Integer(ins.readInt());
|
||||
}
|
||||
|
||||
override public function writeObject (obj :Object, out :ObjectOutputStream) :void
|
||||
{
|
||||
var inty :Integer = (obj as Integer);
|
||||
out.writeInt(inty.value);
|
||||
}
|
||||
|
||||
override public function readObject (obj :Object, ins :ObjectInputStream) :void
|
||||
{
|
||||
// unneeded, done in createObject
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,52 +0,0 @@
|
||||
//
|
||||
// $Id$
|
||||
//
|
||||
// Narya library - tools for developing networked games
|
||||
// Copyright (C) 2002-2009 Three Rings Design, Inc., All Rights Reserved
|
||||
// http://www.threerings.net/code/narya/
|
||||
//
|
||||
// This library is free software; you can redistribute it and/or modify it
|
||||
// under the terms of the GNU Lesser General Public License as published
|
||||
// by the Free Software Foundation; either version 2.1 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// This library is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
// Lesser General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU Lesser General Public
|
||||
// License along with this library; if not, write to the Free Software
|
||||
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
|
||||
package com.threerings.io.streamers {
|
||||
|
||||
import com.threerings.util.Long;
|
||||
|
||||
import com.threerings.io.ObjectInputStream;
|
||||
import com.threerings.io.ObjectOutputStream;
|
||||
import com.threerings.io.Streamer;
|
||||
|
||||
/**
|
||||
* A Streamer for Long objects.
|
||||
*/
|
||||
public class LongStreamer extends Streamer
|
||||
{
|
||||
public function LongStreamer ()
|
||||
{
|
||||
super(Long, "java.lang.Long");
|
||||
}
|
||||
|
||||
override public function writeObject (obj :Object, out :ObjectOutputStream) :void
|
||||
{
|
||||
var longy :Long = (obj as Long);
|
||||
out.writeBytes(longy.bytes, 0, longy.bytes.length);
|
||||
}
|
||||
|
||||
override public function readObject (obj :Object, ins :ObjectInputStream) :void
|
||||
{
|
||||
var longy :Long = (obj as Long);
|
||||
ins.readBytes(longy.bytes, 0, longy.bytes.length);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,56 +0,0 @@
|
||||
//
|
||||
// $Id$
|
||||
//
|
||||
// Narya library - tools for developing networked games
|
||||
// Copyright (C) 2002-2009 Three Rings Design, Inc., All Rights Reserved
|
||||
// http://www.threerings.net/code/narya/
|
||||
//
|
||||
// This library is free software; you can redistribute it and/or modify it
|
||||
// under the terms of the GNU Lesser General Public License as published
|
||||
// by the Free Software Foundation; either version 2.1 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// This library is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
// Lesser General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU Lesser General Public
|
||||
// License along with this library; if not, write to the Free Software
|
||||
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
|
||||
package com.threerings.io.streamers {
|
||||
|
||||
import com.threerings.util.Short;
|
||||
|
||||
import com.threerings.io.ObjectInputStream;
|
||||
import com.threerings.io.ObjectOutputStream;
|
||||
import com.threerings.io.Streamer;
|
||||
|
||||
/**
|
||||
* A Streamer for Short objects.
|
||||
*/
|
||||
public class ShortStreamer extends Streamer
|
||||
{
|
||||
public function ShortStreamer ()
|
||||
{
|
||||
super(Short, "java.lang.Short");
|
||||
}
|
||||
|
||||
override public function createObject (ins :ObjectInputStream) :Object
|
||||
{
|
||||
return new Short(ins.readShort());
|
||||
}
|
||||
|
||||
override public function writeObject (obj :Object, out :ObjectOutputStream) :void
|
||||
{
|
||||
var short :Short = (obj as Short);
|
||||
out.writeShort(short.value);
|
||||
}
|
||||
|
||||
override public function readObject (obj :Object, ins :ObjectInputStream) :void
|
||||
{
|
||||
// unneeded, done in createObject
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user