package org.simantics.databoard.serialization.impl; import java.io.DataInput; import java.io.DataOutput; import java.io.IOException; import java.util.List; import org.simantics.databoard.binding.ArrayBinding; import org.simantics.databoard.serialization.SerializationException; import org.simantics.databoard.serialization.Serializer.NonRecursiveSerializer; import org.simantics.databoard.type.ArrayType; import org.simantics.databoard.util.Range; public class IntArraySerializer extends NonRecursiveSerializer { Range length; Integer fixedLength, fixedSize; public IntArraySerializer(ArrayBinding binding) { ArrayType arrayType = (ArrayType) binding.type(); this.length = arrayType.getLength(); if (length!=null && length.getLower().equals(length.getUpper()) && length.getLower().getValue()!=null) { fixedLength = length.getLower().getValue().intValue(); fixedSize = fixedLength * 4; } } @Override public Object deserialize(DataInput in) throws IOException { int length = fixedSize != null ? fixedLength : in.readInt(); if (length<0) throw new SerializationException("Cannot use negative array length"); assertRemainingBytes(in, length*4L); int[] array = new int[length]; for(int i=0;i identities, Object obj) throws IOException { int length = fixedLength != null ? fixedLength : in.readInt(); int[] array = (int[]) obj; if (length!=array.length) array = new int[ length ]; assertRemainingBytes(in, length*4L); for (int i=0; i