utzig commented on a change in pull request #266: `newt target dump` command URL: https://github.com/apache/mynewt-newt/pull/266#discussion_r256391583
########## File path: newt/syscfg/restrict.go ########## @@ -82,6 +84,48 @@ type CfgRestriction struct { Expr string } +func (c CfgRestrictionCode) String() string { + for s, code := range cfgRestrictionNameCodeMap { + if code == c { + return s + } + } + + return "???" +} + +func parseCfgRestrictionCode(s string) (CfgRestrictionCode, error) { + if c, ok := cfgRestrictionNameCodeMap[s]; ok { + return c, nil + } + + return 0, util.FmtNewtError("cannot parse cfg restriction code \"%s\"", s) +} + +func (c CfgRestrictionCode) MarshalJSON() ([]byte, error) { + s := c.String() + j, err := json.Marshal(s) + if err != nil { + return nil, util.ChildNewtError(err) + } + return j, nil +} + +func (c *CfgRestrictionCode) UnmarshalJSON(b []byte) error { Review comment: These marshal / unmarshall functions look pretty much the same that the ones in `marshal.go` with a different struct being marshalled and a different string parsing functions, perhaps they could be standalone and called passing the string parsing function? ---------------------------------------------------------------- This is an automated message from the Apache Git Service. To respond to the message, please log on GitHub and use the URL above to go to the specific comment. For queries about this service, please contact Infrastructure at: us...@infra.apache.org With regards, Apache Git Services