org.simantics.databoard.serialization.impl
Class GenericRecordSerializer

java.lang.Object
  extended by org.simantics.databoard.serialization.Serializer
      extended by org.simantics.databoard.serialization.Serializer.CompositeSerializer
          extended by org.simantics.databoard.serialization.impl.GenericRecordSerializer

public class GenericRecordSerializer
extends Serializer.CompositeSerializer


Nested Class Summary
 
Nested classes/interfaces inherited from class org.simantics.databoard.serialization.Serializer
Serializer.CompositeSerializer, Serializer.NonRecursiveSerializer, Serializer.RecursiveSerializer
 
Field Summary
 Serializer[] componentSerializers
           
 
Constructor Summary
GenericRecordSerializer(RecordBinding binding, Serializer[] componentSerializers)
           
 
Method Summary
 java.lang.Object deserialize(java.io.DataInput in, java.util.List<java.lang.Object> identities)
          Deserialize an object from a readable.
 void deserialize(java.io.DataInput in, java.util.List<java.lang.Object> identities, java.lang.Object obj)
          Deserialize into an valid object.
 void finalizeConstruction()
          Finalize the construction of the serializer.
 java.lang.Integer getConstantSize()
          Get constant size of the data type in its binary serialized format
 int getMinSize()
           
 int getSize(java.lang.Object obj, gnu.trove.TObjectIntHashMap<java.lang.Object> identities)
          Get the number of bytes required to serialize an object
 void serialize(java.io.DataOutput out, gnu.trove.TObjectIntHashMap<java.lang.Object> identities, java.lang.Object obj)
          Serialize obj to out.
 void skip(java.io.DataInput in, java.util.List<java.lang.Object> identities)
          Skip over an object in a stream.
 
Methods inherited from class org.simantics.databoard.serialization.Serializer.CompositeSerializer
deserialize, deserialize, getSize, serialize, skip
 
Methods inherited from class org.simantics.databoard.serialization.Serializer
deserialize, deserialize, deserialize, deserialize, deserialize, deserialize, getInputStream, serialize, serialize, serialize, skip
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

componentSerializers

public Serializer[] componentSerializers
Constructor Detail

GenericRecordSerializer

public GenericRecordSerializer(RecordBinding binding,
                               Serializer[] componentSerializers)
Parameters:
binding -
componentSerializers - (optional) can be set later
Method Detail

finalizeConstruction

public void finalizeConstruction()
Description copied from class: Serializer.CompositeSerializer
Finalize the construction of the serializer. This is called once all component serializers are constructed.

Specified by:
finalizeConstruction in class Serializer.CompositeSerializer

deserialize

public java.lang.Object deserialize(java.io.DataInput in,
                                    java.util.List<java.lang.Object> identities)
                             throws java.io.IOException
Description copied from class: Serializer
Deserialize an object from a readable. The identities argument is a list of identities (in the binary block) of objects that have already been deserialized. Once deserialized they are added to the list. Typically an empty list is provided. If the type has no recursion, a null value can be provided.

Note, if in argument is instanceof BinaryReadable or RandomAccessBinary, the serializer performs extra protection against malformed data when deserializing arrays and maps. This prevents the serializer from instanting potentially out-of-memory-invoking huge arrays. For example, if data data says array size is 0xffffffff (-1), 4GB is allocated -> out of memory exception -> unhandled runtime error. BinaryReadable has length limit which allowes serializer to estimate whether future data is readable.

Specified by:
deserialize in class Serializer
Parameters:
in - DataInput, BinaryReadable or RandomAccessBinary
identities - empty identities array or null if there is no recursion
Returns:
the instance
Throws:
java.io.IOException

deserialize

public void deserialize(java.io.DataInput in,
                        java.util.List<java.lang.Object> identities,
                        java.lang.Object obj)
                 throws java.io.IOException
Description copied from class: Serializer
Deserialize into an valid object. This method writes over previous values.

Specified by:
deserialize in class Serializer
obj - valid object
Throws:
java.io.IOException

skip

public void skip(java.io.DataInput in,
                 java.util.List<java.lang.Object> identities)
          throws java.io.IOException,
                 SerializationException
Description copied from class: Serializer
Skip over an object in a stream. This method deserializes the object without producing a result or reading thru all bytes.

Specified by:
skip in class Serializer
Throws:
java.io.IOException
SerializationException

serialize

public void serialize(java.io.DataOutput out,
                      gnu.trove.TObjectIntHashMap<java.lang.Object> identities,
                      java.lang.Object obj)
               throws java.io.IOException
Description copied from class: Serializer
Serialize obj to out. The identities argument is a map of identities (in the binary block) and objects that have already been serialized. Once serialized, an object is added to the map. Typically an empty map is provided. If the type has no recursion, a null value can be provided.

Specified by:
serialize in class Serializer
identities - Thread local empty map or null if there is no recursion
Throws:
java.io.IOException

getConstantSize

public java.lang.Integer getConstantSize()
Description copied from class: Serializer
Get constant size of the data type in its binary serialized format

Specified by:
getConstantSize in class Serializer
Returns:
size in bytes or null if not fixed

getSize

public int getSize(java.lang.Object obj,
                   gnu.trove.TObjectIntHashMap<java.lang.Object> identities)
            throws java.io.IOException
Description copied from class: Serializer
Get the number of bytes required to serialize an object

Specified by:
getSize in class Serializer
identities - thread local empty hash map
Returns:
number of bytes required to serialize obj
Throws:
java.io.IOException

getMinSize

public int getMinSize()
Specified by:
getMinSize in class Serializer
Returns:
the minSize