Handling dates, times, and decimal numbers
You might have noted that there are no date/time types built into gRPC. To store these values, you must use well-known type extensions, for example, google.protobuf.Timestamp
(equivalent to DateTimeOffset
) and google.protobuf.Duration
(equivalent to TimeSpan
).
To use them as field types in a message, they must be imported, as shown in the following code:
syntax = "proto3";
import "google/protobuf/duration.proto";
import "google/protobuf/timestamp.proto";
message Employee {
int32 employeeId = 1;
google.protobuf.Timestamp birth_date = 2;
google.protobuf.Duration earned_vacation_time = 3;
...
}
The class generated will not use .NET types directly. Instead, there are intermediate types, as shown in the following code:
public class Employee
{
public int EmployeeId;
public Timestamp BirthDate;
public Duration EarnedVacationTime;
}
There are conversion methods on the types FromDateTimeOffset...