public static <T> T fromKryo(byte[] value, Class<T> clazz) { E.checkState(value != null, "Kryo value can't be null for '%s'", clazz.getSimpleName()); return kryo().readObject(new Input(value), clazz); } }
protected BackendColumn formatProperty(HugeProperty<?> prop) { return BackendColumn.of(this.formatPropertyName(prop), KryoUtil.toKryo(prop.value())); }
protected void parseProperty(Id pkeyId, byte[] val, HugeElement owner) { PropertyKey pkey = owner.graph().propertyKey(pkeyId); // Parse value Object value = KryoUtil.fromKryo(val, pkey.clazz()); // Set properties of vertex/edge if (pkey.cardinality() == Cardinality.SINGLE) { owner.addProperty(pkey, value); } else { if (!(value instanceof Collection)) { throw new BackendException( "Invalid value of non-single property: %s", value); } for (Object v : (Collection<?>) value) { owner.addProperty(pkey, v); } } }
protected void parseProperty(Id pkeyId, byte[] val, HugeElement owner) { PropertyKey pkey = owner.graph().propertyKey(pkeyId); // Parse value Object value = KryoUtil.fromKryo(val, pkey.clazz()); // Set properties of vertex/edge if (pkey.cardinality() == Cardinality.SINGLE) { owner.addProperty(pkey, value); } else { if (!(value instanceof Collection)) { throw new BackendException( "Invalid value of non-single property: %s", value); } for (Object v : (Collection<?>) value) { owner.addProperty(pkey, v); } } }
public static byte[] toKryo(Object value) { try (ByteArrayOutputStream bos = new ByteArrayOutputStream(); Output output = new Output(bos, 256)) { kryo().writeObject(output, value); output.flush(); return bos.toByteArray(); } catch (IOException e) { throw new BackendException("Failed to serialize: %s", e, value); } }
protected byte[] formatEdgeValue(HugeEdge edge) { int propsCount = edge.getProperties().size(); BytesBuffer buffer = BytesBuffer.allocate(4 + 16 * propsCount); // Write edge id //buffer.writeId(edge.id()); // Write edge properties size buffer.writeInt(propsCount); // Write edge properties data for (HugeProperty<?> property : edge.getProperties().values()) { buffer.writeId(property.propertyKey().id()); buffer.writeBytes(KryoUtil.toKryo(property.value())); } return buffer.bytes(); }
public static <T> T fromKryo(byte[] value, Class<T> clazz) { E.checkState(value != null, "Kryo value can't be null for '%s'", clazz.getSimpleName()); return kryo().readObject(new Input(value), clazz); } }
protected BackendColumn formatProperty(HugeProperty<?> prop) { return BackendColumn.of(this.formatPropertyName(prop), KryoUtil.toKryo(prop.value())); }
public static byte[] toKryo(Object value) { try (ByteArrayOutputStream bos = new ByteArrayOutputStream(); Output output = new Output(bos, 256)) { kryo().writeObject(output, value); output.flush(); return bos.toByteArray(); } catch (IOException e) { throw new BackendException("Failed to serialize: %s", e, value); } }
protected byte[] formatEdgeValue(HugeEdge edge) { int propsCount = edge.getProperties().size(); BytesBuffer buffer = BytesBuffer.allocate(4 + 16 * propsCount); // Write edge id //buffer.writeId(edge.id()); // Write edge properties size buffer.writeInt(propsCount); // Write edge properties data for (HugeProperty<?> property : edge.getProperties().values()) { buffer.writeId(property.propertyKey().id()); buffer.writeBytes(KryoUtil.toKryo(property.value())); } return buffer.bytes(); }