I am trying to use gRPC and using the exchange message format as protobuf. I wanted to add timestamp field inside my message.But i don't know the right way to add the import statement in proto file. I am using Golang so I need an output as .pb.go
Asked
Active
Viewed 3.1k times
15
-
1Even if you've added library for timestamp as mentioned in below answers, be sure to import the package "C:\Program Files\protoc-3.13.0-win64\include" as it contains libraries related to timestamp. Faced error because of path problem thought to share it. – infiniteLearner Oct 21 '20 at 12:23
4 Answers
27
Make sure to import in your proto file:
import "google/protobuf/timestamp.proto";
And use the type for you variable like:
google.protobuf.Timestamp time_name = 1;

Sergeenho
- 339
- 3
- 7
2
In your proto file:
import "google/protobuf/timestamp.proto"
Based on the documentation, that should be all that's necessary.

Eric Anderson
- 24,057
- 5
- 55
- 76
0
You can import timestamp from the ptypes package: in the standard Go Protobuf repo.
import (
"github.com/golang/protobuf/ptypes/timestamp"
)

Carl Mastrangelo
- 5,970
- 1
- 28
- 37
-1
Grpc does not have a timestamp AFAIK.
I usually use the Unix Epoch - the go function
Unix(sec int64, nsec int64)
and
func (t Time) Unix() int64
is your fried

weismat
- 7,195
- 3
- 43
- 58