Protobuf as the Communication Protocol of gRPC
Explore the structure and function of Protobuf in gRPC communications within ASP.NET Core. Learn how Protobuf schema defines messages, services, and namespaces, and discover how message serialization translates into auto-generated C# classes for client and server applications.
We'll cover the following...
So far, we've had a look at the basic structure of gRPC client and server on .NET. Both of these applications share the same Protobuf file. This is the file that defines the schema used by Protobuf serializer to construct the messages exchanged between two applications.
In this lesson, we'll delve deeper into the structure of this messaging format. We'll start by looking closely at the Protobuf file we've already used.
Basic Protobuf file structure
To recap, the Protobuf file that both the client and server have been using has the following content:
Let's go through this line by line to see what it does. The first statement that we see inside is syntax = "proto". This statement explicitly tells us that we're using version three of Protobuf. The previous version, proto2, is also available. However, there are some breaking changes between the versions. Since version three is the most recent, it's better to use it. Version one, on the other hand, is unavailable, because it existed before the gRPC framework was open-sourced. Then, we have the following statement on line 3:
The option ...