proto3 is the Protocol Buffers version 3 syntax used to describe gRPC services and the messages they exchange. In a .NET board-game API, a .proto file defines the contract shared by the client and server. section 10.3.4
Apply proto3 to the project by:
- Creating /gRPC/grpc.proto and declaring the proto3 syntax, C# namespace, package, service, RPC method, request message, and response message. section 10.3.4
- Assigning numeric field indexes such as id = 1 and name = 2; these indexes support protobuf serialization and compression rather than representing default values. section 10.3.4
- Registering the .proto file in the project file with a Protobuf Include entry so the .NET compiler generates client and server stubs. section 10.3.4
Listing 10.7 /gRPC/grpc.proto file
syntax = "proto3";
option csharp_namespace = "MyBGList.gRPC";
package Grpc;
service Grpc {
rpc GetBoardGame (BoardGameRequest) returns (BoardGameResponse); #1
}
message BoardGameRequest { #2
int32 id = 1;
}
message BoardGameResponse { #3
int32 id = 1;
string name = 2;
int32 year = 3;
}
Inspect the complete grpc.proto contract, including GetBoardGame, BoardGameRequest, and BoardGameResponse. section 10.3.4
