protobuf
Getting started
Protocol Buffers are a language-neutral, platform-neutral extensible mechanism for serializing structured data.
Each service has own protocol for send/consume data.
Each service has own directory with 3 simple file:
- SERVICE_NAME_grpc_pb.js [server]
- SERVICE_NAME_pb.js [client]
- SERVICE_NAME.proto [protocol]
##Install
You should need GRPC tools installed globally in NPM, so
npm install -g grpc-tools
##Extending
- Define a service in a .proto file.
- Add new rpc service commands with requests/responses with messages which describe input/output data Example of simple proto auth service with single rpc command checkConnection:
package auth;
service Auth {
rpc checkConnection(PingRequest) returns (PongResponse);
}
message PingRequest {
string ping = 1;
}
message PongResponse {
string pong = 1;
}
- Run command: grpc_tools_node_protoc --js_out=import_style=commonjs,binary:SERVICE_NAME --grpc_out=grpc_js:SERVICE_NAME --proto_path=./SERVICE_NAME ./SERVICE_NAME/*.proto
If you want to process multiple *.proto files at once, run the sh update_prtbuf_version.sh
script found in the root directory. This script will simultaneously update the protobuf version in package.json
and rebuild all grpc_pb / pb
files.