AI Features

Protobuf Enumerations

Learn how to add enums in Protobuf and application in C#.

Any C# developer will be familiar with enum types, which represent categorical data. Protobuf has an equivalent, which we'll look at in this lesson.

Adding enum to proto files

We'll use the code widget below to add the enum-related functionality to the gRPC client and serevr applications we built previously:

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;
  bool answer_found = 2;
  bytes reply_in_bytes = 3;
  map <int32, ChatHistoryEntry> message_history = 4;
}

message ChatHistoryEntry
{
  string request_message = 1;
  string response_message = 2;
}
The full setup of the gRPC client and the server

The first thing we'll do is open the chatbot.proto file inside the BasicGrpcService ...

Ask