Timestamp in nanopb

513 views Asked by At

Is there support for google.protobuf.Timestamp datatype and encode decode function in nanopb ? Or we should encode/decode as int64 or may be uint32 (if possible till year 2106) ? The target device is a 32bit MCU and server end is a java based implementation.

3

There are 3 answers

0
jpa On

google.protobuf.Timestamp is just a "well known" message type. Its definition is available from timestamp.proto in Google's repository:

message Timestamp {
  int64 seconds = 1;
  int32 nanos = 2;
}

You can build timestamp.proto using nanopb generator the same way you build other .proto files.

0
Cyril On

You can use the timestamp.proto file from google protobuf package and compile it with nanopb directly to generate timestamp.pb.h and timestamp.pb.c file.

0
LappiesJA On

I know this is a comment on a old post, but I had a similar question on the ESP32 and came across this so I thought I would chime in.

As stated by JPA, if you build the nanopb files it is fairly easy to use.

How I used it:

google_protobuf_Timestamp timestamp;
timestamp.seconds = esp_log_timestamp()/1000;

I was only interested in second intervals and not miliseconds so that is why I divided by 1000.

I works well and it is still encoded.