本文整理汇总了Java中com.google.protobuf.AbstractMessageLite类的典型用法代码示例。如果您正苦于以下问题:Java AbstractMessageLite类的具体用法?Java AbstractMessageLite怎么用?Java AbstractMessageLite使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
AbstractMessageLite类属于com.google.protobuf包,在下文中一共展示了AbstractMessageLite类的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: toChannelBuffer
import com.google.protobuf.AbstractMessageLite; //导入依赖的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: readEvents_multipleEventsInOneChunk
import com.google.protobuf.AbstractMessageLite; //导入依赖的package包/类
@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);
}
示例3: toBody
import com.google.protobuf.AbstractMessageLite; //导入依赖的package包/类
@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);
}
示例4: encode
import com.google.protobuf.AbstractMessageLite; //导入依赖的package包/类
public static String encode(AbstractMessageLite message) {
return new String(Base64.encodeBase64(message.toByteArray()), CHAR_SET);
}
示例5: ProtoDeterministicWriter
import com.google.protobuf.AbstractMessageLite; //导入依赖的package包/类
public ProtoDeterministicWriter(AbstractMessageLite message) {
this.message = message;
}
示例6: of
import com.google.protobuf.AbstractMessageLite; //导入依赖的package包/类
/** Returns a ProtoWrapper that wraps the provided object */
public static <M extends AbstractMessageLite> ProtoWrapper<M> of(M proto) {
return new ProtoWrapper<M>(proto);
}