Преглед на файлове

Use an extra byte per final-typed field to handle
the case of nulls. Note: this is specific to
serialized objects and is therefore not adding
a byte to things like Strings or arrays... those
will have to be reviewed separately.


git-svn-id: https://jmonkeyengine.googlecode.com/svn/trunk@7119 75d07b2b-3a1a-0410-a2c5-0572b91ccdca

PSp..om преди 14 години
родител
ревизия
5012b2d3dd

+ 1 - 1
engine/src/networking/com/jme3/network/serializing/Serializer.java

@@ -132,7 +132,7 @@ public abstract class Serializer {
             Serializable serializable = (Serializable)cls.getAnnotation(Serializable.class);
 
             Class serializerClass = serializable.serializer();
-            short classId = serializable.id();
+            short classId = serializable.id();           
             if (classId == 0) classId = --nextId;
 
             Serializer serializer = getSerializer(serializerClass);

+ 13 - 0
engine/src/networking/com/jme3/network/serializing/serializers/FieldSerializer.java

@@ -88,6 +88,11 @@ public class FieldSerializer extends Serializer {
     }
 
     public <T> T readObject(ByteBuffer data, Class<T> c) throws IOException {
+    
+        // Read the null/non-null marker
+        if (data.get() == 0x0)
+            return null;
+    
         SavedField[] fields = savedFields.get(c);
 
         T object;
@@ -117,6 +122,14 @@ public class FieldSerializer extends Serializer {
     }
 
     public void writeObject(ByteBuffer buffer, Object object) throws IOException {
+    
+        // Add the null/non-null marker
+        buffer.put( (byte)(object != null ? 0x1 : 0x0) );
+        if (object == null) {
+            // Nothing left to do
+            return;
+        }
+        
         SavedField[] fields = savedFields.get(object.getClass());
         if (fields == null)
             throw new IOException("The " + object.getClass() + " is not registered"