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

下面列出了怎么用com.google.protobuf.AbstractMessageLite的API类实例代码及写法,或者点击链接到github查看源代码。

源代码1 项目: feast   文件: RedisClusterOnlineRetriever.java
/**
 * Pull the data stored in Redis at the given keys as bytes using the mget command. If no data is
 * stored at a given key in Redis, will subsitute the data with null.
 *
 * @param keys list of {@link RedisKey} to pull from redis.
 * @return list of data bytes or null pulled from redis for each given key.
 */
private List<byte[]> sendMultiGet(List<RedisKey> keys) {
  try {
    byte[][] binaryKeys =
        keys.stream()
            .map(AbstractMessageLite::toByteArray)
            .collect(Collectors.toList())
            .toArray(new byte[0][0]);
    return syncCommands.mget(binaryKeys).stream()
        .map(
            keyValue -> {
              if (keyValue == null) {
                return null;
              }
              return keyValue.getValueOrElse(null);
            })
        .collect(Collectors.toList());
  } catch (Exception e) {
    throw Status.NOT_FOUND
        .withDescription("Unable to retrieve feature from Redis")
        .withCause(e)
        .asRuntimeException();
  }
}
 
源代码2 项目: feast   文件: RedisOnlineRetriever.java
/**
 * Pull the data stored in Redis at the given keys as bytes using the mget command. If no data is
 * stored at a given key in Redis, will subsitute the data with null.
 *
 * @param keys list of {@link RedisKey} to pull from redis.
 * @return list of data bytes or null pulled from redis for each given key.
 */
private List<byte[]> sendMultiGet(List<RedisKey> keys) {
  try {
    byte[][] binaryKeys =
        keys.stream()
            .map(AbstractMessageLite::toByteArray)
            .collect(Collectors.toList())
            .toArray(new byte[0][0]);
    return syncCommands.mget(binaryKeys).stream()
        .map(
            keyValue -> {
              if (keyValue == null) {
                return null;
              }
              return keyValue.getValueOrElse(null);
            })
        .collect(Collectors.toList());
  } catch (Exception e) {
    throw Status.UNKNOWN
        .withDescription("Unexpected error when pulling data from from Redis.")
        .withCause(e)
        .asRuntimeException();
  }
}
 
源代码3 项目: feast   文件: RedisClusterOnlineRetrieverTest.java
@Before
public void setUp() {
  initMocks(this);
  when(connection.sync()).thenReturn(syncCommands);
  redisClusterOnlineRetriever = RedisClusterOnlineRetriever.create(connection);
  redisKeyList =
      Lists.newArrayList(
              RedisKey.newBuilder()
                  .setFeatureSet("project/featureSet")
                  .addAllEntities(
                      Lists.newArrayList(
                          Field.newBuilder().setName("entity1").setValue(intValue(1)).build(),
                          Field.newBuilder().setName("entity2").setValue(strValue("a")).build()))
                  .build(),
              RedisKey.newBuilder()
                  .setFeatureSet("project/featureSet")
                  .addAllEntities(
                      Lists.newArrayList(
                          Field.newBuilder().setName("entity1").setValue(intValue(2)).build(),
                          Field.newBuilder().setName("entity2").setValue(strValue("b")).build()))
                  .build())
          .stream()
          .map(AbstractMessageLite::toByteArray)
          .collect(Collectors.toList())
          .toArray(new byte[0][0]);
}
 
源代码4 项目: feast   文件: RedisOnlineRetrieverTest.java
@Before
public void setUp() {
  initMocks(this);
  when(connection.sync()).thenReturn(syncCommands);
  redisOnlineRetriever = RedisOnlineRetriever.create(connection);
  redisKeyList =
      Lists.newArrayList(
              RedisKey.newBuilder()
                  .setFeatureSet("project/featureSet")
                  .addAllEntities(
                      Lists.newArrayList(
                          Field.newBuilder().setName("entity1").setValue(intValue(1)).build(),
                          Field.newBuilder().setName("entity2").setValue(strValue("a")).build()))
                  .build(),
              RedisKey.newBuilder()
                  .setFeatureSet("project/featureSet")
                  .addAllEntities(
                      Lists.newArrayList(
                          Field.newBuilder().setName("entity1").setValue(intValue(2)).build(),
                          Field.newBuilder().setName("entity2").setValue(strValue("b")).build()))
                  .build())
          .stream()
          .map(AbstractMessageLite::toByteArray)
          .collect(Collectors.toList())
          .toArray(new byte[0][0]);
}
 
源代码5 项目: 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);
}
 
源代码6 项目: firebase-android-sdk   文件: ProtoStorageClient.java
/**
 * Write the proto to a file in the app' s file directory.
 *
 * <p>Writes are non atomic.
 *
 * <p>Readers are expected to deal with corrupt data resulting from faulty writes
 *
 * @param messageLite
 * @throws IOException
 */
public Completable write(AbstractMessageLite messageLite) {
  return Completable.fromCallable(
      () -> {
        // reads / writes are synchronized per client instance
        synchronized (this) {
          try (FileOutputStream output = application.openFileOutput(fileName, MODE_PRIVATE)) {
            output.write(messageLite.toByteArray());
            return messageLite;
          }
        }
      });
}
 
源代码7 项目: swellrt   文件: Base64Util.java
public static String encode(AbstractMessageLite message) {
  return new String(Base64.encodeBase64(message.toByteArray()), CHAR_SET);
}
 
源代码8 项目: bazel   文件: ProtoDeterministicWriter.java
/** Constructs a {@link ProtoDeterministicWriter} with an eagerly constructed message. */
public ProtoDeterministicWriter(AbstractMessageLite<?, ?> message) {
  this.messageSupplier = () -> message;
}
 
源代码9 项目: 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);
}
 
源代码10 项目: 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);
}
 
源代码11 项目: firebase-android-sdk   文件: ProtoStorageClient.java
/**
 * Read the contents of the file into a proto object using the parser. Since writes are not
 * atomic, the caller will receive {@link Maybe#empty()} when data is corrupt.
 *
 * <p>Some valid scenarios that can lead to corrupt data :
 *
 * <ul>
 *   <li>Out of disk space while writing
 *   <li>Power outage while writing
 *   <li>Process killed while writing
 * </ul>
 *
 * @param parser
 * @param <T>
 */
public <T extends AbstractMessageLite> Maybe<T> read(Parser<T> parser) {
  return Maybe.fromCallable(
      () -> {
        // reads / writes are synchronized per client instance
        synchronized (this) {
          try (FileInputStream inputStream = application.openFileInput(fileName)) {
            return parser.parseFrom(inputStream);
          } catch (InvalidProtocolBufferException | FileNotFoundException e) {
            Logging.logi("Recoverable exception while reading cache: " + e.getMessage());
            return null;
          }
        }
      });
}
 
源代码12 项目: bazel   文件: ProtoDeterministicWriter.java
AbstractMessageLite<?, ?> getMessage() throws IOException; 
 类所在包
 同包方法