private void readArray (Serializer elementSerializer, Class elementClass, ByteBuffer buffer, Object array, int dimension, int[] dimensions) throws IOException { boolean elementsAreArrays = dimension < dimensions.length - 1; int length; if (dimension == 0) { length = dimensions[0]; } else { length = buffer.getInt(); } for (int i = 0; i < length; i++) { if (elementsAreArrays) { // Nested array. Object element = Array.get(array, i); if (element != null) readArray(elementSerializer, elementClass, buffer, element, dimension + 1, dimensions); } else if (elementSerializer != null) { // Use same converter (and class) for all elements. Array.set(array, i, elementSerializer.readObject(buffer, elementClass)); } else { // Each element could be a different type. Look up the class with the object. Array.set(array, i, Serializer.readClassAndObject(buffer)); } } } }
value = serializer.readObject(data, field.getType()); } else { value = Serializer.readClassAndObject(data);
@SuppressWarnings("unchecked") public <T> T readObject(ByteBuffer data, Class<T> c) throws IOException { int length = data.getInt(); Collection collection; try { collection = (Collection)c.newInstance(); } catch (Exception e) { log.log(Level.FINE, "[Serializer][???] Could not determine collection type. Using ArrayList."); collection = new ArrayList(length); } if (length == 0) return (T)collection; if (data.get() == (byte)1) { SerializerRegistration reg = Serializer.readClass(data); Class clazz = reg.getType(); Serializer serializer = reg.getSerializer(); for (int i = 0; i != length; ++i) { collection.add(serializer.readObject(data, clazz)); } } else { for (int i = 0; i != length; ++i) { collection.add(Serializer.readClassAndObject(data)); } } return (T)collection; }
key = Serializer.readClassAndObject(data); }else{ key = keySerial.readObject(data, keyClazz); value = valSerial.readObject(data, valClazz);
/** * Read the class and the object. * * @param buffer Buffer to read from. * @return The Object that was read. * @throws IOException If serialization failed. */ @SuppressWarnings("unchecked") public static Object readClassAndObject(ByteBuffer buffer) throws IOException { SerializerRegistration reg = readClass(buffer); if (reg == NULL_CLASS) return null; if (reg == null) throw new SerializerException( "Class not found for buffer data." ); return reg.getSerializer().readObject(buffer, reg.getType()); }
@SuppressWarnings("unchecked") public <T> T readObject( ByteBuffer data, Class<T> c ) throws IOException { EntityId id = idSerializer.readObject(data, EntityId.class); Class type = classSerializer.readObject(data, Class.class); Object component = Serializer.readClassAndObject(data); return c.cast(new EntityChange(id, type, (EntityComponent)component)); }
private void readArray (Serializer elementSerializer, Class elementClass, ByteBuffer buffer, Object array, int dimension, int[] dimensions) throws IOException { boolean elementsAreArrays = dimension < dimensions.length - 1; int length; if (dimension == 0) { length = dimensions[0]; } else { length = buffer.getInt(); } for (int i = 0; i < length; i++) { if (elementsAreArrays) { // Nested array. Object element = Array.get(array, i); if (element != null) readArray(elementSerializer, elementClass, buffer, element, dimension + 1, dimensions); } else if (elementSerializer != null) { // Use same converter (and class) for all elements. Array.set(array, i, elementSerializer.readObject(buffer, elementClass)); } else { // Each element could be a different type. Look up the class with the object. Array.set(array, i, Serializer.readClassAndObject(buffer)); } } } }
private void readArray (Serializer elementSerializer, Class elementClass, ByteBuffer buffer, Object array, int dimension, int[] dimensions) throws IOException { boolean elementsAreArrays = dimension < dimensions.length - 1; int length; if (dimension == 0) { length = dimensions[0]; } else { length = buffer.getInt(); } for (int i = 0; i < length; i++) { if (elementsAreArrays) { // Nested array. Object element = Array.get(array, i); if (element != null) readArray(elementSerializer, elementClass, buffer, element, dimension + 1, dimensions); } else if (elementSerializer != null) { // Use same converter (and class) for all elements. Array.set(array, i, elementSerializer.readObject(buffer, elementClass)); } else { // Each element could be a different type. Look up the class with the object. Array.set(array, i, Serializer.readClassAndObject(buffer)); } } } }
value = serializer.readObject(data, field.getType()); } else { value = Serializer.readClassAndObject(data);
value = serializer.readObject(data, field.getType()); } else { value = Serializer.readClassAndObject(data);
@SuppressWarnings("unchecked") public <T> T readObject(ByteBuffer data, Class<T> c) throws IOException { int length = data.getInt(); Collection collection; try { collection = (Collection)c.newInstance(); } catch (Exception e) { log.log(Level.FINE, "[Serializer][???] Could not determine collection type. Using ArrayList."); collection = new ArrayList(length); } if (length == 0) return (T)collection; if (data.get() == (byte)1) { SerializerRegistration reg = Serializer.readClass(data); Class clazz = reg.getType(); Serializer serializer = reg.getSerializer(); for (int i = 0; i != length; ++i) { collection.add(serializer.readObject(data, clazz)); } } else { for (int i = 0; i != length; ++i) { collection.add(Serializer.readClassAndObject(data)); } } return (T)collection; }
@SuppressWarnings("unchecked") public <T> T readObject(ByteBuffer data, Class<T> c) throws IOException { int length = data.getInt(); Collection collection; try { collection = (Collection)c.newInstance(); } catch (Exception e) { log.log(Level.FINE, "[Serializer][???] Could not determine collection type. Using ArrayList."); collection = new ArrayList(length); } if (length == 0) return (T)collection; if (data.get() == (byte)1) { SerializerRegistration reg = Serializer.readClass(data); Class clazz = reg.getType(); Serializer serializer = reg.getSerializer(); for (int i = 0; i != length; ++i) { collection.add(serializer.readObject(data, clazz)); } } else { for (int i = 0; i != length; ++i) { collection.add(Serializer.readClassAndObject(data)); } } return (T)collection; }
key = Serializer.readClassAndObject(data); }else{ key = keySerial.readObject(data, keyClazz); value = valSerial.readObject(data, valClazz);
key = Serializer.readClassAndObject(data); }else{ key = keySerial.readObject(data, keyClazz); value = valSerial.readObject(data, valClazz);
/** * Read the class and the object. * * @param buffer Buffer to read from. * @return The Object that was read. * @throws IOException If serialization failed. */ @SuppressWarnings("unchecked") public static Object readClassAndObject(ByteBuffer buffer) throws IOException { SerializerRegistration reg = readClass(buffer); if (reg == NULL_CLASS) return null; if (reg == null) throw new SerializerException( "Class not found for buffer data." ); return reg.getSerializer().readObject(buffer, reg.getType()); }
/** * Read the class and the object. * * @param buffer Buffer to read from. * @return The Object that was read. * @throws IOException If serialization failed. */ @SuppressWarnings("unchecked") public static Object readClassAndObject(ByteBuffer buffer) throws IOException { SerializerRegistration reg = readClass(buffer); if (reg == NULL_CLASS) return null; if (reg == null) throw new SerializerException( "Class not found for buffer data." ); return reg.getSerializer().readObject(buffer, reg.getType()); }