Added methods and @Intern annotation to stream pooled strings (a
la String.intern) as we do class names, by sending the value the first time and a short code thereafter (with special handling for datagrams, where me must continue sending the mapping until we know they've been received). This is mostly useful for the lengthy config names and parameter names of Project X, but it could conceivably also be used for things like NamedEvents, which stream the same object field names many times in the course of a stream. git-svn-id: svn+ssh://src.earth.threerings.net/narya/trunk@5797 542714f4-19e9-0310-aa3c-eee0fc999fb1
This commit is contained in:
@@ -43,4 +43,25 @@ public class UnreliableObjectInputStream extends ObjectInputStream
|
||||
_classmap.set(code, cmap);
|
||||
return cmap;
|
||||
}
|
||||
|
||||
@Override // documentation inherited
|
||||
protected void mapIntern (short code, String value)
|
||||
{
|
||||
// see if we already have a mapping
|
||||
String ovalue = (code < _internmap.size()) ? _internmap.get(code) : null;
|
||||
if (ovalue != null) {
|
||||
// sanity check
|
||||
if (!ovalue.equals(value)) {
|
||||
throw new RuntimeException(
|
||||
"Received mapping for intern that conflicts with existing mapping " +
|
||||
"[code=" + code + ", ovalue=" + ovalue + ", nvalue=" + value + "]");
|
||||
}
|
||||
return;
|
||||
}
|
||||
// insert null entries for missing mappings
|
||||
for (int ii = 0, nn = (code + 1) - _internmap.size(); ii < nn; ii++) {
|
||||
_internmap.add(null);
|
||||
}
|
||||
_internmap.set(code, value);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user