@Override public Integer valueArrayBinaryGet(DataInput2 input, int keysLen, int pos) throws IOException { int a = 0; while (pos-- >= 0) { a += input.unpackInt(); } return a; }
@Override public double[] deserialize(DataInput2 in, int available) throws IOException { final int size = in.unpackInt(); double[] ret = new double[size]; for (int i = 0; i < size; i++) { ret[i] = in.readDouble(); } return ret; }
@Override public Map<String, Object> deserialize(DataInput2 input, int available) throws IOException { Objects.requireNonNull(input); Map<String, Object> map = new TreeMap(); int size = input.unpackInt(); for (int i = 0; i < size; i++) { String k = input.readUTF(); if (k.startsWith("D")) { map.put(k.substring(1), input.readDouble()); } else if (k.startsWith("L")) { map.put(k.substring(1), input.readLong()); } else if (k.startsWith("S")) { map.put(k.substring(1), input.readUTF()); } else if (k.startsWith("I")) { map.put(k.substring(1), input.readInt()); } } return map; }
@Override public NodeInfo deserialize(DataInput2 input, int available) throws IOException { String nodeId = UuidSerializer.INSTANCE.deserialize(input, available).toString(); String name = input.readUTF(); String pseudoClass = input.readUTF(); String description = input.readUTF(); long creationTime = input.readLong(); long modificationTime = input.readLong(); int version = input.readInt(); NodeGenericMetadata metadata = new NodeGenericMetadata(); int stringMetadataSize = input.readInt(); for (int i = 0; i < stringMetadataSize; i++) { metadata.setString(input.readUTF(), input.readUTF()); } int doubleMetadataSize = input.readInt(); for (int i = 0; i < doubleMetadataSize; i++) { metadata.setDouble(input.readUTF(), input.readDouble()); } int intMetadataSize = input.readInt(); for (int i = 0; i < intMetadataSize; i++) { metadata.setInt(input.readUTF(), input.readInt()); } int booleanMetadataSize = input.readInt(); for (int i = 0; i < booleanMetadataSize; i++) { metadata.setBoolean(input.readUTF(), input.readBoolean()); } return new NodeInfo(nodeId, name, pseudoClass, description, creationTime, modificationTime, version, metadata); } }
@Override public LockDesc deserialize(@NotNull DataInput2 input, int available) throws IOException { byte version = input.readByte(); if (version != VERSION) { throw new IOException("Unexpected data format"); } final String path = input.readUTF(); final String hash = input.readUTF(); final String token = input.readUTF(); final String owner = input.readUTF(); final String comment = input.readBoolean() ? input.readUTF() : null; final long created = input.readLong(); return new LockDesc(path, hash, token, owner, comment, created); }
@Override public TimeSeriesMetadata deserialize(DataInput2 input, int available) throws IOException { String name = input.readUTF(); TimeSeriesDataType dataType = TimeSeriesDataType.valueOf(input.readUTF()); Map<String, String> tags = new HashMap<>(); int size = input.readInt(); for (int i = 0; i < size; i++) { String key = input.readUTF(); String value = input.readUTF(); tags.put(key, value); } TimeSeriesIndex index = TimeSeriesIndexSerializer.INSTANCE.deserialize(input, available); return new TimeSeriesMetadata(name, dataType, tags, index); } }
private PartitionedEvent readPartitionedEvent(DataInput2 in) throws IOException { PartitionedEvent event = new PartitionedEvent(); event.setPartitionKey(in.unpackLong()); int partitionHashCode = in.unpackInt(); if (partitionHashCode != 0 && hashCodePartitionDict.containsKey(partitionHashCode)) { event.setPartition(hashCodePartitionDict.get(partitionHashCode)); } int eventBytesLen = in.unpackInt(); if (eventBytesLen > 0) { byte[] eventBytes = new byte[eventBytesLen]; in.readFully(eventBytes); event.setEvent((StreamEvent) SerializableUtils.deserializeFromCompressedByteArray(eventBytes, "Deserialize event from bytes")); } return event; }
@Override public DoubleDataChunk deserialize(DataInput2 input, int available) throws IOException { String type = input.readUTF(); if ("uncompressed".equals(type)) { int offset = input.readInt(); int length = input.readInt(); double[] values = new double[length]; for (int i = 0; i < length; i++) { values[i] = input.readDouble(); } return new UncompressedDoubleDataChunk(offset, values); } else if ("compressed".equals(type)) { int offset = input.readInt(); int uncompressedLength = input.readInt(); int stepLengthsLength = input.readInt(); int[] stepLengths = new int[stepLengthsLength]; for (int i = 0; i < stepLengthsLength; i++) { stepLengths[i] = input.readInt(); } int stepValuesLength = input.readInt(); double[] stepValues = new double[stepValuesLength]; for (int i = 0; i < stepValuesLength; i++) { stepValues[i] = input.readDouble(); } return new CompressedDoubleDataChunk(offset, uncompressedLength, stepValues, stepLengths); } else { throw new AssertionError(); } } }
@Override public byte[] deserialize(DataInput2 in, int available) throws IOException { byte[] ret = new byte[available]; in.readFully(ret); return ret; }
@Override public Object valueArrayDeserialize(DataInput2 in, int size) throws IOException { int[] ret = new int[size]; for (int i = 0; i < size; i++) { ret[i] = in.readInt(); } return ret; }
@Override public Integer valueArrayBinaryGet(DataInput2 input, int keysLen, int pos) throws IOException { input.unpackLongSkip(pos); return input.unpackInt(); }
@Override public T deserialize(@NotNull DataInput2 input, int available) throws IOException { int classIdx = input.readInt(); String className = getClassForInt(classIdx); Class<?> clazz; try { clazz = Class.forName(className); } catch (ClassNotFoundException e) { throw new RuntimeException(e); //Shouldn't normally happen... } Persistable p; try { p = (Persistable) clazz.newInstance(); } catch (InstantiationException | IllegalAccessException e) { throw new RuntimeException(e); } int remainingLength = available - 4; //-4 for int class index byte[] temp = new byte[remainingLength]; input.readFully(temp); p.decode(temp); return (T) p; }
@Override public Object valueArrayDeserialize(DataInput2 in, int size) throws IOException { size *= 2; long[] ret = new long[size]; for (int i = 0; i < size; i++) { ret[i] = in.readLong(); } return ret; }
@Override public TimeSeriesIndex deserialize(DataInput2 input, int available) throws IOException { String indexType = input.readUTF(); long startTime = input.readLong(); long endTime = input.readLong(); long spacing = input.readLong(); if ("regularIndex".equals(indexType)) { return new RegularTimeSeriesIndex(startTime, endTime, spacing); } else { throw new AssertionError(); } } }
@Override public long get(DataInput2 input, int size) throws IOException { int keysLen = DataIO.parity1Get(input.unpackInt())>>>1; int flags = keysLen&0xF; keysLen = keysLen>>>4; input.unpackLong(); input.unpackLongSkip(pos-1); return input.unpackLong();