Fixed writing of polymorphic classes.

Fixes  and probably many others.
This commit is contained in:
SpaceToad 2014-06-23 08:31:56 +02:00
parent 2e209805b8
commit afc9ce619e

View file

@ -253,10 +253,12 @@ public class ClassMapping extends ClassSerializer {
Class realClass = obj.getClass(); Class realClass = obj.getClass();
if (realClass.equals(this.mappedClass)) { if (realClass.equals(this.mappedClass)) {
data.writeByte(0); data.writeBoolean(true);
} else { } else {
data.writeBoolean(false);
NetworkIdRegistry.write(data, realClass.getCanonicalName()); NetworkIdRegistry.write(data, realClass.getCanonicalName());
ClassMapping delegateMapping = (ClassMapping) get(realClass); ClassMapping delegateMapping = (ClassMapping) get(realClass);
delegateMapping.writeClass(obj, data, context);
return; return;
} }
@ -303,16 +305,12 @@ public class ClassMapping extends ClassSerializer {
Object obj = objI; Object obj = objI;
// The data layout for an object is the following: // The data layout for an object is the following:
// [boolean] does the object exist (e.g. non-null) // [boolean] what is the object real class?
// {false} exit // {false} the same as the declared class
// [int] what is the object real class? // {true} the network id of the class
// {0} the same as the declared class
// {1-x} the network id of the class
// [bytes] the actual contents // [bytes] the actual contents
int index = data.readByte(); if (!data.readBoolean()) {
if (index != 0) {
String className = NetworkIdRegistry.read(data); String className = NetworkIdRegistry.read(data);
Class cls = Class.forName(className); Class cls = Class.forName(className);
ClassMapping delegateMapping = (ClassMapping) get(cls); ClassMapping delegateMapping = (ClassMapping) get(cls);