-
Notifications
You must be signed in to change notification settings - Fork 1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Octal number marshalling #420
Comments
It's a valid feature request. It should be easy to support that via something like an ",octal" field tag. |
@niemeyer The problem with an ",octal" field tag is that it's fixed. |
I'm working on v3 at the moment, which will offer an intermediate state with significantly more control than what the package offers today. There's a quick draft of what it will look like here: https://twitter.com/gniemeyer/status/1073638853225996288 With that you'll be able to marshal your value easily, with the exact formatting you want. |
Just for curiosity... (No pressure at all) |
I'll make it widely available soon. I just want to lock down on the compatibility breakages (MapSlice is coming out and be replaced by nodes, marshaling interfaces will also be based on Node, etc), and then will put it out for early testing. |
Finally another YAML library that recognises that comments warrant preserving in a human readable data format! |
README.md says:
So, how do I encode integers to octal representation? |
In the meantime, this is how you can encode with type OctalMode os.FileMode
func (self OctalMode) String() string {
return "0o" + strconv.FormatUint(uint64(self), 8)
}
func (self OctalMode) MarshalYAML() (interface{}, error) {
return &yaml.Node{
Kind: yaml.ScalarNode,
Tag: "!!int",
Value: self.String(),
}, nil
} In fact, this way you can encode to any number format supported by decoder. One drawback to this approach is that you'll have to convert between the formatter type (here |
Hello, I'm still not sure if it's a question or a feature request.
Is there is a way of marshalling an octal number?
Because when unmarshalling this :
number: 0660
I get:
number: 432
And if I implement Marshaler I get:
number: "0660"
(the string "0660")an not:
number: 0660
(the octal number)When implementing jsonNumber I get the same
The text was updated successfully, but these errors were encountered: