Java Code Examples for com.google.protobuf.Value#getStringValue()

The following examples show how to use com.google.protobuf.Value#getStringValue() . 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: StructUtil.java    From rejoiner with Apache License 2.0 6 votes vote down vote up
private static Object getScalarValue(Value value) {
  switch (value.getKindCase()) {
    case STRUCT_VALUE:
    case LIST_VALUE:
      throw new AssertionError("value should be scalar");
    case BOOL_VALUE:
      return value.getBoolValue();
    case NUMBER_VALUE:
      // Note: this assumes all numbers are doubles. Downstream code that have access to the
      // schema can convert this number to the correct number type.
      return value.getNumberValue();
    case STRING_VALUE:
      return value.getStringValue();
    default:
      break;
  }
  return value;
}
 
Example 2
Source File: ValueUtils.java    From cloud-spanner-r2dbc with Apache License 2.0 5 votes vote down vote up
private static LocalDateTime parseTimestamp(Value proto) {
  if (proto.getKindCase() == KindCase.NULL_VALUE || proto.getStringValue() == null) {
    return null;
  }
  TemporalAccessor temporalAccessor = TIMESTAMP_FORMATTER.parse(proto.getStringValue());
  return LocalDateTime.ofInstant(Instant.from(temporalAccessor), ZoneOffset.UTC);
}
 
Example 3
Source File: ValueUtils.java    From cloud-spanner-r2dbc with Apache License 2.0 5 votes vote down vote up
private static LocalDate parseDate(Value proto) {
  String date = proto.getStringValue();
  if (proto.getKindCase() == KindCase.NULL_VALUE || date == null) {
    return null;
  }
  Matcher matcher = FORMAT_REGEXP.matcher(date);
  if (!matcher.matches()) {
    throw new IllegalArgumentException("Invalid date: " + date);
  } else {
    int year = Integer.parseInt(matcher.group(1));
    int month = Integer.parseInt(matcher.group(2));
    int dayOfMonth = Integer.parseInt(matcher.group(3));
    return LocalDate.of(year, month, dayOfMonth);
  }
}
 
Example 4
Source File: PartialResultRowExtractor.java    From cloud-spanner-r2dbc with Apache License 2.0 5 votes vote down vote up
private void concatFirstIncompletePiece(PartialResultSet partialResultSet) {
  Value firstPiece = partialResultSet.getValues(0);
  // Concat code from client lib
  if (this.incompletePieceKind == KindCase.STRING_VALUE) {
    this.incompletePiece = this.incompletePiece + firstPiece.getStringValue();
  } else {
    concatLists((List<Value>) this.incompletePiece,
        firstPiece.getListValue().getValuesList());
  }
}
 
Example 5
Source File: VariantToVcf.java    From genomewarp with Apache License 2.0 5 votes vote down vote up
private static Object parseObject(String key, Value in, VCFHeaderLineType type) {
  // Case on type
  switch (in.getKindCase()) {
      case NULL_VALUE: throw new IllegalStateException(String.format("field %s contained "
          + "a null value", key));
      case NUMBER_VALUE: return getNumberValue(in.getNumberValue(), type);
      case STRING_VALUE: return in.getStringValue();
      case BOOL_VALUE: return (Boolean) in.getBoolValue();
      default: throw new IllegalStateException(String.format("field %s contained a %s type, which"
          + " is not supported by VariantToVcf", key, getKind(in.getKindCase())));
  }
}
 
Example 6
Source File: SdsClient.java    From grpc-java with Apache License 2.0 5 votes vote down vote up
@VisibleForTesting
static ChannelInfo extractChannelInfo(ConfigSource configSource) {
  checkNotNull(configSource, "configSource");
  checkArgument(
      configSource.hasApiConfigSource(), "only configSource with ApiConfigSource supported");
  ApiConfigSource apiConfigSource = configSource.getApiConfigSource();
  checkArgument(
      ApiType.GRPC.equals(apiConfigSource.getApiType()),
      "only GRPC ApiConfigSource type supported");
  checkArgument(
      apiConfigSource.getGrpcServicesCount() == 1,
      "expecting exactly 1 GrpcService in ApiConfigSource");
  GrpcService grpcService = apiConfigSource.getGrpcServices(0);
  checkArgument(
      grpcService.hasGoogleGrpc() && !grpcService.hasEnvoyGrpc(),
      "only GoogleGrpc expected in GrpcService");
  GoogleGrpc googleGrpc = grpcService.getGoogleGrpc();
  CallCredentials callCredentials = getVerifiedCredentials(googleGrpc);
  String targetUri = googleGrpc.getTargetUri();
  String channelType = null;
  if (googleGrpc.hasConfig()) {
    Struct struct = googleGrpc.getConfig();
    Value value = struct.getFieldsMap().get("channelType");
    channelType = value.getStringValue();
  }
  checkArgument(!Strings.isNullOrEmpty(targetUri), "targetUri in GoogleGrpc is empty!");
  return new ChannelInfo(targetUri, channelType, callCredentials);
}
 
Example 7
Source File: ValueUtils.java    From cloud-spanner-r2dbc with Apache License 2.0 4 votes vote down vote up
private static String parseString(Value input) {
  return input.getKindCase() == KindCase.NULL_VALUE ? null : input.getStringValue();
}
 
Example 8
Source File: ValueUtils.java    From cloud-spanner-r2dbc with Apache License 2.0 4 votes vote down vote up
private static ByteBuffer parseBytes(Value value) {
  if (value.getKindCase() == KindCase.NULL_VALUE || value.getStringValue() == null) {
    return null;
  }
  return ByteBuffer.wrap(value.getStringValueBytes().toByteArray());
}
 
Example 9
Source File: PartialResultRowExtractor.java    From cloud-spanner-r2dbc with Apache License 2.0 4 votes vote down vote up
private void initializeIncompletePiece(Value lastVal) {
  this.incompletePieceKind = lastVal.getKindCase();
  this.incompletePiece =
          lastVal.getKindCase() == KindCase.STRING_VALUE ? lastVal.getStringValue() :
                  new ArrayList<>(lastVal.getListValue().getValuesList());
}