本文整理匯總了Java中com.google.protobuf.CodedOutputStream.writeRawVarint64方法的典型用法代碼示例。如果您正苦於以下問題:Java CodedOutputStream.writeRawVarint64方法的具體用法?Java CodedOutputStream.writeRawVarint64怎麽用?Java CodedOutputStream.writeRawVarint64使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類com.google.protobuf.CodedOutputStream
的用法示例。
在下文中一共展示了CodedOutputStream.writeRawVarint64方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: encode
import com.google.protobuf.CodedOutputStream; //導入方法依賴的package包/類
@Override
protected Object encode(ChannelHandlerContext ctx, Channel channel, Object msg) throws Exception
{
if (!(msg instanceof ChannelBuffer))
{
return msg;
}
ChannelBuffer body = (ChannelBuffer) msg;
int length = body.readableBytes();
ChannelBuffer header = channel.getConfig().getBufferFactory()
.getBuffer(body.order(), CodedOutputStream.computeRawVarint64Size(length) + 4);
CodedOutputStream codedOutputStream = CodedOutputStream.newInstance(new ChannelBufferOutputStream(header));
codedOutputStream.writeRawVarint64(length);
int value = 0x0;
value |= (0x0 & 0xff);// network version
value |= ((0x0 & 0xff) << 8);// type
if (ctx.getPipeline().get("cryptoEncoder") != null) value |= ((0x1 & 0xf) << 16);// crypto type
else value |= ((0x0 & 0xf) << 16);// crypto type
value |= ((0x0 & 0xfff) << 20);// version
codedOutputStream.writeRawLittleEndian32(value);
codedOutputStream.flush();
return wrappedBuffer(header, body);
}