本文整理汇总了Java中io.protostuff.Output类的典型用法代码示例。如果您正苦于以下问题:Java Output类的具体用法?Java Output怎么用?Java Output使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Output类属于io.protostuff包,在下文中一共展示了Output类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: writeTo
import io.protostuff.Output; //导入依赖的package包/类
@Override
@SuppressWarnings("unchecked")
protected void writeTo(Output output, T message) throws IOException {
if (!ProtobufFeatureUtils.isUseProtobufMapCodec()) {
runtimeMapField.writeTo(output, message);
return;
}
final Map<Object, Object> existing;
try {
existing = (Map<Object, Object>) field.get(message);
} catch (Exception e) {
throw new RuntimeException(e);
}
if (existing != null) {
for (Entry<Object, Object> entry : existing.entrySet()) {
output.writeObject(number, entry, entrySchema, true);
}
}
}
示例2: writeUnmodifiableCollectionTo
import io.protostuff.Output; //导入依赖的package包/类
private static void writeUnmodifiableCollectionTo(Output output,
Object value, Schema<?> currentSchema, IdStrategy strategy, int id)
throws IOException
{
final Object c;
try
{
c = fUnmodifiableCollection_c.get(value);
}
catch (IllegalArgumentException | IllegalAccessException e)
{
throw new RuntimeException(e);
}
output.writeObject(id, c, strategy.POLYMORPHIC_COLLECTION_SCHEMA, false);
}
示例3: writeObjectTo
import io.protostuff.Output; //导入依赖的package包/类
static void writeObjectTo(Output output, Object value,
Schema<?> currentSchema, IdStrategy strategy) throws IOException
{
final Class<?> c = ((Class<?>) value);
if (c.isArray())
{
int dimensions = 1;
Class<?> componentType = c.getComponentType();
while (componentType.isArray())
{
dimensions++;
componentType = componentType.getComponentType();
}
strategy.writeClassIdTo(output, componentType, true);
// write the dimensions of the array
output.writeUInt32(ID_ARRAY_DIMENSION, dimensions, false);
return;
}
strategy.writeClassIdTo(output, c, false);
}
示例4: writeCollectionIdTo
import io.protostuff.Output; //导入依赖的package包/类
@Override
protected void writeCollectionIdTo(Output output, int fieldNumber,
Class<?> clazz) throws IOException
{
final CollectionSchema.MessageFactory factory = collectionMapping
.get(clazz);
if (factory == null && clazz.getName().startsWith("java.util"))
{
// jdk collection
// better not to register the jdk collection if using this strategy
// as it saves space by not writing the full package
output.writeString(fieldNumber, clazz.getSimpleName(), false);
}
else
{
output.writeString(fieldNumber, clazz.getName(), false);
}
}
示例5: writeObjectTo
import io.protostuff.Output; //导入依赖的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);
}
示例6: writeMessageIdTo
import io.protostuff.Output; //导入依赖的package包/类
@Override
@SuppressWarnings("unchecked")
protected <T> Schema<T> writeMessageIdTo(Output output, int fieldNumber,
Message<T> message) throws IOException
{
int id;
BaseHS<T> wrapper = (BaseHS<T>) getSchemaWrapper(message.getClass(), true);
// wait till everything is completely set
while (0 == (id = wrapper.id))
LockSupport.parkNanos(1);
output.writeUInt32(fieldNumber, id, false);
// TODO allow the wrapper to return an override schema?
return message.cachedSchema();
}
示例7: writeTo
import io.protostuff.Output; //导入依赖的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);
}
示例8: writeObjectTo
import io.protostuff.Output; //导入依赖的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);
}
示例9: writeUnmodifiableMapTo
import io.protostuff.Output; //导入依赖的package包/类
private static void writeUnmodifiableMapTo(Output output, Object value,
Schema<?> currentSchema, IdStrategy strategy, int id)
throws IOException
{
final Object m;
try
{
m = fUnmodifiableMap_m.get(value);
}
catch (IllegalArgumentException | IllegalAccessException e)
{
throw new RuntimeException(e);
}
output.writeObject(id, m, strategy.POLYMORPHIC_MAP_SCHEMA, false);
}
示例10: writeObject
import io.protostuff.Output; //导入依赖的package包/类
default void writeObject(Output output, Object value, ProtobufFeature protobufFeature) throws Exception {
ProtobufFeatureUtils.setProtobufFeature(protobufFeature);
try {
writeObject(output, value);
} finally {
ProtobufFeatureUtils.removeProtobufFeature();
}
}
示例11: writeObject
import io.protostuff.Output; //导入依赖的package包/类
public void writeObject(Output output, Object value) throws IOException {
if (value == null) {
return;
}
schema.writeTo(output, value);
}
示例12: writeObject
import io.protostuff.Output; //导入依赖的package包/类
public void writeObject(Output output, Object value) throws IOException {
if (value == null) {
return;
}
SingleWrapper wrapper = (SingleWrapper) schema.newMessage();
wrapper.writeField(value);
schema.writeTo(output, wrapper);
}
示例13: writeObject
import io.protostuff.Output; //导入依赖的package包/类
public void writeObject(Output output, Object value) throws IOException {
Object writeValue = ((Object[]) value)[0];
if (writeValue == null) {
return;
}
schema.writeTo(output, writeValue);
}
示例14: writeTo
import io.protostuff.Output; //导入依赖的package包/类
@Override
public void writeTo(Output output, Message message) throws IOException {
// Write headers
if (!message.headers().isEmpty()) {
for (Map.Entry<String, String> headerEntry : message.headers().entrySet()) {
if (headerEntry.getKey() != null && headerEntry.getValue() != null) {
output.writeString(HEADER_KEYS_FIELD_NUMBER, headerEntry.getKey(), true);
output.writeString(HEADER_VALUES_FIELD_NUMBER, headerEntry.getValue(), true);
}
}
}
// Write data
Object originalData = message.data();
if (originalData != null) {
if (originalData instanceof byte[]) {
// Write data byte array as is
output.writeByteArray(DATA_FIELD_NUMBER, (byte[]) originalData, false);
} else {
// Write data class as an additional header
Class<?> dataClass = originalData.getClass();
output.writeString(HEADER_KEYS_FIELD_NUMBER, Message.HEADER_DATA_TYPE, true);
output.writeString(HEADER_VALUES_FIELD_NUMBER, dataClass.getName(), true);
// Write data as serialized byte array
Schema dataSchema = RuntimeSchema.getSchema(dataClass);
try (RecyclableLinkedBuffer rlb = recyclableLinkedBuffer.get()) {
byte[] array = ProtostuffIOUtil.toByteArray(originalData, dataSchema, rlb.buffer());
output.writeByteArray(DATA_FIELD_NUMBER, array, false);
}
}
}
// Write sender
Address sender = message.sender();
if (sender != null) {
output.writeString(SENDER_HOST_FIELD_NUMBER, sender.host(), false);
output.writeInt32(SENDER_PORT_FIELD_NUMBER, sender.port(), false);
}
}
示例15: writeObjectTo
import io.protostuff.Output; //导入依赖的package包/类
@SuppressWarnings("unchecked")
static void writeObjectTo(Output output, Object value,
Schema<?> currentSchema, IdStrategy strategy) throws IOException
{
if (Collections.class == value.getClass().getDeclaringClass())
{
writeNonPublicCollectionTo(output, value, currentSchema, strategy);
return;
}
if (EnumSet.class.isAssignableFrom(value.getClass()))
{
strategy.writeEnumIdTo(output, ID_ENUM_SET,
EnumIO.getElementTypeFromEnumSet(value));
// TODO optimize
}
else
{
strategy.writeCollectionIdTo(output, ID_COLLECTION,
value.getClass());
}
if (output instanceof StatefulOutput)
{
// update using the derived schema.
((StatefulOutput) output).updateLast(strategy.COLLECTION_SCHEMA,
currentSchema);
}
strategy.COLLECTION_SCHEMA.writeTo(output, (Collection<Object>) value);
}