com.google.protobuf.Any.is()方法的使用及代码示例

x33g5p2x  于2022-01-16 转载在 其他  
字(2.0k)|赞(0)|评价(0)|浏览(278)

本文整理了Java中com.google.protobuf.Any.is()方法的一些代码示例,展示了Any.is()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Any.is()方法的具体详情如下:
包路径:com.google.protobuf.Any
类名称:Any
方法名:is

Any.is介绍

暂无

代码示例

代码示例来源:origin: com.google.protobuf/protobuf-java

@java.lang.SuppressWarnings("unchecked")
public <T extends com.google.protobuf.Message> T unpack(
  java.lang.Class<T> clazz)
  throws com.google.protobuf.InvalidProtocolBufferException {
 if (!is(clazz)) {
  throw new com.google.protobuf.InvalidProtocolBufferException(
    "Type of the Any message does not match the given class.");
 }
 if (cachedUnpackValue != null) {
  return (T) cachedUnpackValue;
 }
 T defaultInstance =
   com.google.protobuf.Internal.getDefaultInstance(clazz);
 T result = (T) defaultInstance.getParserForType()
   .parseFrom(getValue());
 cachedUnpackValue = result;
 return result;
}
public static final int TYPE_URL_FIELD_NUMBER = 1;

代码示例来源:origin: com.athaydes.protobuf/protobuf-tcp-rpc

static Object convert(Any any, Class<?> type) throws InvalidProtocolBufferException {
  if (Message.class.isAssignableFrom(type)) {
    Class<? extends Message> messageType = type.asSubclass(Message.class);
    if (any.is(messageType)) {
      return any.unpack(messageType);
    }
  }
  // not a protobuf type, try a Java type
  return convertJavaType(any, type);
}

代码示例来源:origin: com.xorlev.grpc-jersey/jersey-rpc-support

public static Response createJerseyResponse(Throwable t) {
  GrpcErrorUtil.GrpcError grpcError = GrpcErrorUtil.throwableToStatus(t);
  int httpStatusCode = GrpcErrorUtil.grpcToHttpStatus(grpcError.getStatus());
  Response.ResponseBuilder httpResponse = Response.status(httpStatusCode);
  try {
    for (Any extra : grpcError.getPayload().getDetailsList()) {
      if (extra.is(RetryInfo.class)) {
        RetryInfo retryInfo = extra.unpack(RetryInfo.class);
        if (retryInfo.hasRetryDelay()) {
          httpResponse.header("Retry-After", Durations.toSeconds(retryInfo.getRetryDelay()));
        }
      }
    }
    httpResponse.entity(JsonFormat.printer().print(grpcError.getPayload().toBuilder().clearDetails().build()));
  } catch (InvalidProtocolBufferException e) {
    // this should never happen
    throw new RuntimeException(e);
  }
  return httpResponse.build();
}

相关文章