Proto To Ballerina

If you already have protocol buffer file for your service(s) you can use that to autogenerate Ballerina source code. Currently, Ballerina supports two types of code generation. service generation generates a mock version of the Ballerina service for an input proto definition. client generation generates a Ballerina client endpoint for an input proto definition. The Ballerina code generator supports the following parameters: --input The path of the .proto file. This is a mandatory parameter. --output The file location in which the Ballerina client/service and the stub must be generated. This is an optional parameter. If no value is specified for this parameter and proto definition doesn’t contain package value, the Ballerina client/service and the stub files are generated inside temp directory in the current location. This path must be a project directory. --mode The mode (client or server) to generate code samples. If no value is specified for this parameter, only the stub file will be generated.

For more information on the underlying module, see the GRPC module and How to generate Ballerina code for Protocol Buffer Definition.

syntax = "proto3";
service helloWorld {
    rpc hello(HelloRequest) returns (HelloResponse);
    rpc bye(ByeRequest) returns (ByeResponse);
}
message HelloRequest {
	string name = 1;
}
message HelloResponse {
	string message = 1;
}
message ByeRequest {
	string greet = 1;
}
message ByeResponse {
	string say = 1;
}
# Execute the command below in the Ballerina tools distribution to generate the mock service.
bal grpc --input proto_to_ballerina.proto --mode service --output service
# Execute the command below in the Ballerina tools distribution to generate the client endpoint and the stub file.
bal grpc --input proto_to_ballerina.proto --mode client --output client
# Execute the command below in the Ballerina tools distribution to generate the stub file.
bal grpc --input proto_to_ballerina.proto