/**
* 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);
}
java类com.google.protobuf.AbstractMessageLite的实例源码
HBaseRpc.java 文件源码
项目:asynccassandra
阅读 33
收藏 0
点赞 0
评论 0
RecordIOOperatorTest.java 文件源码
项目:mesos-rxjava
阅读 35
收藏 0
点赞 0
评论 0
@Test
public void readEvents_multipleEventsInOneChunk() throws Exception {
final List<Event> subHbOffer = newArrayList(
TestingProtos.SUBSCRIBED,
TestingProtos.HEARTBEAT,
TestingProtos.OFFER
);
final List<byte[]> eventChunks = subHbOffer.stream()
.map(AbstractMessageLite::toByteArray)
.map(RecordIOUtils::createChunk)
.collect(Collectors.toList());
final List<ByteBuf> singleChunk = newArrayList(Unpooled.copiedBuffer(concatAllChunks(eventChunks)));
final List<Event> events = runTestOnChunks(singleChunk);
assertThat(events).isEqualTo(subHbOffer);
}
ProtoConverter.java 文件源码
项目:retrofit-jaxrs
阅读 25
收藏 0
点赞 0
评论 0
@Override
public TypedOutput toBody(Object object)
{
if (!(object instanceof AbstractMessageLite))
{
throw new IllegalArgumentException(
"Expected a protobuf message but was " + (object != null ? object.getClass().getName()
: "null"));
}
byte[] bytes = ((AbstractMessageLite) object).toByteArray();
return new TypedByteArray(MIME_TYPE, bytes);
}
Base64Util.java 文件源码
项目:Wiab.pro
阅读 35
收藏 0
点赞 0
评论 0
public static String encode(AbstractMessageLite message) {
return new String(Base64.encodeBase64(message.toByteArray()), CHAR_SET);
}
ProtoDeterministicWriter.java 文件源码
项目:bazel
阅读 35
收藏 0
点赞 0
评论 0
public ProtoDeterministicWriter(AbstractMessageLite message) {
this.message = message;
}
ProtoWrapper.java 文件源码
项目:android-chromium
阅读 79
收藏 0
点赞 0
评论 0
/** Returns a ProtoWrapper that wraps the provided object */
public static <M extends AbstractMessageLite> ProtoWrapper<M> of(M proto) {
return new ProtoWrapper<M>(proto);
}
ProtoWrapper.java 文件源码
项目:cordova-android-chromium
阅读 32
收藏 0
点赞 0
评论 0
/** Returns a ProtoWrapper that wraps the provided object */
public static <M extends AbstractMessageLite> ProtoWrapper<M> of(M proto) {
return new ProtoWrapper<M>(proto);
}