'Can the .proto file be generated from the server by any client?
I have seen that Evans CLI can be used to determine the exposed messages and sessions on the server from the client setup. Is it possible that the .proto file being used by the server (containing messages and session details), can be generated on the client setup? If yes how and if no then how can Evans access those messages?
I am new to the concepts of gRPC so this would be very helpful. The only thing I know is, in GoLang we use reflector to enable Evans CLI to access messages and services.
Solution 1:[1]
The server can choose to enable reflection so you can see the registered RPCs and proto messages. Here is a general blurb about it:
https://github.com/grpc/grpc/blob/master/doc/server-reflection.md
You can use grpc_cli, which is packaged as part of gRPC, to get the list of RPCs and the message protos as described here:
https://grpc.github.io/grpc/cpp/md_doc_server_reflection_tutorial.html
$ grpc_cli ls localhost:50051
output:
helloworld.Greeter
grpc.reflection.v1alpha.ServerReflection
$ grpc_cli ls localhost:50051 helloworld.Greeter -l
output, where the "service" part shows what the proto should look like and contains the proto filename also.
filename: helloworld.proto
package: helloworld;
service Greeter {
rpc SayHello(helloworld.HelloRequest) returns (helloworld.HelloReply) {}
}
To get information about the message, you can use this:
$ grpc_cli type localhost:50051 helloworld.HelloRequest
output:
message HelloRequest {
optional string name = 1;
}
grpc_cli is the official tool packaged with grpc. Evans CLI is a third party client that is using public APIs to generate the same information. As long as the server exports it, you can access it programmatically in your code (the first link contains pointers to other languages also), in a script using grpc_cli, or using the third party clients. You can then take the information exported from the server to create your own proto files.
However, if the server does not support reflection, you're out of luck.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | QOTJ |