public void readExternal(ObjectInput in) throws IOException { GraphIOUtil.mergeDelimitedFrom(in, this, this); }
public void writeExternal(ObjectOutput out) throws IOException { GraphIOUtil.writeDelimitedTo(out, this, this); }
/** * Merges the {@code message} with the byte array using the given {@code schema}. */ public static <T> void mergeFrom(byte[] data, T message, Schema<T> schema) { mergeFrom(data, 0, data.length, message, schema); }
public void testGraph() { System.err.println(RuntimeEnv.COLLECTION_SCHEMA_ON_REPEATED_FIELDS); Bean bean = fill(new Bean()); verify(bean); Schema<Bean> schema = RuntimeSchema.getSchema(Bean.class); // print(schema); byte[] bytes = GraphIOUtil.toByteArray(bean, schema, LinkedBuffer.allocate(256)); Bean deBean = new Bean(); GraphIOUtil.mergeFrom(bytes, deBean, schema); verify(deBean); }
@SuppressWarnings("unchecked") @Override public void writeObject(Object obj) throws IOException { byte[] bytes; byte[] classNameBytes; try { if (WrapperUtils.needWrapper(obj)) { Schema<Wrapper> schema = RuntimeSchema.getSchema(Wrapper.class); Wrapper wrapper = new Wrapper(obj); bytes = GraphIOUtil.toByteArray(wrapper, schema, buffer); classNameBytes = Wrapper.class.getName().getBytes(); } else { Schema schema = RuntimeSchema.getSchema(obj.getClass()); bytes = GraphIOUtil.toByteArray(obj, schema, buffer); classNameBytes = obj.getClass().getName().getBytes(); } } finally { buffer.clear(); } dos.writeInt(classNameBytes.length); dos.writeInt(bytes.length); dos.write(classNameBytes); dos.write(bytes); }
/** * Optimal/Optional mergeDelimitedFrom - If the message does not fit the buffer, no merge is done and this method * will return false. * <p> * This is strictly for reading a single message from the stream because the buffer is aggressively filled when * reading the delimited size (which could result into reading more bytes than it has to). * <p> * The remaining bytes will be drained (consumed and discared) when the message is too large. */ public static <T> boolean optMergeDelimitedFrom(InputStream in, T message, Schema<T> schema, LinkedBuffer buffer) throws IOException { return optMergeDelimitedFrom(in, message, schema, true, buffer); }
@Override public void serialize(Object object, OutputStream outputStream) throws IOException { GraphIOUtil.writeTo(outputStream, new Wrapper(object), wrapperSchema, LinkedBuffer.allocate()); }
public void testBeanCyclic() { System.err.println(RuntimeEnv.COLLECTION_SCHEMA_ON_REPEATED_FIELDS); Bean bean = fillCyclic(new Bean()); verifyCyclic(bean); Schema<Bean> schema = RuntimeSchema.getSchema(Bean.class); // print(schema); byte[] bytes = GraphIOUtil.toByteArray(bean, schema, LinkedBuffer.allocate(256)); Bean deBean = new Bean(); GraphIOUtil.mergeFrom(bytes, deBean, schema); verifyCyclic(deBean); }
@SuppressWarnings("unchecked") @Override public void writeObject(Object obj) throws IOException { byte[] bytes; byte[] classNameBytes; try { if (WrapperUtils.needWrapper(obj)) { Schema<Wrapper> schema = RuntimeSchema.getSchema(Wrapper.class); Wrapper wrapper = new Wrapper(obj); bytes = GraphIOUtil.toByteArray(wrapper, schema, buffer); classNameBytes = Wrapper.class.getName().getBytes(); } else { Schema schema = RuntimeSchema.getSchema(obj.getClass()); bytes = GraphIOUtil.toByteArray(obj, schema, buffer); classNameBytes = obj.getClass().getName().getBytes(); } } finally { buffer.clear(); } dos.writeInt(classNameBytes.length); dos.writeInt(bytes.length); dos.write(classNameBytes); dos.write(bytes); }
@Override protected <T> boolean optMergeDelimitedFrom(InputStream in, T message, Schema<T> schema, LinkedBuffer buffer) throws IOException { return GraphIOUtil.optMergeDelimitedFrom(in, message, schema, buffer); }
public void readExternal(ObjectInput in) throws IOException { GraphIOUtil.mergeDelimitedFrom(in, this, this); }
public void writeExternal(ObjectOutput out) throws IOException { GraphIOUtil.writeDelimitedTo(out, this, this); }
public static <T> void mergeFrom(InputStream in, T message, Schema<T> schema) throws IOException { GraphIOUtil.mergeFrom(in, message, schema); }
public static <T> byte[] toByteArray(T message, Schema<T> schema) throws IOException { return GraphIOUtil.toByteArray(message, schema, buf()); }
public void readExternal(ObjectInput in) throws IOException { GraphIOUtil.mergeDelimitedFrom(in, this, this); }
public void writeExternal(ObjectOutput out) throws IOException { GraphIOUtil.writeDelimitedTo(out, this, this); }
public static <T> void mergeFrom(byte[] data, int offset, int length, T message, Schema<T> schema) throws IOException { GraphIOUtil.mergeFrom(data, offset, length, message, schema); }
private static <T> byte[] serializeGraph(T object) { @SuppressWarnings("unchecked") Class<T> clazz = (Class<T>) object.getClass(); Schema<T> schema = RuntimeSchema.getSchema(clazz); return GraphIOUtil.toByteArray(object, schema, LinkedBuffer.allocate()); }
@Override public void readExternal(ObjectInput in) throws IOException { GraphIOUtil.mergeDelimitedFrom(in, this, this); }