com.google.protobuf.AbstractMessageLite Java Examples

The following examples show how to use com.google.protobuf.AbstractMessageLite. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: RedisClusterOnlineRetriever.java    From feast with Apache License 2.0 6 votes vote down vote up
/**
 * 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();
  }
}
 
Example #2
Source File: RedisOnlineRetriever.java    From feast with Apache License 2.0 6 votes vote down vote up
/**
 * 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();
  }
}
 
Example #3
Source File: RedisClusterOnlineRetrieverTest.java    From feast with Apache License 2.0 6 votes vote down vote up
@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]);
}
 
Example #4
Source File: RedisOnlineRetrieverTest.java    From feast with Apache License 2.0 6 votes vote down vote up
@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]);
}
 
Example #5
Source File: RecordIOOperatorTest.java    From mesos-rxjava with Apache License 2.0 6 votes vote down vote up
@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);
}
 
Example #6
Source File: ProtoStorageClient.java    From firebase-android-sdk with Apache License 2.0 5 votes vote down vote up
/**
 * 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;
          }
        }
      });
}
 
Example #7
Source File: Base64Util.java    From swellrt with Apache License 2.0 4 votes vote down vote up
public static String encode(AbstractMessageLite message) {
  return new String(Base64.encodeBase64(message.toByteArray()), CHAR_SET);
}
 
Example #8
Source File: ProtoDeterministicWriter.java    From bazel with Apache License 2.0 4 votes vote down vote up
/** Constructs a {@link ProtoDeterministicWriter} with an eagerly constructed message. */
public ProtoDeterministicWriter(AbstractMessageLite<?, ?> message) {
  this.messageSupplier = () -> message;
}
 
Example #9
Source File: ProtoWrapper.java    From android-chromium with BSD 2-Clause "Simplified" License 4 votes vote down vote up
/** Returns a ProtoWrapper that wraps the provided object */
public static <M extends AbstractMessageLite> ProtoWrapper<M> of(M proto) {
  return new ProtoWrapper<M>(proto);
}
 
Example #10
Source File: ProtoWrapper.java    From android-chromium with BSD 2-Clause "Simplified" License 4 votes vote down vote up
/** Returns a ProtoWrapper that wraps the provided object */
public static <M extends AbstractMessageLite> ProtoWrapper<M> of(M proto) {
  return new ProtoWrapper<M>(proto);
}
 
Example #11
Source File: ProtoStorageClient.java    From firebase-android-sdk with Apache License 2.0 3 votes vote down vote up
/**
 * 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;
          }
        }
      });
}
 
Example #12
Source File: ProtoDeterministicWriter.java    From bazel with Apache License 2.0 votes vote down vote up
AbstractMessageLite<?, ?> getMessage() throws IOException;