Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to store time in protobuf 3

Tags:

I have this struct in golang

struct File {
  name string
  creatation_time time.Time
}

How do I write it in protobuf3 ?

like image 785
thanhpk Avatar asked Feb 22 '17 07:02

thanhpk


People also ask

What is Protobuf timestamp?

Reference documentation and code samples for the Kubernetes Engine V1 API class Google::Protobuf::Timestamp. A Timestamp represents a point in time independent of any time zone or local calendar, encoded as a count of seconds and fractions of seconds at nanosecond resolution.

Is Protobuf 3 backwards compatible?

It can accept input crafted by later versions of protobuf. The sender is backward compatible because it's creating output that can be consumed by earlier versions. So long as you're careful about when and how you change and remove fields, your protobuf will be forward and backward compatible.

Is Google Protobuf timestamp Nullable?

Protobuf messages are either present (possibly default) valued or optional but they can't be null.

How do I set default value in Protobuf?

For bool s, the default value is false. For numeric types, the default value is zero. For enums , the default value is the first value listed in the enum's type definition. This means care must be taken when adding a value to the beginning of an enum value list.


1 Answers

Create example.proto;

syntax = "proto3";

import google_protobuf "github.com/golang/protobuf/ptypes/timestamp"

message File {
    string name = 1;
    google.protobuf.Timestamp creatation_time = 2;  
}

After compilation check the example.pb.go for the structure definition that has been created.

like image 64
Guirish Salgaonkar Avatar answered Nov 01 '22 15:11

Guirish Salgaonkar