當前位置: 首頁>>代碼示例>>Java>>正文


Java CodedOutputStream.computeRawVarint32Size方法代碼示例

本文整理匯總了Java中com.google.protobuf.CodedOutputStream.computeRawVarint32Size方法的典型用法代碼示例。如果您正苦於以下問題:Java CodedOutputStream.computeRawVarint32Size方法的具體用法?Java CodedOutputStream.computeRawVarint32Size怎麽用?Java CodedOutputStream.computeRawVarint32Size使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在com.google.protobuf.CodedOutputStream的用法示例。


在下文中一共展示了CodedOutputStream.computeRawVarint32Size方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: toChannelBuffer

import com.google.protobuf.CodedOutputStream; //導入方法依賴的package包/類
/**
 * Serializes the given protobuf object into a Netty {@link ChannelBuffer}.
 * @param method The name of the method of the RPC we're going to send.
 * @param pb The protobuf to serialize.
 * @return A new channel buffer containing the serialized protobuf, with
 * enough free space at the beginning to tack on the RPC header.
 */
static final ChannelBuffer toChannelBuffer(final byte[] method,
                                           final AbstractMessageLite pb) {
  final int pblen = pb.getSerializedSize();
  final int vlen = CodedOutputStream.computeRawVarint32Size(pblen);
  final byte[] buf = new byte[4 + 19 + method.length + vlen + pblen];
  try {
    final CodedOutputStream out = CodedOutputStream.newInstance(buf, 4 + 19 + method.length,
                                                                vlen + pblen);
    out.writeRawVarint32(pblen);
    pb.writeTo(out);
    out.checkNoSpaceLeft();
  } catch (IOException e) {
    throw new RuntimeException("Should never happen", e);
  }
  return ChannelBuffers.wrappedBuffer(buf);
}
 
開發者ID:OpenTSDB,項目名稱:asynccassandra,代碼行數:24,代碼來源:HBaseRpc.java

示例2: sendSaslMessage

import com.google.protobuf.CodedOutputStream; //導入方法依賴的package包/類
private void sendSaslMessage(ChannelHandlerContext ctx, byte[] payload,
    List<CipherOption> options) throws IOException {
  DataTransferEncryptorMessageProto.Builder builder =
      DataTransferEncryptorMessageProto.newBuilder();
  builder.setStatus(DataTransferEncryptorStatus.SUCCESS);
  if (payload != null) {
    // Was ByteStringer; fix w/o using ByteStringer. Its in hbase-protocol
    // and we want to keep that out of hbase-server.
    builder.setPayload(ByteString.copyFrom(payload));
  }
  if (options != null) {
    builder.addAllCipherOption(PB_HELPER.convertCipherOptions(options));
  }
  DataTransferEncryptorMessageProto proto = builder.build();
  int size = proto.getSerializedSize();
  size += CodedOutputStream.computeRawVarint32Size(size);
  ByteBuf buf = ctx.alloc().buffer(size);
  proto.writeDelimitedTo(new ByteBufOutputStream(buf));
  ctx.write(buf);
}
 
開發者ID:apache,項目名稱:hbase,代碼行數:21,代碼來源:FanOutOneBlockAsyncDFSOutputSaslHelper.java

示例3: computeObjectSizeNoTag

import com.google.protobuf.CodedOutputStream; //導入方法依賴的package包/類
/**
 * Compute object size no tag.
 *
 * @param o the o
 * @return the int
 */
public static int computeObjectSizeNoTag(Object o) {
    int size = 0;
    if (o == null) {
        return size;
    }

    Class cls = o.getClass();
    Codec target = ProtobufProxy.create(cls);
    try {
        size = target.size(o);
        size = size + CodedOutputStream.computeRawVarint32Size(size);
        return size;
    } catch (IOException e) {
        throw new RuntimeException(e.getMessage(), e);
    }
}
 
開發者ID:jhunters,項目名稱:jprotobuf,代碼行數:23,代碼來源:CodedConstant.java

示例4: encodeWithLengthPrefix

import com.google.protobuf.CodedOutputStream; //導入方法依賴的package包/類
public static void encodeWithLengthPrefix(MessageLite msg, ByteBuf out) throws Exception {
	ByteBuf msgBytes;
	if(msg==null){
		msgBytes=Unpooled.EMPTY_BUFFER;
	}
	else{
		msgBytes=encodeNoLengthPrefix(msg);
	}
    int encodedMessageLen = msgBytes.readableBytes();
    int headerLenLen = CodedOutputStream.computeRawVarint32Size(encodedMessageLen);
    out.ensureWritable(headerLenLen + encodedMessageLen);

    CodedOutputStream headerOut =
            CodedOutputStream.newInstance(new ByteBufOutputStream(out), headerLenLen);
    headerOut.writeRawVarint32(encodedMessageLen);
    headerOut.flush();

    out.writeBytes(msgBytes, msgBytes.readerIndex(), encodedMessageLen);

}
 
開發者ID:pmarches,項目名稱:peercentrum-core,代碼行數:21,代碼來源:ProtobufByteBufCodec.java

示例5: encode

import com.google.protobuf.CodedOutputStream; //導入方法依賴的package包/類
@Override
protected void encode(
        ChannelHandlerContext ctx, ByteBuf msg, ByteBuf out) throws Exception {
    int bodyLen = msg.readableBytes();
    int headerLen = CodedOutputStream.computeRawVarint32Size(bodyLen);
    out.ensureWritable(headerLen + bodyLen);

    CodedOutputStream headerOut =
            CodedOutputStream.newInstance(new ByteBufOutputStream(out), headerLen);
    headerOut.writeRawVarint32(bodyLen);
    headerOut.flush();

    out.writeBytes(msg, msg.readerIndex(), bodyLen);
}
 
開發者ID:ninelook,項目名稱:wecard-server,代碼行數:15,代碼來源:ProtobufVarint32LengthFieldPrepender.java

示例6: getLength

import com.google.protobuf.CodedOutputStream; //導入方法依賴的package包/類
@Override
public int getLength() {
  int headerLen = requestHeader.getSerializedSize();
  int reqLen;
  if (theRequest != null) {
    reqLen = theRequest.getSerializedSize();
  } else if (theRequestRead != null ) {
    reqLen = theRequestRead.length;
  } else {
    throw new IllegalArgumentException(
        "getLength on uninitialized RpcWrapper");      
  }
  return CodedOutputStream.computeRawVarint32Size(headerLen) +  headerLen
      + CodedOutputStream.computeRawVarint32Size(reqLen) + reqLen;
}
 
開發者ID:nucypher,項目名稱:hadoop-oss,代碼行數:16,代碼來源:ProtobufRpcEngine.java

示例7: encode

import com.google.protobuf.CodedOutputStream; //導入方法依賴的package包/類
protected void encode(ChannelHandlerContext paramChannelHandlerContext, ByteBuf paramByteBuf1, ByteBuf paramByteBuf2)
        throws Exception {
    int i = paramByteBuf1.readableBytes();
    int j = CodedOutputStream.computeRawVarint32Size(i);
    paramByteBuf2.ensureWritable(j + i);

    CodedOutputStream localCodedOutputStream = CodedOutputStream.newInstance(new ByteBufOutputStream(paramByteBuf2), j);

    localCodedOutputStream.writeRawVarint32(i);
    localCodedOutputStream.flush();

    paramByteBuf2.writeBytes(paramByteBuf1, paramByteBuf1.readerIndex(), i);
}
 
開發者ID:Superioz,項目名稱:MooProject,代碼行數:14,代碼來源:Varint32LengthFieldPrepender.java

示例8: encode

import com.google.protobuf.CodedOutputStream; //導入方法依賴的package包/類
protected void encode(ChannelHandlerContext paramChannelHandlerContext, ByteBuf paramByteBuf1, ByteBuf paramByteBuf2)
        throws Exception {
    int i = paramByteBuf1.readableBytes();
    int j = CodedOutputStream.computeRawVarint32Size(i);
    paramByteBuf2.ensureWritable(j + i);

    CodedOutputStream localCodedOutputStream = CodedOutputStream.newInstance(new ByteBufOutputStream(paramByteBuf2), j);

    localCodedOutputStream.writeRawVarint32(i);
    localCodedOutputStream.flush();

    paramByteBuf2.writeBytes(paramByteBuf1, paramByteBuf1.readerIndex(), i);
    paramByteBuf2.release();
}
 
開發者ID:Superioz,項目名稱:MooProject,代碼行數:15,代碼來源:ProtobufVarint32LengthFieldPrepender.java

示例9: getDelimitedMessageAsByteBuffer

import com.google.protobuf.CodedOutputStream; //導入方法依賴的package包/類
/**
 * @param m Message to serialize delimited; i.e. w/ a vint of its size preceeding its
 * serialization.
 * @return The passed in Message serialized with delimiter.  Return null if <code>m</code> is null
 * @throws IOException
 */
public static ByteBuffer getDelimitedMessageAsByteBuffer(final Message m) throws IOException {
  if (m == null) return null;
  int serializedSize = m.getSerializedSize();
  int vintSize = CodedOutputStream.computeRawVarint32Size(serializedSize);
  byte [] buffer = new byte[serializedSize + vintSize];
  // Passing in a byte array saves COS creating a buffer which it does when using streams.
  CodedOutputStream cos = CodedOutputStream.newInstance(buffer);
  // This will write out the vint preamble and the message serialized.
  cos.writeMessageNoTag(m);
  cos.flush();
  cos.checkNoSpaceLeft();
  return ByteBuffer.wrap(buffer);
}
 
開發者ID:fengchen8086,項目名稱:ditb,代碼行數:20,代碼來源:IPCUtil.java

示例10: getTotalSizeWhenWrittenDelimited

import com.google.protobuf.CodedOutputStream; //導入方法依賴的package包/類
/**
 * @return Size on the wire when the two messages are written with writeDelimitedTo
 */
public static int getTotalSizeWhenWrittenDelimited(Message ... messages) {
  int totalSize = 0;
  for (Message m: messages) {
    if (m == null) continue;
    totalSize += m.getSerializedSize();
    totalSize += CodedOutputStream.computeRawVarint32Size(m.getSerializedSize());
  }
  Preconditions.checkArgument(totalSize < Integer.MAX_VALUE);
  return totalSize;
}
 
開發者ID:fengchen8086,項目名稱:ditb,代碼行數:14,代碼來源:IPCUtil.java

示例11: getDelimitedMessageAsByteBuffer

import com.google.protobuf.CodedOutputStream; //導入方法依賴的package包/類
/**
 * @param m Message to serialize delimited; i.e. w/ a vint of its size preceeding its
 * serialization.
 * @return The passed in Message serialized with delimiter.  Return null if <code>m</code> is null
 * @throws IOException
 */
static ByteBuffer getDelimitedMessageAsByteBuffer(final Message m) throws IOException {
  if (m == null) return null;
  int serializedSize = m.getSerializedSize();
  int vintSize = CodedOutputStream.computeRawVarint32Size(serializedSize);
  byte [] buffer = new byte[serializedSize + vintSize];
  // Passing in a byte array saves COS creating a buffer which it does when using streams.
  CodedOutputStream cos = CodedOutputStream.newInstance(buffer);
  // This will write out the vint preamble and the message serialized.
  cos.writeMessageNoTag(m);
  cos.flush();
  cos.checkNoSpaceLeft();
  return ByteBuffer.wrap(buffer);
}
 
開發者ID:tenggyut,項目名稱:HIndex,代碼行數:20,代碼來源:IPCUtil.java

示例12: getTotalSizeWhenWrittenDelimited

import com.google.protobuf.CodedOutputStream; //導入方法依賴的package包/類
/**
 * @param header
 * @param body
 * @return Size on the wire when the two messages are written with writeDelimitedTo
 */
static int getTotalSizeWhenWrittenDelimited(Message ... messages) {
  int totalSize = 0;
  for (Message m: messages) {
    if (m == null) continue;
    totalSize += m.getSerializedSize();
    totalSize += CodedOutputStream.computeRawVarint32Size(m.getSerializedSize());
  }
  Preconditions.checkArgument(totalSize < Integer.MAX_VALUE);
  return totalSize;
}
 
開發者ID:tenggyut,項目名稱:HIndex,代碼行數:16,代碼來源:IPCUtil.java

示例13: writeTo

import com.google.protobuf.CodedOutputStream; //導入方法依賴的package包/類
@Override
void writeTo(ResponseBuffer out) throws IOException {
  int length = message.getSerializedSize();
  length += CodedOutputStream.computeRawVarint32Size(length);
  out.ensureCapacity(length);
  message.writeDelimitedTo(out);
}
 
開發者ID:hopshadoop,項目名稱:hops,代碼行數:8,代碼來源:RpcWritable.java

示例14: encode

import com.google.protobuf.CodedOutputStream; //導入方法依賴的package包/類
@Override
protected void encode(
        ChannelHandlerContext ctx, ByteBuf msg, ByteBuf out) throws Exception {
    int bodyLen = msg.readableBytes();
    int headerLen = CodedOutputStream.computeRawVarint32Size(bodyLen);
    out.ensureWritable(headerLen + bodyLen);

    CodedOutputStream headerOut =
            CodedOutputStream.newInstance(new ByteBufOutputStream(out));
    headerOut.writeRawVarint32(bodyLen);
    headerOut.flush();

    out.writeBytes(msg, msg.readerIndex(), bodyLen);
}
 
開發者ID:kyle-liu,項目名稱:netty4study,代碼行數:15,代碼來源:ProtobufVarint32LengthFieldPrepender.java

示例15: getTotalSizeofMessages

import com.google.protobuf.CodedOutputStream; //導入方法依賴的package包/類
public static int getTotalSizeofMessages(Message ... messages) {
  int totalSize = 0;
  for (Message m: messages) {
    if (m == null) continue;
    totalSize += m.getSerializedSize();
    totalSize += CodedOutputStream.computeRawVarint32Size(m.getSerializedSize());
  }
  return totalSize;
}
 
開發者ID:chicm,項目名稱:CmRaft,代碼行數:10,代碼來源:PacketUtils.java


注:本文中的com.google.protobuf.CodedOutputStream.computeRawVarint32Size方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。