当前位置: 首页>>代码示例>>Java>>正文


Java Output.writeInt32方法代码示例

本文整理汇总了Java中io.protostuff.Output.writeInt32方法的典型用法代码示例。如果您正苦于以下问题:Java Output.writeInt32方法的具体用法?Java Output.writeInt32怎么用?Java Output.writeInt32使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在io.protostuff.Output的用法示例。


在下文中一共展示了Output.writeInt32方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: 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);
  }
}
 
开发者ID:scalecube,项目名称:scalecube,代码行数:41,代码来源:MessageSchema.java

示例2: writeTo

import io.protostuff.Output; //导入方法依赖的package包/类
@Override
public void writeTo(Output output, SerObj message) throws IOException {
  output.writeInt32(1, message.id, false);
  output.writeString(2, message.desc, false);
  output.writeInt64(3, message.timestamp, false);
  output.writeDouble(4, message.cost, false);
}
 
开发者ID:cloud-software-foundation,项目名称:c5-replicator,代码行数:8,代码来源:ProtostuffCodecTest.java

示例3: writeTo

import io.protostuff.Output; //导入方法依赖的package包/类
@Override
public void writeTo(Output output, Object array) throws IOException
{
    final int len = Array.getLength(array);

    output.writeInt32(ID_ARRAY_LEN, len, false);

    int nullCount = 0;
    for (int i = 0; i < len; i++)
    {
        Enum<?> v = (Enum<?>) Array.get(array, i);
        if (v != null)
        {
            if (nullCount != 0)
            {
                output.writeUInt32(ID_ARRAY_NULLCOUNT, nullCount, false);
                nullCount = 0;
            }

            eio.writeTo(output, ID_ARRAY_DATA, true, v);
        }
        else if (allowNullArrayElement)
        {
            nullCount++;
        }
    }

    // if last element is null
    if (nullCount != 0)
        output.writeUInt32(ID_ARRAY_NULLCOUNT, nullCount, false);
}
 
开发者ID:protostuff,项目名称:protostuff,代码行数:32,代码来源:ArraySchemas.java

示例4: transferObject

import io.protostuff.Output; //导入方法依赖的package包/类
static void transferObject(Pipe.Schema<Object> pipeSchema, Pipe pipe,
        Input input, Output output, IdStrategy strategy,
        Delegate<?> delegate) throws IOException
{
    if (ID_ARRAY_LEN != input.readFieldNumber(pipeSchema.wrappedSchema))
        throw new ProtostuffException("Corrupt input.");

    int len = input.readInt32();
    // write it back
    output.writeInt32(ID_ARRAY_LEN, len, false);
    
    // if from derived schema and the array is boxed, the length written
    // during serialization is: -(len + 1)
    if (len < 0)
        len = -len - 1;

    for (int i = 0, nullCount = 0; i < len;)
    {
        switch (input.readFieldNumber(pipeSchema.wrappedSchema))
        {
            case ID_ARRAY_DATA:
                i++;
                delegate.transfer(pipe, input, output, ID_ARRAY_DATA, true);
                break;
            case ID_ARRAY_NULLCOUNT:
                nullCount = input.readUInt32();
                i += nullCount;
                output.writeUInt32(ID_ARRAY_NULLCOUNT, nullCount, false);
                break;
            default:
                throw new ProtostuffException("Corrupt input.");
        }
    }

    if (0 != input.readFieldNumber(pipeSchema.wrappedSchema))
        throw new ProtostuffException("Corrupt input.");
}
 
开发者ID:protostuff,项目名称:protostuff,代码行数:38,代码来源:ArraySchemas.java

示例5: transfer

import io.protostuff.Output; //导入方法依赖的package包/类
@Override
protected void transfer(Pipe pipe, Input input, Output output)
        throws IOException
{
    if (ID_ARRAY_LEN != input
            .readFieldNumber(pipeSchema.wrappedSchema))
        throw new ProtostuffException("Corrupt input.");

    final int len = input.readInt32();
    // write it back
    output.writeInt32(ID_ARRAY_LEN, len, false);

    for (int i = 0, nullCount = 0; i < len;)
    {
        switch (input.readFieldNumber(pipeSchema.wrappedSchema))
        {
            case ID_ARRAY_DATA:
                i++;
                EnumIO.transfer(pipe, input, output, ID_ARRAY_DATA, true, eio.strategy);
                break;
            case ID_ARRAY_NULLCOUNT:
                nullCount = input.readUInt32();
                i += nullCount;
                output.writeUInt32(ID_ARRAY_NULLCOUNT, nullCount, false);
                break;
            default:
                throw new ProtostuffException("Corrupt input.");
        }
    }

    if (0 != input.readFieldNumber(pipeSchema.wrappedSchema))
        throw new ProtostuffException("Corrupt input.");
}
 
开发者ID:protostuff,项目名称:protostuff,代码行数:34,代码来源:ArraySchemas.java

示例6: transfer

import io.protostuff.Output; //导入方法依赖的package包/类
@Override
public void transfer(Pipe pipe, Input input, Output output, int number,
        boolean repeated) throws IOException
{
    output.writeInt32(number, input.readInt32(), repeated);
}
 
开发者ID:BFergerson,项目名称:Beam,代码行数:7,代码来源:RuntimeUnsafeFieldFactory.java

示例7: writeTo

import io.protostuff.Output; //导入方法依赖的package包/类
@Override
public void writeTo(Output output, int number, Integer value,
        boolean repeated) throws IOException
{
    output.writeInt32(number, value.intValue(), repeated);
}
 
开发者ID:BFergerson,项目名称:Beam,代码行数:7,代码来源:RuntimeReflectionFieldFactory.java

示例8: writeLengthTo

import io.protostuff.Output; //导入方法依赖的package包/类
protected void writeLengthTo(Output output, int len, boolean primitive)
        throws IOException
{
    output.writeInt32(ID_ARRAY_LEN, len, false);
}
 
开发者ID:protostuff,项目名称:protostuff,代码行数:6,代码来源:ArraySchemas.java


注:本文中的io.protostuff.Output.writeInt32方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。