Java 类com.google.protobuf.AbstractMessageLite 实例源码

项目:asynccassandra    文件:HBaseRpc.java   
/**
 * 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);
}
项目:mesos-rxjava    文件:RecordIOOperatorTest.java   
@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);
}
项目:retrofit-jaxrs    文件:ProtoConverter.java   
@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);
}
项目:Wiab.pro    文件:Base64Util.java   
public static String encode(AbstractMessageLite message) {
  return new String(Base64.encodeBase64(message.toByteArray()), CHAR_SET);
}
项目:bazel    文件:ProtoDeterministicWriter.java   
public ProtoDeterministicWriter(AbstractMessageLite message) {
  this.message = message;
}
项目:android-chromium    文件:ProtoWrapper.java   
/** Returns a ProtoWrapper that wraps the provided object */
public static <M extends AbstractMessageLite> ProtoWrapper<M> of(M proto) {
  return new ProtoWrapper<M>(proto);
}
项目:cordova-android-chromium    文件:ProtoWrapper.java   
/** Returns a ProtoWrapper that wraps the provided object */
public static <M extends AbstractMessageLite> ProtoWrapper<M> of(M proto) {
  return new ProtoWrapper<M>(proto);
}