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
3.0
PSp..om 14 years ago
parent 3e5973793e
commit 5012b2d3dd
  1. 13
      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"

Loading…
Cancel
Save