Java Code Examples for com.google.protobuf.Timestamp#Builder

The following examples show how to use com.google.protobuf.Timestamp#Builder . 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: WellKnownTypeMarshaller.java    From curiostack with MIT License 5 votes vote down vote up
@Override
public void doMerge(JsonParser parser, int unused, Message.Builder messageBuilder)
    throws IOException {
  Timestamp.Builder builder = (Timestamp.Builder) messageBuilder;
  try {
    builder.mergeFrom(Timestamps.parse(ParseSupport.parseString(parser)));
  } catch (ParseException e) {
    throw new InvalidProtocolBufferException(
        "Failed to readValue timestamp: " + parser.getText());
  }
}
 
Example 2
Source File: DatastoreHelper.java    From google-cloud-datastore with Apache License 2.0 5 votes vote down vote up
private static Timestamp.Builder toTimestamp(long microseconds) {
  long seconds = microseconds / MICROSECONDS_PER_SECOND;
  long microsecondsRemainder = microseconds % MICROSECONDS_PER_SECOND;
  if (microsecondsRemainder < 0) {
    // Nanos must be positive even if microseconds is negative.
    // Java modulus doesn't take care of this for us.
    microsecondsRemainder += MICROSECONDS_PER_SECOND;
    seconds -= 1;
  }
  return Timestamp.newBuilder()
      .setSeconds(seconds)
      .setNanos((int) microsecondsRemainder * NANOSECONDS_PER_MICROSECOND);
}
 
Example 3
Source File: EventsClient.java    From julongchain with Apache License 2.0 3 votes vote down vote up
/**
 * 构造gRPC需要的时间戳
 *
 * @param second 秒,从1970-01-01T00:00:00Z开始算
 * @param nano   纳秒,仅包含尾数
 * @return
 */
private Timestamp buildTimestamp(long second, int nano) {
    Timestamp.Builder timestampBuilder = Timestamp.newBuilder();
    timestampBuilder.setSeconds(second);
    timestampBuilder.setNanos(nano);
    return timestampBuilder.build();
}