/** * Serializes the {@code message} into an {@link OutputStream} using the given schema. * * @return the size of the message */ public static <T> int writeTo(OutputStream out, T message, Schema<T> schema, LinkedBuffer buffer) throws IOException { if(buffer.start != buffer.offset) throw new IllegalArgumentException("Buffer previously used and had not been reset."); final ProtobufOutput output = new ProtobufOutput(buffer); schema.writeTo(output, message); return LinkedBuffer.writeTo(out, buffer); }
/** * Serializes the {@code message} into an {@link OutputStream} using the given schema. * * @return the size of the message */ public static <T> int writeTo(final OutputStream out, final T message, final Schema<T> schema, final LinkedBuffer buffer) throws IOException { if(buffer.start != buffer.offset) throw new IllegalArgumentException("Buffer previously used and had not been reset."); final ProtostuffOutput output = new ProtostuffOutput(buffer, out); schema.writeTo(output, message); LinkedBuffer.writeTo(out, buffer); return output.size; }
/** * Serializes the {@code message}, prefixed with its length, into an * {@link OutputStream}. * * @return the size of the message */ public static <T> int writeDelimitedTo(final OutputStream out, final T message, final Schema<T> schema, final LinkedBuffer buffer) throws IOException { if(buffer.start != buffer.offset) throw new IllegalArgumentException("Buffer previously used and had not been reset."); final ProtostuffOutput output = new ProtostuffOutput(buffer); schema.writeTo(output, message); ProtobufOutput.writeRawVarInt32Bytes(out, output.size); LinkedBuffer.writeTo(out, buffer); return output.size; }
/** * Serializes the {@code message} into an {@link OutputStream} using the given schema. * * @return the size of the message */ public static <T> int writeTo(final OutputStream out, final T message, final Schema<T> schema, final LinkedBuffer buffer) throws IOException { if(buffer.start != buffer.offset) throw new IllegalArgumentException("Buffer previously used and had not been reset."); final ProtostuffOutput output = new ProtostuffOutput(buffer, out); final GraphProtostuffOutput graphOutput = new GraphProtostuffOutput(output); schema.writeTo(graphOutput, message); LinkedBuffer.writeTo(out, buffer); return output.size; }
LinkedBuffer.writeTo(out, buffer.next);
LinkedBuffer.writeTo(out, buffer.next);
/** * Serializes the {@code message}, prefixed with its length, into an * {@link OutputStream}. * * @return the size of the message */ public static <T> int writeDelimitedTo(OutputStream out, T message, Schema<T> schema, LinkedBuffer buffer) throws IOException { if(buffer.start != buffer.offset) throw new IllegalArgumentException("Buffer previously used and had not been reset."); final ProtobufOutput output = new ProtobufOutput(buffer); schema.writeTo(output, message); final int size = output.getSize(); ProtobufOutput.writeRawVarInt32Bytes(out, size); final int msgSize = LinkedBuffer.writeTo(out, buffer); assert size == msgSize; return size; }
/** * Serializes the {@code messages} (delimited) into an {@link OutputStream} * using the given schema. * * @return the bytes written */ public static <T> int writeListTo(final OutputStream out, final List<T> messages, final Schema<T> schema, final LinkedBuffer buffer) throws IOException { if(buffer.start != buffer.offset) throw new IllegalArgumentException("Buffer previously used and had not been reset."); final int size = messages.size(); if(size == 0) return 0; final ProtostuffOutput output = new ProtostuffOutput(buffer, out); output.sink.writeVarInt32(size, output, buffer); for(T m : messages) { schema.writeTo(output, m); output.sink.writeByte((byte)WireFormat.WIRETYPE_TAIL_DELIMITER, output, buffer); } LinkedBuffer.writeTo(out, buffer); return output.size; }
/** * Serializes the {@code message}, prefixed with its length, into an * {@link OutputStream}. * * @return the size of the message */ public static <T> int writeDelimitedTo(final OutputStream out, final T message, final Schema<T> schema, final LinkedBuffer buffer) throws IOException { if(buffer.start != buffer.offset) throw new IllegalArgumentException("Buffer previously used and had not been reset."); final ProtostuffOutput output = new ProtostuffOutput(buffer); final GraphProtostuffOutput graphOutput = new GraphProtostuffOutput(output); schema.writeTo(graphOutput, message); ProtobufOutput.writeRawVarInt32Bytes(out, output.size); LinkedBuffer.writeTo(out, buffer); return output.size; }
LinkedBuffer.writeTo(out, buffer.next);
@SuppressWarnings({ "unchecked", "rawtypes" }) private <T> void encode(OutputStream out, T object) throws IOException { LinkedBuffer buffer = LinkedBuffer.allocate(4096); Schema schema = null; if (null == object) { schema = SchemaCache.getSchema(Object.class); } else { schema = SchemaCache.getSchema(object.getClass()); } // write the length header int length = writeObject(buffer, object, schema); IOUtils.writeInt(out, length); // write content LinkedBuffer.writeTo(out, buffer); }
/** * Used by the code generated messages that implement {@link java.io.Externalizable}. * Writes to the {@link DataOutput}. * * @return the size of the message. */ public static <T> int writeDelimitedTo(DataOutput out, T message, Schema<T> schema) throws IOException { final LinkedBuffer buffer = new LinkedBuffer(LinkedBuffer.MIN_BUFFER_SIZE); final ProtostuffOutput output = new ProtostuffOutput(buffer); schema.writeTo(output, message); ProtobufOutput.writeRawVarInt32Bytes(out, output.size); LinkedBuffer.writeTo(out, buffer); return output.size; }
/** * Serializes the {@code message} into an {@link OutputStream} via {@link JsonXOutput} * using the given {@code schema}. */ public static <T> void writeTo(OutputStream out, T message, Schema<T> schema, boolean numeric, LinkedBuffer buffer) throws IOException { if(buffer.start != buffer.offset) throw new IllegalArgumentException("Buffer previously used and had not been reset."); final JsonXOutput output = new JsonXOutput(buffer, out, numeric, schema); output.writeStartObject(); schema.writeTo(output, message); if(output.isLastRepeated()) output.writeEndArray(); output.writeEndObject(); LinkedBuffer.writeTo(out, buffer); }
/** * Serializes the {@code messages} (delimited) into an {@link OutputStream} * using the given schema. * * @return the total size of the messages (excluding the length prefix varint) */ public static <T> int writeListTo(OutputStream out, List<T> messages, Schema<T> schema, LinkedBuffer buffer) throws IOException { if(buffer.start != buffer.offset) throw new IllegalArgumentException("Buffer previously used and had not been reset."); final ProtobufOutput output = new ProtobufOutput(buffer); int totalSize = 0; for(T m : messages) { schema.writeTo(output, m); final int size = output.getSize(); ProtobufOutput.writeRawVarInt32Bytes(out, size); final int msgSize = LinkedBuffer.writeTo(out, buffer); assert size == msgSize; totalSize += size; output.clear(); } return totalSize; }
/** * Used by the code generated messages that implement {@link java.io.Externalizable}. * Writes to the {@link DataOutput}. * * @return the size of the message. */ public static <T> int writeDelimitedTo(DataOutput out, T message, Schema<T> schema) throws IOException { final LinkedBuffer buffer = new LinkedBuffer(LinkedBuffer.MIN_BUFFER_SIZE); final ProtobufOutput output = new ProtobufOutput(buffer); schema.writeTo(output, message); final int size = output.getSize(); ProtobufOutput.writeRawVarInt32Bytes(out, size); final int msgSize = LinkedBuffer.writeTo(out, buffer); assert size == msgSize; return size; }
/** * Used by the code generated messages that implement {@link java.io.Externalizable}. * Writes to the {@link DataOutput}. * * @return the size of the message. */ public static <T> int writeDelimitedTo(DataOutput out, T message, Schema<T> schema) throws IOException { final LinkedBuffer buffer = new LinkedBuffer(LinkedBuffer.MIN_BUFFER_SIZE); final ProtostuffOutput output = new ProtostuffOutput(buffer); final GraphProtostuffOutput graphOutput = new GraphProtostuffOutput(output); schema.writeTo(graphOutput, message); ProtobufOutput.writeRawVarInt32Bytes(out, output.size); LinkedBuffer.writeTo(out, buffer); return output.size; }
/** * Serializes the {@code message} into an {@link OutputStream} * with the supplied buffer. * * @return the total bytes written to the output. */ public static <T> int writeTo(OutputStream out, T message, Schema<T> schema, LinkedBuffer buffer) throws IOException { if(buffer.start != buffer.offset) throw new IllegalArgumentException("Buffer previously used and had not been reset."); final YamlOutput output = new YamlOutput(buffer, out, schema); output.tail = YamlOutput.writeTag( schema.messageName(), false, output.sink, output, output.sink.writeByteArray( START_DIRECTIVE, output, buffer)); schema.writeTo(output, message); LinkedBuffer.writeTo(out, buffer); return output.getSize(); }
LinkedBuffer.writeTo(out, buffer);
LinkedBuffer.writeTo(out, buffer);
output.sink.writeByteArray(XmlXOutput.START_SLASH_TAG, output, output.tail))); LinkedBuffer.writeTo(out, buffer);