liveBook · Manning

Proto3

As explained in Building Web APIs with ASP.NET Core

Proto3 is version 3 of the Protocol Buffers interface-description and serialization syntax.

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

How Building Web APIs with ASP.NET Core covers it

How deep it goes
Covers file structure, messages, field indexes, and project integration, but defers detailed proto3 syntax.
Examples
Uses GetBoardGame with BoardGameRequest and BoardGameResponse messages containing id, name, and year fields.
What it assumes
Assumes familiarity with C#-style DTOs while showing that proto3 uses a different syntax for similar request and response types.
What you can do after
Build it from scratch by defining a .proto contract and wiring it into a .NET project for stub generation.
How it connects
Connects gRPC services with Protocol Buffers, serialization, DTOs, and generated client and server stubs.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Building Web APIs with ASP.NET Core. The section links point to the parts of the book it draws on.