Search in sources :

Example 1 with MethodDescriptor

use of com.google.protobuf.Descriptors.MethodDescriptor in project jvm-serializers by eishay.

the class ProtoServerHandler method handle.

void handle(final OutputStream os, final InputStream is) throws IOException {
    RpcCallback<Message> done = new RpcCallback<Message>() {

        DataOutputStream dos = new DataOutputStream(os);

        public void run(Message content) {
            try {
                byte[] array = _serializer.serialize((MediaContent) content);
                dos.writeInt(array.length);
                dos.write(array);
                dos.flush();
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    };
    DataInputStream dis = new DataInputStream(is);
    int index = dis.readInt();
    MethodDescriptor method = getDescriptor().getMethods().get(index);
    byte[] array = new byte[dis.readInt()];
    dis.readFully(array);
    Message request = getRequestPrototype(method).newBuilderForType().mergeFrom(array).build();
    callMethod(method, null, request, done);
}
Also used : Message(com.google.protobuf.Message) DataOutputStream(java.io.DataOutputStream) RpcCallback(com.google.protobuf.RpcCallback) DataInputStream(java.io.DataInputStream) MethodDescriptor(com.google.protobuf.Descriptors.MethodDescriptor) IOException(java.io.IOException)

Example 2 with MethodDescriptor

use of com.google.protobuf.Descriptors.MethodDescriptor in project tesla by linking12.

the class ServiceResolver method resolveServiceMethod.

private MethodDescriptor resolveServiceMethod(String serviceName, String methodName, String packageName) {
    ServiceDescriptor service = findService(serviceName, packageName);
    MethodDescriptor method = service.findMethodByName(methodName);
    if (method == null) {
        throw new IllegalArgumentException("Unable to find method " + methodName + " in service " + serviceName);
    }
    return method;
}
Also used : ServiceDescriptor(com.google.protobuf.Descriptors.ServiceDescriptor) MethodDescriptor(com.google.protobuf.Descriptors.MethodDescriptor)

Example 3 with MethodDescriptor

use of com.google.protobuf.Descriptors.MethodDescriptor 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

MethodDescriptor (com.google.protobuf.Descriptors.MethodDescriptor)3 FileDescriptorSet (com.google.protobuf.DescriptorProtos.FileDescriptorSet)1 ServiceDescriptor (com.google.protobuf.Descriptors.ServiceDescriptor)1 InvalidProtocolBufferException (com.google.protobuf.InvalidProtocolBufferException)1 Message (com.google.protobuf.Message)1 RpcCallback (com.google.protobuf.RpcCallback)1 RpcBizException (com.quancheng.saluki.core.grpc.exception.RpcBizException)1 DataInputStream (java.io.DataInputStream)1 DataOutputStream (java.io.DataOutputStream)1 IOException (java.io.IOException)1 ImmutablePair (org.apache.commons.lang3.tuple.ImmutablePair)1