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);
}
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;
}
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;
}
Aggregations