You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
How can I marshal a number from a structure to YAML in hexadecimal representation?
I have a structure with integer fields, the representation of which makes sense to humans in hexadecimal form. I want to save this data to a YAML file for manual editing and then load it from the file. go-yaml (I use v3) encodes integers in decimal form only.
I tried to make a custom marshaler based on the documentation (playground link):
How can I marshal a number from a structure to YAML in hexadecimal representation?
I have a structure with integer fields, the representation of which makes sense to humans in hexadecimal form. I want to save this data to a YAML file for manual editing and then load it from the file. go-yaml (I use v3) encodes integers in decimal form only.
I tried to make a custom marshaler based on the documentation (playground link):
But in this case, the number is generated as a string:
And in order to then unmarshal this line into a number, I will also have to write a custom unmarshaler.
Is there any other way?
So far, I've made a fork and added the ability to set the format in the form of structure tags:
I replaced the module in go.mod and that solved my problem for now. But it would be nice to have a built-in feature.
The text was updated successfully, but these errors were encountered: