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


Java LinkBuffer类代码示例

本文整理汇总了Java中io.protostuff.LinkBuffer的典型用法代码示例。如果您正苦于以下问题:Java LinkBuffer类的具体用法?Java LinkBuffer怎么用?Java LinkBuffer使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


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

示例1: writeVarInt32

import io.protostuff.LinkBuffer; //导入依赖的package包/类
@Override
public LinkBuffer writeVarInt32(int value) throws IOException {
    // TODO too costly operation
    byte[] buf = new byte[5];
    int locPtr = 0;
    while (true)
    {
        if ((value & ~0x7F) == 0)
        {
            buf[locPtr++] = (byte) value;
            // thing;
            buffer.writeBytes(buf, 0, locPtr);
            return this;
        }
        else
        {
            buf[locPtr++] = (byte) ((value & 0x7F) | 0x80);
            value >>>= 7;
        }
    }
}
 
开发者ID:dmart28,项目名称:reveno,代码行数:22,代码来源:ZeroCopyLinkBuffer.java

示例2: writeVarInt64

import io.protostuff.LinkBuffer; //导入依赖的package包/类
@Override
public LinkBuffer writeVarInt64(long value) throws IOException {
    // TODO too costly operation
    byte[] buf = new byte[10];
    int locPtr = 0;

    while (true)
    {
        if ((value & ~0x7FL) == 0)
        {
            buf[locPtr++] = (byte) value;
            buffer.writeBytes(buf, 0, locPtr);
            return this;
        }
        else
        {
            buf[locPtr++] = (byte) (((int) value & 0x7F) | 0x80);
            value >>>= 7;
        }
    }
}
 
开发者ID:dmart28,项目名称:reveno,代码行数:22,代码来源:ZeroCopyLinkBuffer.java

示例3: testSimpleSerialization

import io.protostuff.LinkBuffer; //导入依赖的package包/类
@Test
public void testSimpleSerialization() throws Exception {
  RequestVote rv = new RequestVote(1, 22222, 34, 22);
  ReplicationWireMessage rwm = new ReplicationWireMessage(
      1, 1, 0, "quorumId", false, rv, null, null, null, null, null
  );

  LowCopyProtobufOutput lcpo = new LowCopyProtobufOutput(new LinkBuffer(24));
  rwm.writeTo(lcpo, rwm);
  List<ByteBuffer> serBufs = lcpo.buffer.finish();
  logBufsInformation("ReplicationWireMessage", serBufs);

  ByteBuf b = Unpooled.wrappedBuffer(serBufs.toArray(new ByteBuffer[serBufs.size()]));
  System.out.println("ByteBuf info = " + b);
  System.out.println("ByteBuf size = " + b.readableBytes());
  assertEquals(lcpo.buffer.size(), b.readableBytes());

  System.out.println("rwm = " + rwm);
}
 
开发者ID:cloud-software-foundation,项目名称:c5-replicator,代码行数:20,代码来源:ReplicationWireMessageTest.java

示例4: encodeWithLengthAndCrc

import io.protostuff.LinkBuffer; //导入依赖的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);
  }
}
 
开发者ID:cloud-software-foundation,项目名称:c5-replicator,代码行数:29,代码来源:EntryEncodingUtil.java

示例5: writeInt32LE

import io.protostuff.LinkBuffer; //导入依赖的package包/类
@Override
public LinkBuffer writeInt32LE(int value) throws IOException {
    buffer.writeByte((byte) (value & 255));
    buffer.writeByte((byte) (value >>> 8 & 255));
    buffer.writeByte((byte) (value >>> 16 & 255));
    buffer.writeByte((byte) (value >>> 24 & 255));
    return this;
}
 
开发者ID:dmart28,项目名称:reveno,代码行数:9,代码来源:ZeroCopyLinkBuffer.java

示例6: writeInt64LE

import io.protostuff.LinkBuffer; //导入依赖的package包/类
@Override
public LinkBuffer writeInt64LE(long value) throws IOException {
    buffer.writeByte((byte) ((int) (value)));
    buffer.writeByte((byte) ((int) (value >>> 8)));
    buffer.writeByte((byte) ((int) (value >>> 16)));
    buffer.writeByte((byte) ((int) (value >>> 24)));
    buffer.writeByte((byte) ((int) (value >>> 32)));
    buffer.writeByte((byte) ((int) (value >>> 40)));
    buffer.writeByte((byte) ((int) (value >>> 48)));
    buffer.writeByte((byte)((int)(value >>> 56)));
    return this;
}
 
开发者ID:dmart28,项目名称:reveno,代码行数:13,代码来源:ZeroCopyLinkBuffer.java

示例7: serialize

import io.protostuff.LinkBuffer; //导入依赖的package包/类
@Override
public List<ByteBuffer> serialize() {
  final LinkBuffer messageBuf = new LinkBuffer();
  final LowCopyProtobufOutput lcpo = new LowCopyProtobufOutput(messageBuf);

  try {
    message.writeTo(lcpo, message);
    return messageBuf.finish();

  } catch (IOException e) {
    throw new RuntimeException(e);
  }
}
 
开发者ID:cloud-software-foundation,项目名称:c5-replicator,代码行数:14,代码来源:OLogProtostuffContent.java

示例8: addLengthPrependedEntryBuffersToList

import io.protostuff.LinkBuffer; //导入依赖的package包/类
private static void addLengthPrependedEntryBuffersToList(RegionWalEntry entry, List<ByteBuffer> buffers)
    throws IOException {
  LinkBuffer entryBuffer = new LinkBuffer();
  LowCopyProtostuffOutput lcpo = new LowCopyProtostuffOutput(entryBuffer);
  RegionWalEntry.getSchema().writeTo(lcpo, entry);

  final int length = Ints.checkedCast(lcpo.buffer.size());
  final LinkBuffer lengthBuf = new LinkBuffer().writeVarInt32(length);

  buffers.addAll(lengthBuf.finish());
  buffers.addAll(entryBuffer.finish());
}
 
开发者ID:cloud-software-foundation,项目名称:c5,代码行数:13,代码来源:OLogShim.java

示例9: writeByte

import io.protostuff.LinkBuffer; //导入依赖的package包/类
@Override
public LinkBuffer writeByte(byte value) throws IOException {
    buffer.writeByte(value);
    return this;
}
 
开发者ID:dmart28,项目名称:reveno,代码行数:6,代码来源:ZeroCopyLinkBuffer.java

示例10: writeInt16

import io.protostuff.LinkBuffer; //导入依赖的package包/类
@Override
public LinkBuffer writeInt16(int value) throws IOException {
    buffer.writeShort((short) value);
    return this;
}
 
开发者ID:dmart28,项目名称:reveno,代码行数:6,代码来源:ZeroCopyLinkBuffer.java

示例11: writeInt16LE

import io.protostuff.LinkBuffer; //导入依赖的package包/类
@Override
public LinkBuffer writeInt16LE(int value) throws IOException {
    buffer.writeByte((byte) value);
    buffer.writeByte((byte) (value >>> 8 & 255));
    return this;
}
 
开发者ID:dmart28,项目名称:reveno,代码行数:7,代码来源:ZeroCopyLinkBuffer.java

示例12: writeInt32

import io.protostuff.LinkBuffer; //导入依赖的package包/类
@Override
public LinkBuffer writeInt32(int value) throws IOException {
    buffer.writeInt(value);
    return this;
}
 
开发者ID:dmart28,项目名称:reveno,代码行数:6,代码来源:ZeroCopyLinkBuffer.java

示例13: writeInt64

import io.protostuff.LinkBuffer; //导入依赖的package包/类
@Override
public LinkBuffer writeInt64(long value) throws IOException {
    buffer.writeLong(value);
    return this;
}
 
开发者ID:dmart28,项目名称:reveno,代码行数:6,代码来源:ZeroCopyLinkBuffer.java

示例14: writeByteArray

import io.protostuff.LinkBuffer; //导入依赖的package包/类
@Override
public LinkBuffer writeByteArray(byte[] value, final int offset, final int length) throws IOException {
    // copy in:
    buffer.writeBytes(value, offset, length);
    return this;
}
 
开发者ID:dmart28,项目名称:reveno,代码行数:7,代码来源:ZeroCopyLinkBuffer.java

示例15: writeByteBuffer

import io.protostuff.LinkBuffer; //导入依赖的package包/类
@Override
public LinkBuffer writeByteBuffer(ByteBuffer buf) {
    ByteBuffer cp = buf.slice();
    buffer.writeFromBuffer(cp);
    return this;
}
 
开发者ID:dmart28,项目名称:reveno,代码行数:7,代码来源:ZeroCopyLinkBuffer.java


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