Search in sources :

Example 1 with RpcBizException

use of com.quancheng.saluki.core.grpc.exception.RpcBizException in project tesla by linking12.

the class ProtobufUtil method findDirectyprotobuf.

private static Pair<Descriptor, Descriptor> findDirectyprotobuf(final FilterRpcDO rpcDo) {
    byte[] protoContent = rpcDo.getProtoContext();
    FileDescriptorSet descriptorSet = null;
    if (protoContent != null && protoContent.length > 0) {
        try {
            descriptorSet = FileDescriptorSet.parseFrom(protoContent);
            ServiceResolver serviceResolver = ServiceResolver.fromFileDescriptorSet(descriptorSet);
            ProtoMethodName protoMethodName = ProtoMethodName.parseFullGrpcMethodName(rpcDo.getServiceName() + "/" + rpcDo.getMethodName());
            MethodDescriptor protoMethodDesc = serviceResolver.resolveServiceMethod(protoMethodName);
            return new ImmutablePair<Descriptor, Descriptor>(protoMethodDesc.getInputType(), protoMethodDesc.getOutputType());
        } catch (InvalidProtocolBufferException e) {
            LOG.error(e.getMessage(), e);
            throw new RpcBizException("protobuf service definition is invalid,the descriptorSet is: " + descriptorSet, e);
        }
    }
    return null;
}
Also used : ImmutablePair(org.apache.commons.lang3.tuple.ImmutablePair) FileDescriptorSet(com.google.protobuf.DescriptorProtos.FileDescriptorSet) RpcBizException(com.quancheng.saluki.core.grpc.exception.RpcBizException) InvalidProtocolBufferException(com.google.protobuf.InvalidProtocolBufferException) MethodDescriptor(com.google.protobuf.Descriptors.MethodDescriptor)

Aggregations

FileDescriptorSet (com.google.protobuf.DescriptorProtos.FileDescriptorSet)1 MethodDescriptor (com.google.protobuf.Descriptors.MethodDescriptor)1 InvalidProtocolBufferException (com.google.protobuf.InvalidProtocolBufferException)1 RpcBizException (com.quancheng.saluki.core.grpc.exception.RpcBizException)1 ImmutablePair (org.apache.commons.lang3.tuple.ImmutablePair)1