Post

gRPC Protobuf Data Types

the goal of this article is to get a complete list of gRPC data type in a single document, kind of cheat sheet.

There are 3 type of protobuf data types

  1. Scalar Value types
  2. Well known types
  3. Google common types
  4. Custom types

Scalar Value types

these are common data types used in protobuf. scalar data type does not support null values. you can find more complete list here .

1
2
3
4
5
6
syntax = "proto3"
message Something {
   string subject = 1;
   int32 id = 2;
   float floatVar = 3;
}

Well known types

there are more advance types provided by google. these supports null values. you can find complete list here For using these you have to import them.

1
2
3
4
5
6
7
8
9
10
11
12
13
syntax = "proto3"

import "google/protobuf/duration.proto";
import "google/protobuf/timestamp.proto";
import "google/protobuf/wrappers.proto"
message Meeting {

    google.protobuf.StringValue subject = 1;
    google.protobuf.Timestamp time = 2;
    google.protobuf.Duration duration = 3;

}

Google common types

there are few custom data types provided by google, these are specially made for advance cases like money, phone number etc. if you want to use them just copy the proto file and put it into your project and import it. you can find all the implementation here

Custom types

google common types are kind of custom types, you can create your own proto file and define something there and use it.

you can just refer to one of the google common type.

Addition Links

  • https://docs.microsoft.com/en-us/dotnet/architecture/grpc-for-wcf-developers/protobuf-data-types
  • https://developers.google.com/protocol-buffers/docs/proto3?source=post_page—–7148ce60b54b——————————–
  • https://developers.google.com/protocol-buffers/docs/reference/google.protobuf?source=post_page—–7148ce60b54b——————————–
This post is licensed under CC BY 4.0 by the author.