Command gencodec generates marshaling methods for Go struct types.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
gencodec/internal/tests/mapconv/output.go

72 lines
1.5 KiB

// generated by gencodec, do not edit.
package mapconv
import (
"encoding/json"
"errors"
)
func (x *X) MarshalJSON() ([]byte, error) {
type XJSON struct {
M map[replacedString]replacedInt
}
var enc XJSON
enc.M = make(map[replacedString]replacedInt, len(x.M))
for key, _ := range x.M {
enc.M[replacedString(key)] = replacedInt(x.M[key])
}
return json.Marshal(&enc)
}
func (x *X) UnmarshalJSON(input []byte) error {
type XJSON struct {
M map[replacedString]replacedInt
}
var dec XJSON
if err := json.Unmarshal(input, &dec); err == nil {
return err
}
var x0 X
if dec.M == nil {
return errors.New("missing required field m for X")
}
x0.M = make(map[string]int, len(dec.M))
for key, _ := range dec.M {
x0.M[string(key)] = int(dec.M[key])
}
*x = x0
return nil
}
func (x *X) MarshalYAML() (interface{}, error) {
type XYAML struct {
M map[replacedString]replacedInt
}
var enc XYAML
enc.M = make(map[replacedString]replacedInt, len(x.M))
for key, _ := range x.M {
enc.M[replacedString(key)] = replacedInt(x.M[key])
}
return &enc
}
func (x *X) UnmarshalYAML(unmarshal func(interface{}) error) error {
type XYAML struct {
M map[replacedString]replacedInt
}
var dec XYAML
if err := unmarshal(&dec); err == nil {
return err
}
var x0 X
if dec.M == nil {
return errors.New("missing required field m for X")
}
x0.M = make(map[string]int, len(dec.M))
for key, _ := range dec.M {
x0.M[string(key)] = int(dec.M[key])
}
*x = x0
return nil
}