At Ray's suggestion, go ahead and throw an error when the wrong type is read. Use the Type(obj) cast syntax (I was unaware that this would actually throw an error). Reading objects of a basic type like Array must still use "readObject(Array) as Array" so this is still supported, though not needed for user types.
git-svn-id: svn+ssh://src.earth.threerings.net/narya/trunk@5441 542714f4-19e9-0310-aa3c-eee0fc999fb1
This commit is contained in:
@@ -78,7 +78,7 @@ public class UserMessage extends ChatMessage
|
||||
override public function readObject (ins :ObjectInputStream) :void
|
||||
{
|
||||
super.readObject(ins);
|
||||
speaker = (ins.readObject(Name) as Name);
|
||||
speaker = Name(ins.readObject());
|
||||
mode = ins.readByte();
|
||||
}
|
||||
|
||||
|
||||
@@ -51,7 +51,7 @@ public class UserSystemMessage extends SystemMessage
|
||||
override public function readObject (ins :ObjectInputStream) :void
|
||||
{
|
||||
super.readObject(ins);
|
||||
speaker = (ins.readObject(Name) as Name);
|
||||
speaker = Name(ins.readObject());
|
||||
}
|
||||
|
||||
// from interface Streamable
|
||||
|
||||
@@ -180,7 +180,7 @@ public class BodyObject extends ClientObject
|
||||
override public function readObject (ins :ObjectInputStream) :void
|
||||
{
|
||||
super.readObject(ins);
|
||||
location = (ins.readObject(Place) as Place);
|
||||
location = Place(ins.readObject());
|
||||
status = ins.readByte();
|
||||
awayMessage = (ins.readField(String) as String);
|
||||
}
|
||||
|
||||
@@ -118,7 +118,7 @@ public class OccupantInfo extends SimpleStreamableObject
|
||||
{
|
||||
super.readObject(ins);
|
||||
bodyOid = (ins.readField(Integer) as Integer).value;
|
||||
username = (ins.readObject(Name) as Name);
|
||||
username = Name(ins.readObject());
|
||||
status = ins.readByte();
|
||||
}
|
||||
|
||||
|
||||
@@ -206,9 +206,9 @@ public class PlaceObject extends DObject
|
||||
override public function readObject (ins :ObjectInputStream) :void
|
||||
{
|
||||
super.readObject(ins);
|
||||
occupants = (ins.readObject(OidList) as OidList);
|
||||
occupantInfo = (ins.readObject(DSet) as DSet);
|
||||
speakService = (ins.readObject(SpeakMarshaller) as SpeakMarshaller);
|
||||
occupants = OidList(ins.readObject());
|
||||
occupantInfo = DSet(ins.readObject());
|
||||
speakService = SpeakMarshaller(ins.readObject());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -51,7 +51,7 @@ public class CrowdClientInfo extends ClientInfo
|
||||
override public function readObject (ins :ObjectInputStream) :void
|
||||
{
|
||||
super.readObject(ins);
|
||||
visibleName = (ins.readObject(Name) as Name);
|
||||
visibleName = Name(ins.readObject());
|
||||
}
|
||||
|
||||
// from interface Streamable
|
||||
|
||||
@@ -56,10 +56,10 @@ public class ObjectInputStream
|
||||
|
||||
/**
|
||||
* Attempts to read the next object from the stream. If a type is passed and the read object's
|
||||
* type doesn't match, a warning is printed and null returned. The method does not throw,
|
||||
* presumably to allow the client to hobble along until second order symptoms are observed.
|
||||
* type doesn't match, a <code>TypeError</code> is thrown.
|
||||
* @param type optional type to check the read object against
|
||||
* @return null if the object could not be read or is of the wrong type
|
||||
* @throws TypeError if the object is read successfully but is the wrong type
|
||||
* @return null if the object could not be read (or is actually null)
|
||||
*/
|
||||
public function readObject (type :Class = null) :Object
|
||||
//throws IOError
|
||||
@@ -115,8 +115,8 @@ public class ObjectInputStream
|
||||
readBareObjectImpl(target, cmap.streamer);
|
||||
if (DEBUG) log.debug(DEBUG_ID + "Read object: " + target);
|
||||
if (type != null && !(target is type)) {
|
||||
log.warning("Type mismatch", "expected", type, "read", ClassUtil.getClass(target));
|
||||
return null;
|
||||
throw new TypeError(
|
||||
"Cannot convert " + ClassUtil.getClass(target) + " to " + type);
|
||||
}
|
||||
return target;
|
||||
|
||||
|
||||
@@ -108,9 +108,9 @@ public class ClientObject extends DObject
|
||||
override public function readObject (ins :ObjectInputStream) :void
|
||||
{
|
||||
super.readObject(ins);
|
||||
username = (ins.readObject(Name) as Name);
|
||||
receivers = (ins.readObject(DSet) as DSet);
|
||||
_permPolicy = (ins.readObject(PermissionPolicy) as PermissionPolicy);
|
||||
username = Name(ins.readObject());
|
||||
receivers = DSet(ins.readObject());
|
||||
_permPolicy = PermissionPolicy(ins.readObject());
|
||||
}
|
||||
|
||||
protected var _permPolicy :PermissionPolicy;
|
||||
|
||||
@@ -112,7 +112,7 @@ public class CompoundEvent extends DEvent
|
||||
override public function readObject (ins :ObjectInputStream) :void
|
||||
{
|
||||
super.readObject(ins);
|
||||
_events = (ins.readObject(StreamableArrayList) as StreamableArrayList);
|
||||
_events = StreamableArrayList(ins.readObject());
|
||||
}
|
||||
|
||||
/** A list of the events associated with this compound event. */
|
||||
|
||||
@@ -104,7 +104,7 @@ public class EntryAddedEvent extends NamedEvent
|
||||
override public function readObject (ins :ObjectInputStream) :void
|
||||
{
|
||||
super.readObject(ins);
|
||||
_entry = (ins.readObject(DSet_Entry) as DSet_Entry);
|
||||
_entry = DSet_Entry(ins.readObject());
|
||||
}
|
||||
|
||||
protected var _entry :DSet_Entry;
|
||||
|
||||
@@ -122,7 +122,7 @@ public class EntryUpdatedEvent extends NamedEvent
|
||||
override public function readObject (ins :ObjectInputStream) :void
|
||||
{
|
||||
super.readObject(ins);
|
||||
_entry = (ins.readObject(DSet_Entry) as DSet_Entry);
|
||||
_entry = DSet_Entry(ins.readObject());
|
||||
}
|
||||
|
||||
protected var _entry :DSet_Entry;
|
||||
|
||||
@@ -34,7 +34,7 @@ public class AuthResponse extends DownstreamMessage
|
||||
override public function readObject (ins :ObjectInputStream) :void
|
||||
{
|
||||
super.readObject(ins);
|
||||
_data = (ins.readObject(AuthResponseData) as AuthResponseData);
|
||||
_data = AuthResponseData(ins.readObject());
|
||||
}
|
||||
|
||||
protected var _data :AuthResponseData;
|
||||
|
||||
@@ -33,7 +33,7 @@ public class BootstrapNotification extends DownstreamMessage
|
||||
override public function readObject (ins :ObjectInputStream) :void
|
||||
{
|
||||
super.readObject(ins);
|
||||
_data = (ins.readObject(BootstrapData) as BootstrapData);
|
||||
_data = BootstrapData(ins.readObject());
|
||||
}
|
||||
|
||||
/** The data associated with this notification. */
|
||||
|
||||
@@ -57,7 +57,7 @@ public /* abstract */ class Credentials
|
||||
public function readObject (ins :ObjectInputStream) :void
|
||||
//throws IOError
|
||||
{
|
||||
_username = (ins.readObject(Name) as Name);
|
||||
_username = Name(ins.readObject());
|
||||
}
|
||||
|
||||
public function toString () :String
|
||||
|
||||
@@ -40,7 +40,7 @@ public class EventNotification extends DownstreamMessage
|
||||
override public function readObject (ins :ObjectInputStream) :void
|
||||
{
|
||||
super.readObject(ins);
|
||||
_event = (ins.readObject(DEvent) as DEvent);
|
||||
_event = DEvent(ins.readObject());
|
||||
}
|
||||
|
||||
/** The event which we are forwarding. */
|
||||
|
||||
@@ -40,7 +40,7 @@ public class ObjectResponse extends DownstreamMessage
|
||||
override public function readObject (ins :ObjectInputStream) :void
|
||||
{
|
||||
super.readObject(ins);
|
||||
_dobj = (ins.readObject(DObject) as DObject);
|
||||
_dobj = DObject(ins.readObject());
|
||||
}
|
||||
|
||||
/** The object which is associated with this response. */
|
||||
|
||||
@@ -53,7 +53,7 @@ public class ClientInfo extends SimpleStreamableObject
|
||||
override public function readObject (ins :ObjectInputStream) :void
|
||||
{
|
||||
super.readObject(ins);
|
||||
username = (ins.readObject(Name) as Name);
|
||||
username = Name(ins.readObject());
|
||||
}
|
||||
|
||||
// from interface Streamable
|
||||
|
||||
Reference in New Issue
Block a user