本文整理汇总了Java中io.protostuff.Schema.writeTo方法的典型用法代码示例。如果您正苦于以下问题:Java Schema.writeTo方法的具体用法?Java Schema.writeTo怎么用?Java Schema.writeTo使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类io.protostuff.Schema
的用法示例。
在下文中一共展示了Schema.writeTo方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: encodeWithLengthAndCrc
import io.protostuff.Schema; //导入方法依赖的package包/类
/**
* Serialize a protostuff message object, prefixed with message length, and suffixed with a 4-byte CRC.
*
* @param schema Protostuff message schema
* @param message Object to serialize
* @param <T> Message type
* @return A list of ByteBuffers containing a varInt length, followed by the message, followed by a 4-byte CRC.
*/
public static <T> List<ByteBuffer> encodeWithLengthAndCrc(Schema<T> schema, T message) {
final LinkBuffer messageBuf = new LinkBuffer();
final LowCopyProtobufOutput lcpo = new LowCopyProtobufOutput(messageBuf);
try {
schema.writeTo(lcpo, message);
final int length = Ints.checkedCast(lcpo.buffer.size());
final LinkBuffer lengthBuf = new LinkBuffer().writeVarInt32(length);
return appendCrcToBufferList(
Lists.newArrayList(
Iterables.concat(lengthBuf.finish(), messageBuf.finish()))
);
} catch (IOException e) {
// This method performs no IO, so it should not actually be possible for an IOException to be thrown.
// But just in case...
throw new RuntimeException(e);
}
}
示例2: encode
import io.protostuff.Schema; //导入方法依赖的package包/类
@Override
protected void encode(ChannelHandlerContext ctx, Message<T> msg, List<Object> out) throws Exception {
Schema<T> schema = msg.cachedSchema();
LowCopyProtobufOutput lcpo = new LowCopyProtobufOutput();
schema.writeTo(lcpo, (T) msg);
List<ByteBuffer> buffers = lcpo.buffer.finish();
long size = lcpo.buffer.size();
if (size > Integer.MAX_VALUE) {
throw new EncoderException("Serialized form was too large, actual size: " + size);
}
out.add(Unpooled.wrappedBuffer(buffers.toArray(new ByteBuffer[]{})));
}
示例3: writeTo
import io.protostuff.Schema; //导入方法依赖的package包/类
/**
* Delegates to the schema derived from the {@code value}.
*/
@Override
@SuppressWarnings("unchecked")
public void writeTo(final Output output, final Object value)
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, this);
}
// write the rest of the fields of the exact type
schema.writeTo(output, value);
}
示例4: writeObjectTo
import io.protostuff.Schema; //导入方法依赖的package包/类
@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);
}
示例5: writeObjectTo
import io.protostuff.Schema; //导入方法依赖的package包/类
@SuppressWarnings("unchecked")
static void writeObjectTo(Output output, Object value,
Schema<?> currentSchema, IdStrategy strategy) throws IOException
{
final HasSchema<Object> hs = strategy.tryWritePojoIdTo(output, ID_POJO,
(Class<Object>)value.getClass(), true);
if (hs == null)
{
PolymorphicMapSchema.writeObjectTo(output, value, currentSchema, strategy);
return;
}
final Schema<Object> schema = hs.getSchema();
if (output instanceof StatefulOutput)
{
// update using the derived schema.
((StatefulOutput) output).updateLast(schema, currentSchema);
}
schema.writeTo(output, value);
}
示例6: writeObjectTo
import io.protostuff.Schema; //导入方法依赖的package包/类
@SuppressWarnings("unchecked")
static void writeObjectTo(Output output, Object value,
Schema<?> currentSchema, IdStrategy strategy) throws IOException
{
final HasSchema<Object> hs = strategy.tryWritePojoIdTo(output, ID_POJO,
(Class<Object>)value.getClass(), true);
if (hs == null)
{
PolymorphicCollectionSchema.writeObjectTo(output, value, currentSchema,
strategy);
return;
}
final Schema<Object> schema = hs.getSchema();
if (output instanceof StatefulOutput)
{
// update using the derived schema.
((StatefulOutput) output).updateLast(schema, currentSchema);
}
schema.writeTo(output, value);
}
示例7: serializeObject
import io.protostuff.Schema; //导入方法依赖的package包/类
@SuppressWarnings("unchecked")
public void serializeObject(Buffer buffer, Object tc) {
ZeroCopyLinkBuffer zeroCopyLinkBuffer = linkedBuff.get();
LowCopyProtostuffOutput lowCopyProtostuffOutput = output.get();
zeroCopyLinkBuffer.withBuffer(buffer);
lowCopyProtostuffOutput.buffer = zeroCopyLinkBuffer;
long crc = crcNames.get(tc.getClass());
ProtoTransactionTypeHolder ptth = registeredCrc.get(crc);
if (ptth.crcCollision) {
byte[] key = sha1Names.get(tc.getClass());
ptth = registeredSha1.get(key);
buffer.writeByte(SHA1_TYPE);
buffer.writeBytes(key, 0, SHA1_DIGEST_SIZE);
} else {
buffer.writeByte(CRC32_TYPE);
buffer.writeLong(crc);
}
buffer.markSize();
Schema<Object> schema = (Schema<Object>) ptth.schema;
try {
schema.writeTo(lowCopyProtostuffOutput, tc);
} catch (IOException e) {
throw new RuntimeException(e);
}
buffer.writeSize();
}
示例8: writeObjectTo
import io.protostuff.Schema; //导入方法依赖的package包/类
@SuppressWarnings("unchecked")
static void writeObjectTo(Output output, Object value,
Schema<?> currentSchema, IdStrategy strategy) throws IOException
{
final Class<Object> clazz = (Class<Object>) value.getClass();
final RuntimeFieldFactory<Object> inline = RuntimeFieldFactory
.getInline(clazz);
if (inline != null)
{
// scalar value
inline.writeTo(output, inline.id, value, false);
return;
}
// AtomicInteger/AtomicLong
final Schema<Object> schema = strategy.writePojoIdTo(output, ID_POJO,
clazz).getSchema();
if (output instanceof StatefulOutput)
{
// update using the derived schema.
((StatefulOutput) output).updateLast(schema, currentSchema);
}
schema.writeTo(output, value);
}
示例9: writeObjectTo
import io.protostuff.Schema; //导入方法依赖的package包/类
@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);
}