本文整理匯總了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);
}
示例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);
}
示例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);
}
}
示例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);
}
示例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);
}
示例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;
}
示例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);
}
示例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();
}
示例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);
}
示例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;
}
示例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);
}
示例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;
}
示例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);
}
示例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);
}
示例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;
}