io.protostuff.Schema.writeTo()方法的使用及代码示例

x33g5p2x  于2022-01-30 转载在 其他  
字(8.0k)|赞(0)|评价(0)|浏览(145)

本文整理了Java中io.protostuff.Schema.writeTo()方法的一些代码示例,展示了Schema.writeTo()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Schema.writeTo()方法的具体详情如下:
包路径:io.protostuff.Schema
类名称:Schema
方法名:writeTo

Schema.writeTo介绍

[英]Serializes a message/object to the Output.
[中]将消息/对象序列化到输出。

代码示例

代码示例来源:origin: protostuff/protostuff

@Override
public void writeTo(Output output, T message) throws IOException
{
  schema.writeTo(output, message);
}

代码示例来源:origin: protostuff/protostuff

/**
 * 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();
}

代码示例来源:origin: protostuff/protostuff

/**
 * 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();
}

代码示例来源:origin: protostuff/protostuff

/**
 * 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);
}

代码示例来源:origin: protostuff/protostuff

@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);
}

代码示例来源:origin: fengjiachun/Jupiter

@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;
}

代码示例来源:origin: fengjiachun/Jupiter

@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;
}

代码示例来源:origin: protostuff/protostuff

@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);
}

代码示例来源:origin: protostuff/protostuff

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);
}

代码示例来源:origin: protostuff/protostuff

@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);
}

代码示例来源:origin: protostuff/protostuff

@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));
}

代码示例来源:origin: fengjiachun/Jupiter

@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));
}

代码示例来源:origin: fengjiachun/Jupiter

@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));
}

代码示例来源:origin: protostuff/protostuff

@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);
}

代码示例来源:origin: protostuff/protostuff

/**
 * 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();
  }
}

代码示例来源:origin: protostuff/protostuff

/**
 * 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);
}

代码示例来源:origin: protostuff/protostuff

@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);
}

代码示例来源:origin: protostuff/protostuff

@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();
}

代码示例来源:origin: protostuff/protostuff

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();
}

代码示例来源:origin: protostuff/protostuff

<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));
}

相关文章