package org.simantics.databoard.serialization.impl;
import gnu.trove.map.hash.TObjectIntHashMap;
import java.io.DataInput;
import java.io.DataOutput;
import java.io.IOException;
import java.util.List;
import org.simantics.databoard.binding.RecordBinding;
import org.simantics.databoard.binding.error.BindingException;
import org.simantics.databoard.serialization.SerializationException;
import org.simantics.databoard.serialization.Serializer;
import org.simantics.databoard.serialization.Serializer.RecursiveSerializer;
import org.simantics.databoard.type.RecordType;
public class ReferableRecordSerializer extends RecursiveSerializer {
RecordBinding binding;
public Serializer[] componentSerializers;
/** The combined size elements, or null
*/
Integer fixedSizeOfContent;
int minContentSize;
public ReferableRecordSerializer(RecordBinding binding, Serializer[] componentSerializers) {
this.binding = binding;
this.componentSerializers = componentSerializers;
}
@Override
public void finalizeConstruction() {
fixedSizeOfContent = null;
for (Serializer componentSerializer : componentSerializers) {
minContentSize += componentSerializer.getMinSize();
Integer componentFixedSize = componentSerializer.getConstantSize();
if (componentFixedSize==null) {
fixedSizeOfContent = null;
break;
}
fixedSizeOfContent = fixedSizeOfContent==null ? componentFixedSize : fixedSizeOfContent + componentFixedSize;
}
}
boolean referable() {
return ((RecordType)binding.type()).isReferable();
}
@Override
public Object deserialize(DataInput in, List