cbor
cbor copied to clipboard
feature: Add option to return RFC3339 string while decoding tag 0 & 1 into interface{}
Is your feature request related to a problem? Please describe. When decoding a cbor data item, tagged with either tag 0 or tag 1, into an empty interface type, unmarshal returns a value of type time.Time. I would like a new decoding option with which unmarshal returns a RFC3339 string. This is needed to ensure compatibility in a project which expects unmarshal to return only certain types (bool, float64, string, []interface{}, map[string]interface{}, or nil).
Describe the solution you'd like
A new decode Option TimeTagToAnyMode whose default mode TimeTagToGoTime returns a time.Time value (current behavior). TimeTagToRFC3339String returns a time string in RFC3339 format and TimeTagToRFC3339NanoString returns a time string with nano seconds in RFC3339 format.
Additional context I'd be happy to contribute the changes needed for this feature.
Hey @ssuriyan7 thanks for opening this feature request!
Please feel free to open a PR to implement TimeTagToAnyMode decoding option. Maybe with these option names:
TimeTagToTimeTimeTagToRFC3339TimeTagToRFC3339Nano
Waiting for https://github.com/fxamacker/cbor/pull/503 to merge as this option should be implemented on top of that change.
Hey @ssuriyan7 the PR got merged tonight:
- #503
Closed by #506