'Packing a Timestamp into a Protobuf3 struct
I am currently trying to use protobuf for data exchange.
My message needs to have a dynamically typed dictionary to transfer data so I am using the protobuf type Struct.
I am now trying to solve the problem that Struct only seems to work with primitive types but I need to at least be able to also give it a Timestamp value.
Protofile:
syntax = "proto3";
import "google/protobuf/timestamp.proto";
import "google/protobuf/struct.proto";
message SensorReading {
enum SensorTypes {
Generic_MultiValue = 0;
GPS = 1;
}
google.protobuf.Timestamp MeasurementTime = 1;
string SensorName = 2;
SensorTypes SensorType = 3;
google.protobuf.Struct Values = 4;
}
C# code:
using ProtoTypes = Google.Protobuf.WellKnownTypes;
using Google.Protobuf;
(...)
SensorReading reading = new SensorReading()
{
MeasurementTime = ProtoTypes.Timestamp.FromDateTimeOffset(DateTimeOffset.UtcNow),
SensorName = "me3630_gps",
SensorType = SensorReading.Types.SensorTypes.Gps,
Values = new ProtoTypes.Struct()
{
Fields =
{
["positionTime"] = ProtoTypes.Timestamp.FromDateTimeOffset(gps.PositionTime), // <--- Timestamp is not compatible with Value
["latitude"] = ProtoTypes.Value.ForNumber(gps.Latitude),
["longitude"] = ProtoTypes.Value.ForNumber(gps.Longitude),
["speedOverGround"] = ProtoTypes.Value.ForNumber(gps.SpeedOverGround),
}
}
};
Is it possible to somehow pack timestamp into a struct or will I have to use a workaround? (For example use a number and convert the time to a unix timestamp)
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
