private void writeArray(Serializer elementSerializer, ByteBuffer buffer, Object array, int dimension, int dimensionCount) throws IOException { int length = Array.getLength(array); if (dimension > 0) { buffer.putInt(length); } // Write array data. boolean elementsAreArrays = dimension < dimensionCount - 1; for (int i = 0; i < length; i++) { Object element = Array.get(array, i); if (elementsAreArrays) { if (element != null) writeArray(elementSerializer, buffer, element, dimension + 1, dimensionCount); } else if (elementSerializer != null) { elementSerializer.writeObject(buffer, element); } else { // Each element could be a different type. Store the class with the object. Serializer.writeClassAndObject(buffer, element); } } }
serializer.writeObject(buffer, elem);
serializer.writeObject(buffer, val); } else { Serializer.writeClassAndObject(buffer, val);
Serializer.writeClassAndObject(buffer, entry.getKey()); }else{ keySerial.writeObject(buffer, entry.getKey()); valSerial.writeObject(buffer, entry.getValue());
/** * Write the class and object. * * @param buffer The buffer to write to. * @param object The object to write. * @throws IOException If serializing fails. */ public static void writeClassAndObject(ByteBuffer buffer, Object object) throws IOException { if (object == null) { buffer.putShort((short)-1); return; } SerializerRegistration reg = writeClass(buffer, object.getClass()); // If the caller (or us) has registered a generic base class (like Enum) // that is meant to steer automatic resolution for things like FieldSerializer // that have final classes in fields... then there are cases where the exact // type isn't known by the outer class. (Think of a message object // that has an Object field but tries to send an Enum subclass in it.) // In that case, the SerializerRegistration object we get back isn't // really going to be capable of recreating the object on the other // end because it won't know what class to use. This only comes up // in writeclassAndObejct() because we just wrote an ID to a more generic // class than will be readable on the other end. The check is simple, though. if( reg.getType() != object.getClass() ) { throw new IllegalArgumentException("Class has not been registered:" + object.getClass() + " but resolved to generic serializer for:" + reg.getType()); } reg.getSerializer().writeObject(buffer, object); }
/** * Write the class and object. * * @param buffer The buffer to write to. * @param object The object to write. * @throws IOException If serializing fails. */ public static void writeClassAndObject(ByteBuffer buffer, Object object) throws IOException { if (object == null) { buffer.putShort((short)-1); return; } SerializerRegistration reg = writeClass(buffer, object.getClass()); reg.getSerializer().writeObject(buffer, object); }
private void writeArray(Serializer elementSerializer, ByteBuffer buffer, Object array, int dimension, int dimensionCount) throws IOException { int length = Array.getLength(array); if (dimension > 0) { buffer.putInt(length); } // Write array data. boolean elementsAreArrays = dimension < dimensionCount - 1; for (int i = 0; i < length; i++) { Object element = Array.get(array, i); if (elementsAreArrays) { if (element != null) writeArray(elementSerializer, buffer, element, dimension + 1, dimensionCount); } else if (elementSerializer != null) { elementSerializer.writeObject(buffer, element); } else { // Each element could be a different type. Store the class with the object. Serializer.writeClassAndObject(buffer, element); } } }
private void writeArray(Serializer elementSerializer, ByteBuffer buffer, Object array, int dimension, int dimensionCount) throws IOException { int length = Array.getLength(array); if (dimension > 0) { buffer.putInt(length); } // Write array data. boolean elementsAreArrays = dimension < dimensionCount - 1; for (int i = 0; i < length; i++) { Object element = Array.get(array, i); if (elementsAreArrays) { if (element != null) writeArray(elementSerializer, buffer, element, dimension + 1, dimensionCount); } else if (elementSerializer != null) { elementSerializer.writeObject(buffer, element); } else { // Each element could be a different type. Store the class with the object. Serializer.writeClassAndObject(buffer, element); } } }
serializer.writeObject(buffer, val); } else { Serializer.writeClassAndObject(buffer, val);
serializer.writeObject(buffer, elem);
serializer.writeObject(buffer, elem);
public void writeObject( ByteBuffer buffer, Object object ) throws IOException { EntityChange change = (EntityChange)object; idSerializer.writeObject(buffer, change.getEntityId()); classSerializer.writeObject(buffer, change.getComponentType()); // Have to use dynamic lookup for the value Serializer.writeClassAndObject(buffer, TransientUtils.clean(change.getComponent())); } }
serializer.writeObject(buffer, val); } else { Serializer.writeClassAndObject(buffer, val);
Serializer.writeClassAndObject(buffer, entry.getKey()); }else{ keySerial.writeObject(buffer, entry.getKey()); valSerial.writeObject(buffer, entry.getValue());
Serializer.writeClassAndObject(buffer, entry.getKey()); }else{ keySerial.writeObject(buffer, entry.getKey()); valSerial.writeObject(buffer, entry.getValue());
/** * Write the class and object. * * @param buffer The buffer to write to. * @param object The object to write. * @throws IOException If serializing fails. */ public static void writeClassAndObject(ByteBuffer buffer, Object object) throws IOException { if (object == null) { buffer.putShort((short)-1); return; } SerializerRegistration reg = writeClass(buffer, object.getClass()); // If the caller (or us) has registered a generic base class (like Enum) // that is meant to steer automatic resolution for things like FieldSerializer // that have final classes in fields... then there are cases where the exact // type isn't known by the outer class. (Think of a message object // that has an Object field but tries to send an Enum subclass in it.) // In that case, the SerializerRegistration object we get back isn't // really going to be capable of recreating the object on the other // end because it won't know what class to use. This only comes up // in writeclassAndObejct() because we just wrote an ID to a more generic // class than will be readable on the other end. The check is simple, though. if( reg.getType() != object.getClass() ) { throw new IllegalArgumentException("Class has not been registered:" + object.getClass() + " but resolved to generic serializer for:" + reg.getType()); } reg.getSerializer().writeObject(buffer, object); }