Scalar Data Types in Protobuf
Learn about the inbuilt data types available in Protobuf and how these get translated to the C# data type.
We'll cover the following...
In this lesson, we'll have a look at built-in data types available in Protobuf. We'll also learn how these get translated to the C# data type. We'll see how these basic data types work by adding them to the setup we've built previously. The code widget below contains the full setup that we have built up to this point, containing both the gRPC client and server applications.
syntax = "proto3";
option csharp_namespace = "BasicGrpcService";
package basic_grpc_service;
service Chatbot {
rpc SendMessage (ChatRequest) returns (ChatReply);
}
message ChatRequest {
string name = 1;
string message = 2;
}
message ChatReply {
string message = 1;
}
The inbuilt data types are also known as scalar value types. These are the primitive data types that are available in Protobuf without using any external libraries. Previously, we used string, which is one such data type, which holds textual information. However, now we'll modify our Protobuf definition to include all other types. To do so, we'll go back to our BasicGrpcService and BasicGrpcClient projects in the code widget above. We'll then replace the content inside the chatbot.proto file in both of these projects with the following, where the highlighted lines show the text that we have modified:
We add some new fields to the ChatReply message. The field on line 20 is of the type NumericPayload, which itself is a message type we define on line 23. This type was created solely to showcase all numeric types supported by Protobuf. Now, we'll go over the data types supported by Protobuf.
Scalar value types supported by Protobuf
Let's have a look at every scalar value type supported by Protobuf and see which C# types they get ...