1.5 KiB
tars supports syntax of protobuf service
Maybe there are a lots of businesses use by the protocol of protobuf that you have worked when you know tars. If you want to use tars for your businesses code, you must translate proto files into tars which is very troublesome and error prone. Pleasant is that tars provides direct support for proto files by using plugin mechanism of protoc. This mechanism can generate code about tars rpc automatically which makes you migration smooth and worry free.
Instructions
1. write your proto files
The syntax of the proto file is not limited, so you can use proto2 or proto3. But you must add option cc_generic_services=false; to your proto files. Because using the pb rpc interface generated by protoc it not our goal. Our goal is that taking over with the tars plugin to generate a rpc interface which conforms to the tars framework. An example of a proto file:
syntax = "proto2";
option cc_generic_services=false;
package TestApp;
message PbRequest {
required int32 a = 1;
required int32 b = 2;
}
message PbResponse {
required int32 c = 1;
}
service Hello {
rpc add(PbRequest) returns (PbResponse) {
}
}
2. make
Because of the statement that calls the tars pb plugin is already built into the makefile.tars, you just need to execute make. Tars plugin follows the rule that the file with a .pb.h suffix generated by protoc, so its generated file has a .tars.h suffix.