當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。