@Override public BigDecimal readBigDecimal(DataInput in) throws IOException { int scale = in.readInt(); BigInteger intValue = readBigInteger(in); BigDecimal decValue = new BigDecimal(intValue, scale); return decValue; }
@Override public BigInteger readBigInteger(DataInput in) throws IOException { byte[] bytes = readByteArray(in); return new BigInteger(bytes); }
@Override public String[] readStringArray(DataInput in) throws IOException { final int len = readUnsignedVarInt(in); String[] strings = new String[len]; for (int i = 0; i < len; i++) { strings[i] = readString(in); } return strings; }
@Override public void writeMap(Map<String, Object> map, DataOutput out) throws IOException { final int size = map.size(); writeUnsignedVarInt(size, out); for (Entry<String, Object> e : map.entrySet()) { String key = e.getKey(); writeString(key, out); Object value = e.getValue(); FieldType fieldType = FieldType.forValue(value); out.writeByte(fieldType.getTag()); encode(fieldType, value, out); } } }
@Override public Map<String, Object> readMap(DataInput in) throws IOException { final int size = readUnsignedVarInt(in); Map<String, Object> map = new HashMap<>(); String key; byte fieldTag; FieldType fieldType; Object value; for (int i = 0; i < size; i++) { key = readString(in); fieldTag = in.readByte(); fieldType = FieldType.valueOf(fieldTag); value = decode(fieldType, in); map.put(key, value); } return map; }
public static void write(NodeId id, DataOutput out) throws IOException { checkNotNull(id); checkNotNull(out); final String name = id.name(); @Nullable final Object value = id.value(); final FieldType valueType = FieldType.forValue((Object) id.value()); out.writeUTF(name); out.writeByte(valueType.ordinal()); DataStreamValueSerializerV2.INSTANCE.encode(valueType, value, out); }
public static NodeId read(DataInput in) throws IOException { final String name = in.readUTF(); FieldType type = FieldType.valueOf(in.readUnsignedByte()); final Object val = DataStreamValueSerializerV2.INSTANCE.decode(type, in); return new NodeId(name, val); } }
@Override public void writeBigInteger(BigInteger field, DataOutput data) throws IOException { byte[] bytes = field.toByteArray(); writeByteArray(bytes, data); }
@Override public void writeStringArray(String[] field, DataOutput data) throws IOException { writeUnsignedVarInt(field.length, data); for (String s : field) writeString(s, data); }
@Override public void writeBigDecimal(BigDecimal d, DataOutput data) throws IOException { int scale = d.scale(); BigInteger i = d.unscaledValue(); data.writeInt(scale); writeBigInteger(i, data); }
@Override public void writeMap(Map<String, Object> map, DataOutput out) throws IOException { final int size = map.size(); writeUnsignedVarInt(size, out); for (Entry<String, Object> e : map.entrySet()) { String key = e.getKey(); writeString(key, out); Object value = e.getValue(); FieldType fieldType = FieldType.forValue(value); out.writeByte(fieldType.getTag()); encode(fieldType, value, out); } } }
@Override public Map<String, Object> readMap(DataInput in) throws IOException { final int size = readUnsignedVarInt(in); Map<String, Object> map = new HashMap<>(); String key; byte fieldTag; FieldType fieldType; Object value; for (int i = 0; i < size; i++) { key = readString(in); fieldTag = in.readByte(); fieldType = FieldType.valueOf(fieldTag); value = decode(fieldType, in); map.put(key, value); } return map; }
public static void write(NodeId id, DataOutput out) { checkNotNull(id); checkNotNull(out); final String name = id.name(); @Nullable final Object value = id.value(); final FieldType valueType = FieldType.forValue((Object) id.value()); try { out.writeUTF(name); out.writeByte(valueType.ordinal()); DataStreamValueSerializerV2.INSTANCE.encode(valueType, value, out); } catch (IOException e) { throw new RuntimeException(e); } }
public static NodeId read(DataInput in) throws IOException { final String name = in.readUTF(); FieldType type = FieldType.valueOf(in.readUnsignedByte()); final Object val = DataStreamValueSerializerV2.INSTANCE.decode(type, in); return new NodeId(name, val); } }
@Override public void writeBigInteger(BigInteger field, DataOutput data) throws IOException { byte[] bytes = field.toByteArray(); writeByteArray(bytes, data); }
@Override public void writeStringArray(String[] field, DataOutput data) throws IOException { writeUnsignedVarInt(field.length, data); for (String s : field) writeString(s, data); }
@Override public void writeBigDecimal(BigDecimal d, DataOutput data) throws IOException { int scale = d.scale(); BigInteger i = d.unscaledValue(); data.writeInt(scale); writeBigInteger(i, data); }
writeUnsignedVarInt(relativeValueOffset, inlineData); } else { super.encode(valueType, value, inlineData);
@Override public void writeGeometry(Geometry field, DataOutput data) throws IOException { WKBWriter wkbWriter = new WKBWriter(); byte[] bytes = wkbWriter.write(field); writeByteArray(bytes, data); }
@Override public String[] readStringArray(DataInput in) throws IOException { final int len = readUnsignedVarInt(in); String[] strings = new String[len]; for (int i = 0; i < len; i++) { strings[i] = readString(in); } return strings; }