@Override public void writeTo(Output output, T message) throws IOException { schema.writeTo(output, message); }
/** * Serializes the {@code message} into a JsonGenerator using the given {@code schema}. */ public static <T> void writeTo(JsonGenerator generator, T message, Schema<T> schema, boolean numeric) throws IOException { generator.writeStartObject(); final JsonOutput output = new JsonOutput(generator, numeric, schema); schema.writeTo(output, message); if (output.isLastRepeated()) generator.writeEndArray(); generator.writeEndObject(); }
/** * Serializes the {@code message} into an {@link XMLStreamWriter} using the given {@code schema}. */ public static <T> void writeTo(XMLStreamWriter writer, T message, Schema<T> schema) throws IOException, XMLStreamException, XmlOutputException { writer.writeStartElement(schema.messageName()); schema.writeTo(new XmlOutput(writer, schema), message); writer.writeEndElement(); }
/** * 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); }
@SuppressWarnings("unchecked") static void writeObjectTo(Output output, Object value, Schema<?> currentSchema, IdStrategy strategy) throws IOException { final Schema<Object> schema = strategy.writePojoIdTo(output, ID_POJO, (Class<Object>) value.getClass()).getSchema(); if (output instanceof StatefulOutput) { // update using the derived schema. ((StatefulOutput) output).updateLast(schema, currentSchema); } schema.writeTo(output, value); }
@SuppressWarnings("unchecked") @Override public <T> OutputBuf writeObject(OutputBuf outputBuf, T obj) { Schema<T> schema = RuntimeSchema.getSchema((Class<T>) obj.getClass()); Output output = Outputs.getOutput(outputBuf); try { schema.writeTo(output, obj); } catch (IOException e) { ThrowUtil.throwException(e); } return outputBuf; }
@SuppressWarnings("unchecked") @Override public <T> OutputBuf writeObject(OutputBuf outputBuf, T obj) { Schema<T> schema = RuntimeSchema.getSchema((Class<T>) obj.getClass()); Output output = Outputs.getOutput(outputBuf); try { schema.writeTo(output, obj); } catch (IOException e) { ThrowUtil.throwException(e); } return outputBuf; }
@SuppressWarnings("unchecked") static void writeObjectTo(Output output, Object value, Schema<?> currentSchema, IdStrategy strategy) throws IOException { final Schema<Object> schema = strategy.writePojoIdTo(output, ID_POJO, (Class<Object>) value.getClass()).getSchema(); if (output instanceof StatefulOutput) { // update using the derived schema. ((StatefulOutput) output).updateLast(schema, currentSchema); } schema.writeTo(output, value); }
public static <T> void writeTo(MessagePacker packer, T message, Schema<T> schema, boolean numeric) throws IOException { MsgpackGenerator generator = new MsgpackGenerator(numeric); MsgpackOutput output = new MsgpackOutput(generator, schema); schema.writeTo(output, message); generator.writeTo(packer); }
@SuppressWarnings("unchecked") static void writeObjectTo(Output output, Object value, Schema<?> currentSchema, IdStrategy strategy) throws IOException { final Schema<Object> schema = strategy.writePojoIdTo(output, ID_THROWABLE, (Class<Object>) value.getClass()).getSchema(); if (output instanceof StatefulOutput) { // update using the derived schema. ((StatefulOutput) output).updateLast(schema, currentSchema); } if (tryWriteWithoutCause(output, value, schema)) return; schema.writeTo(output, value); }
@Override public <T> void writeObject(final int fieldNumber, final T value, final Schema<T> schema, final boolean repeated) throws IOException { buffer.writeVarInt32(makeTag(fieldNumber, WIRETYPE_START_GROUP)); schema.writeTo(this, value); buffer.writeVarInt32(makeTag(fieldNumber, WIRETYPE_END_GROUP)); }
@Override public <T> void writeObject(int fieldNumber, T value, Schema<T> schema, boolean repeated) throws IOException { writeVarInt32(makeTag(fieldNumber, WIRETYPE_START_GROUP)); schema.writeTo(this, value); writeVarInt32(makeTag(fieldNumber, WIRETYPE_END_GROUP)); }
@Override public <T> void writeObject(int fieldNumber, T value, Schema<T> schema, boolean repeated) throws IOException { writeVarInt32(makeTag(fieldNumber, WIRETYPE_START_GROUP)); schema.writeTo(this, value); writeVarInt32(makeTag(fieldNumber, WIRETYPE_END_GROUP)); }
@Override public <T> void writeObject(final int fieldNumber, final T value, final Schema<T> schema, final boolean repeated) throws IOException { tail = sink.writeVarInt32( makeTag(fieldNumber, WIRETYPE_START_GROUP), this, tail); schema.writeTo(this, value); tail = sink.writeVarInt32( makeTag(fieldNumber, WIRETYPE_END_GROUP), this, tail); }
/** * Serializes the {@code messages} into the generator using the given schema. */ public static <T> void writeListTo(MessagePacker packer, List<T> messages, Schema<T> schema, boolean numeric) throws IOException { MsgpackGenerator generator = new MsgpackGenerator(numeric); MsgpackOutput output = new MsgpackOutput(generator, schema); for (T m : messages) { schema.writeTo(output, m); generator.writeTo(packer); generator.reset(); } }
/** * Write the nested message encoded as group. */ <T> void writeObjectEncodedAsGroup(final int fieldNumber, final T value, final Schema<T> schema, boolean repeated) throws IOException { writeTag(fieldNumber, WireFormat.WIRETYPE_START_GROUP); schema.writeTo(this, value); writeTag(fieldNumber, WireFormat.WIRETYPE_END_GROUP); }
@Override public <T> void writeObject(int fieldNumber, T value, Schema<T> innerSchema, boolean repeated) throws IOException { MsgpackGenerator innerGenerator = new MsgpackGenerator(generator.isNumeric()); MsgpackGenerator thisGenerator = this.generator; Schema<?> thisSchema = this.schema; use(innerGenerator, innerSchema); innerSchema.writeTo(this, value); use(thisGenerator, thisSchema); generator.pushValue(this.schema, fieldNumber, innerGenerator.toValue(), repeated); }
@Override protected <T> void writeDelimitedTo(OutputStream out, T message, Schema<T> schema) throws IOException { final ComputedSizeOutput sizeCount = new ComputedSizeOutput(false); schema.writeTo(sizeCount, message); CodedOutput.writeRawVarInt32Bytes(out, sizeCount.getSize()); final CodedOutput output = CodedOutput.newInstance(out); schema.writeTo(output, message); output.flush(); }
static <T> byte[] toByteArrayBufferedProtostuff(T message, Schema<T> schema) { final ProtostuffOutput output = new ProtostuffOutput(new LinkedBuffer(BUF_SIZE)); try { schema.writeTo(output, message); } catch (IOException e) { throw new RuntimeException("Serializing to a byte array threw an IOException " + "(should never happen).", e); } return output.toByteArray(); }
<T> void writeObjectEncodedAsGroup(int fieldNumber, T value, Schema<T> schema, boolean repeated) throws IOException { size += ProtobufOutput.computeRawVarint32Size(WireFormat.makeTag(fieldNumber, WireFormat.WIRETYPE_START_GROUP)); schema.writeTo(this, value); size += ProtobufOutput.computeRawVarint32Size(WireFormat.makeTag(fieldNumber, WireFormat.WIRETYPE_END_GROUP)); }