Basic support for datagram messaging. Hope I haven't fucked

anything up!


git-svn-id: svn+ssh://src.earth.threerings.net/narya/trunk@5090 542714f4-19e9-0310-aa3c-eee0fc999fb1
This commit is contained in:
Andrzej Kapolka
2008-05-13 21:12:39 +00:00
parent 02654017d0
commit 9bafa5e7c8
20 changed files with 1397 additions and 109 deletions
@@ -89,32 +89,66 @@ public class ObjectOutputStream extends DataOutputStream
log.info(hashCode() + ": Creating class mapping [code=" + _nextCode +
", class=" + sclass.getName() + "].");
}
cmap = new ClassMapping(_nextCode++, sclass, streamer);
cmap = createClassMapping(_nextCode++, sclass, streamer);
_classmap.put(sclass, cmap);
// make sure we didn't blow past our maximum class count
if (_nextCode <= 0) {
throw new RuntimeException("Too many unique classes written to ObjectOutputStream");
}
// writing a negative class code indicates that the class name will follow
writeShort(-cmap.code);
String cname = sclass.getName();
if (_translations != null) {
String tname = _translations.get(cname);
if (tname != null) {
cname = tname;
}
}
writeUTF(cname);
writeNewClassMapping(cmap);
} else {
writeShort(cmap.code);
writeExistingClassMapping(cmap);
}
writeBareObject(object, cmap.streamer, true);
}
/**
* Creates and returns a new class mapping.
*/
protected ClassMapping createClassMapping (short code, Class sclass, Streamer streamer)
{
return new ClassMapping(code, sclass, streamer);
}
/**
* Writes a new class mapping to the stream.
*/
protected void writeNewClassMapping (ClassMapping cmap)
throws IOException
{
// writing a negative class code indicates that the class name will follow
writeClassMapping(-cmap.code, cmap.sclass);
}
/**
* Writes an existing class mapping to the stream.
*/
protected void writeExistingClassMapping (ClassMapping cmap)
throws IOException
{
writeShort(cmap.code);
}
/**
* Writes out the mapping for a class.
*/
protected void writeClassMapping (int code, Class sclass)
throws IOException
{
writeShort(code);
String cname = sclass.getName();
if (_translations != null) {
String tname = _translations.get(cname);
if (tname != null) {
cname = tname;
}
}
writeUTF(cname);
}
/**
* Writes a {@link Streamable} instance or one of the support object types <em>without
* associated class metadata</em> to the output stream. The caller is responsible for knowing