X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=blobdiff_plain;f=bundles%2Forg.simantics.databoard%2Fsrc%2Forg%2Fsimantics%2Fdataboard%2Fstreaming%2FDataSerializationDebugger.java;fp=bundles%2Forg.simantics.databoard%2Fsrc%2Forg%2Fsimantics%2Fdataboard%2Fstreaming%2FDataSerializationDebugger.java;h=df64db20586332a02bb39e9d0b4b7313f2520022;hb=694c553a3c402b9397ff99e904b4f99b77b51df1;hp=0000000000000000000000000000000000000000;hpb=957ddea830ceb97eab9f358d99a591cafc518d8a;p=simantics%2Fplatform.git diff --git a/bundles/org.simantics.databoard/src/org/simantics/databoard/streaming/DataSerializationDebugger.java b/bundles/org.simantics.databoard/src/org/simantics/databoard/streaming/DataSerializationDebugger.java new file mode 100644 index 000000000..df64db205 --- /dev/null +++ b/bundles/org.simantics.databoard/src/org/simantics/databoard/streaming/DataSerializationDebugger.java @@ -0,0 +1,313 @@ +package org.simantics.databoard.streaming; + +import java.io.IOException; +import java.io.PrintStream; + +import org.simantics.databoard.Bindings; +import org.simantics.databoard.serialization.Serializer; +import org.simantics.databoard.type.ArrayType; +import org.simantics.databoard.type.BooleanType; +import org.simantics.databoard.type.ByteType; +import org.simantics.databoard.type.Component; +import org.simantics.databoard.type.Datatype; +import org.simantics.databoard.type.Datatype.Visitor; +import org.simantics.databoard.type.DoubleType; +import org.simantics.databoard.type.FloatType; +import org.simantics.databoard.type.IntegerType; +import org.simantics.databoard.type.LongType; +import org.simantics.databoard.type.MapType; +import org.simantics.databoard.type.OptionalType; +import org.simantics.databoard.type.RecordType; +import org.simantics.databoard.type.StringType; +import org.simantics.databoard.type.UnionType; +import org.simantics.databoard.type.VariantType; +import org.simantics.databoard.util.Range; +import org.simantics.databoard.util.binary.Endian; + +/** + * Utility for debugging corrupted values. + */ +public class DataSerializationDebugger { + DataReader in; + PrintStream out; + int indentation; + + private void indentation() { + for(int i=0;i FIXED_SIZE = new Visitor() { + + @Override + public Integer visit(ArrayType b) { + Range length = b.getLength(); + if(length == null + || length.getLower().getValue()==null + || !length.getLower().equals(length.getUpper())) + return null; + + int fixedLength = length.getLower().getValue().intValue(); + + Integer componentLength = b.componentType.accept(this); + if(componentLength == null) + return null; + + return fixedLength * componentLength; + } + + @Override + public Integer visit(BooleanType b) { + return I1; + } + + @Override + public Integer visit(DoubleType b) { + return I8; + } + + @Override + public Integer visit(FloatType b) { + return I4; + } + + @Override + public Integer visit(IntegerType b) { + return I4; + } + + @Override + public Integer visit(ByteType b) { + return I1; + } + + @Override + public Integer visit(LongType b) { + return I8; + } + + @Override + public Integer visit(OptionalType b) { + return null; + } + + @Override + public Integer visit(RecordType b) { + if(b.isReferable()) + return null; + int sum = 0; + for(Component component : b.getComponents()) { + Integer componentSize = component.type.accept(this); + if(componentSize == null) + return null; + sum += componentSize; + } + return sum; + } + + @Override + public Integer visit(StringType b) { + return null; + } + + @Override + public Integer visit(UnionType b) { + Integer commonComponentSize = null; + for(Component component : b.components) { + Integer componentSize = component.type.accept(this); + if(componentSize == null) + return null; + if(commonComponentSize == null) + commonComponentSize = componentSize; + else if(!commonComponentSize.equals(componentSize)) + return null; + } + if(commonComponentSize == null) + return 0; + return commonComponentSize + Endian.getUIntLength(b.components.length-1); + } + + @Override + public Integer visit(VariantType b) { + return null; + } + + @Override + public Integer visit(MapType b) { + return null; + } + + }; + + private void expectArray(ArrayType datatype) throws IOException { + out.print("Array"); + int length; + if(datatype.accept(FIXED_SIZE) == null) + length = in.beginVariableLengthArray(); + else + length = getFixedLength(datatype); + out.println("(" + length + "):"); + ++indentation; + for(int i=0;i