time.Time and gogo/protobuf

319 views
Skip to first unread message

Markus Mahlberg

unread,
Feb 2, 2016, 9:44:29 AM2/2/16
to gogoprotobuf
Hi List!

Is there any way to have a message field be unmarshalled to time.Time? Since I am aware of issue #113 (and #57,respectively), I was trying to find a workaround. I am open to use syntax 2 or 3.

I tried to implement a custom field type being a type alias for time.Time implementing the Marshal and Unmarshal interface and use casttype to have it cast to time.Time, but on generation, this causes an error:

protoc-gen-gogo: error:timestamp cannot be custom type and cast type


The reason for this requirement is that I want to persist the unmarshalled  instance into MongoDB, where it is supposed to be processed by the ISODate value time.Time gets marshalled to by mgo.

As a last resort, I could have a type alias for the message and (un)marshal an additional time.Time field for MongoDB's BSON accordingly, but that seems like a rather inelegant solution, hence my question.


Thanks in advance,

Markus

Walter Schulze

unread,
Feb 2, 2016, 9:52:52 AM2/2/16
to Markus Mahlberg, gogoprotobuf
I hope that https://github.com/gogo/protobuf/issues/57 will solve your issue in future.
I suspect https://github.com/gogo/protobuf/issues/28 would also have helped.
So yes the type alias is the only current solution which is definitely not ideal.

--
You received this message because you are subscribed to the Google Groups "gogoprotobuf" group.
To unsubscribe from this group and stop receiving emails from it, send an email to gogoprotobuf...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply all
Reply to author
Forward
0 new messages