@Override public void serialize(DataOutput2 out, short[] value) throws IOException { out.packInt(value.length); for (short v : value) { out.writeShort(v); } }
@Override public void serialize(DataOutput2 out, Map<String, Object> map) throws IOException { Objects.requireNonNull(out); Objects.requireNonNull(map); out.packInt(map.size()); for (String k : map.keySet()) { Object o = map.get(k); if (o instanceof Double) { out.writeUTF("D" + k); out.writeDouble((Double) o); } else if (o instanceof Long) { out.writeUTF("L" + k); out.writeLong((Long) o); } else if (o instanceof String) { out.writeUTF("S" + k); out.writeUTF((String) o); } else if (o instanceof Integer) { out.writeUTF("I" + k); out.writeInt((Integer) o); } else { throw new RuntimeException("Unexpected type " + o.getClass()); } } }
@Override public void serialize(DataOutput2 out, E value) throws IOException { DataOutput2 out2 = new DataOutput2(); serializer.serialize(out2,value); byte[] tmp = new byte[out2.pos+41]; int newLen; try{ newLen = LZF.get().compress(out2.buf,out2.pos,tmp,0); }catch(IndexOutOfBoundsException e){ newLen=0; //larger after compression } if(newLen>=out2.pos||newLen==0){ //compression adds size, so do not compress out.packInt(0); out.write(out2.buf,0,out2.pos); return; } out.packInt( out2.pos+1); //unpacked size, zero indicates no compression out.write(tmp,0,newLen); }
@Override public void serialize(DataOutput2 out, NodeInfo nodeInfo) throws IOException { UuidSerializer.INSTANCE.serialize(out, MapDbAppStorage.checkNodeId(nodeInfo.getId())); out.writeUTF(nodeInfo.getName()); out.writeUTF(nodeInfo.getPseudoClass()); out.writeUTF(nodeInfo.getDescription()); out.writeLong(nodeInfo.getCreationTime()); out.writeLong(nodeInfo.getModificationTime()); out.writeInt(nodeInfo.getVersion()); out.writeInt(nodeInfo.getGenericMetadata().getStrings().size()); for (Map.Entry<String, String> e : nodeInfo.getGenericMetadata().getStrings().entrySet()) { out.writeUTF(e.getKey()); out.writeUTF(e.getValue()); } out.writeInt(nodeInfo.getGenericMetadata().getDoubles().size()); for (Map.Entry<String, Double> e : nodeInfo.getGenericMetadata().getDoubles().entrySet()) { out.writeUTF(e.getKey()); out.writeDouble(e.getValue()); } out.writeInt(nodeInfo.getGenericMetadata().getInts().size()); for (Map.Entry<String, Integer> e : nodeInfo.getGenericMetadata().getInts().entrySet()) { out.writeUTF(e.getKey()); out.writeInt(e.getValue()); } out.writeInt(nodeInfo.getGenericMetadata().getBooleans().size()); for (Map.Entry<String, Boolean> e : nodeInfo.getGenericMetadata().getBooleans().entrySet()) { out.writeUTF(e.getKey()); out.writeBoolean(e.getValue()); } }
@Override public void serialize(@NotNull DataOutput2 out, @NotNull LockDesc value) throws IOException { out.writeByte(VERSION); out.writeUTF(value.getPath()); out.writeUTF(value.getHash()); out.writeUTF(value.getToken()); out.writeUTF(value.getOwner()); if (value.getComment() != null) { out.writeBoolean(true); out.writeUTF(value.getComment()); } else { out.writeBoolean(false); } out.writeLong(value.getCreated()); }
@Override public void serialize(DataOutput2 out, TimeSeriesMetadata metadata) throws IOException { out.writeUTF(metadata.getName()); out.writeUTF(metadata.getDataType().name()); out.writeInt(metadata.getTags().size()); for (Map.Entry<String, String> e : metadata.getTags().entrySet()) { out.writeUTF(e.getKey()); out.writeUTF(e.getValue()); } TimeSeriesIndexSerializer.INSTANCE.serialize(out, metadata.getIndex()); }
@Override public void valueArraySerialize(DataOutput2 out, Object vals) throws IOException { for (int o : (int[]) vals) { out.writeInt(o); } }
@Override public void serialize(DataOutput2 out, DoubleDataChunk chunk) throws IOException { if (chunk instanceof UncompressedDoubleDataChunk) { UncompressedDoubleDataChunk uncompressedChunk = (UncompressedDoubleDataChunk) chunk; out.writeUTF("uncompressed"); out.writeInt(uncompressedChunk.getOffset()); out.writeInt(uncompressedChunk.getLength()); for (double value : uncompressedChunk.getValues()) { out.writeDouble(value); } } else if (chunk instanceof CompressedDoubleDataChunk) { CompressedDoubleDataChunk compressedChunk = (CompressedDoubleDataChunk) chunk; out.writeUTF("compressed"); out.writeInt(compressedChunk.getOffset()); out.writeInt(compressedChunk.getUncompressedLength()); out.writeInt(compressedChunk.getStepLengths().length); for (int value : compressedChunk.getStepLengths()) { out.writeInt(value); } out.writeInt(compressedChunk.getStepValues().length); for (double value : compressedChunk.getStepValues()) { out.writeDouble(value); } } else { throw new AssertionError(); } }
private void writePartitionedEvent(DataOutput2 out, PartitionedEvent event) throws IOException { out.packLong(event.getPartitionKey()); int partitionHashCode = 0; if (event.getPartition() != null) { partitionHashCode = event.getPartition().hashCode(); if (!hashCodePartitionDict.containsKey(partitionHashCode)) { hashCodePartitionDict.put(partitionHashCode, event.getPartition()); } } out.packInt(partitionHashCode); if (event.getEvent() != null) { byte[] eventBytes = SerializableUtils.serializeToCompressedByteArray(event.getEvent()); out.packInt(eventBytes.length); out.write(eventBytes); } else { out.packInt(0); } }
@Override public void serialize(DataOutput2 out, double[] value) throws IOException { out.packInt(value.length); for (double c : value) { out.writeDouble(c); } }
@Override public void valueArraySerialize(DataOutput2 out, Object vals) throws IOException { for (long o : (long[]) vals) { out.writeLong(o); } }
@Override public void writeChars(final String s) throws IOException { writeUTF(s); }
@Override public void serialize(@NotNull DataOutput2 out, @NotNull Node value) throws IOException { if(CC.ASSERT && value.flags>>>4!=0) throw new AssertionError(); if(CC.PARANOID) value.verifyNode(keySerializer, comparator, valueSerializer); int keysLenOrig = keySerializer.valueArraySize(value.keys); int keysLen = keySerializer.valueArraySize(value.keys)<<4; keysLen += value.flags; keysLen = DataIO.parity1Set(keysLen<<1); //keysLen and flags are combined into single packed long, that saves a byte for small nodes out.packInt(keysLen); if(!value.isRightEdge()) out.packLong(value.link); if(keysLenOrig>0) keySerializer.valueArraySerialize(out, value.keys); if(value.isDir()) { long[] child = (long[]) value.values; out.packLongArray(child, 0, child.length ); }else valueSerializer.valueArraySerialize(out, value.values); }
@Override public void serialize(DataOutput2 out, TimeSeriesIndex index) throws IOException { if (index instanceof RegularTimeSeriesIndex) { RegularTimeSeriesIndex regularIndex = (RegularTimeSeriesIndex) index; out.writeUTF("regularIndex"); out.writeLong(regularIndex.getStartTime()); out.writeLong(regularIndex.getEndTime()); out.writeLong(regularIndex.getSpacing()); } else { throw new AssertionError(); } }
@Override public void serialize(DataOutput2 out, float[] value) throws IOException { out.packInt(value.length); for (float v : value) { out.writeFloat(v); } }