Skip to content

Commit

Permalink
Add MarshalBinary() func to enums
Browse files Browse the repository at this point in the history
  • Loading branch information
amyasnikov committed Feb 26, 2021
1 parent d2b09c4 commit be15b97
Show file tree
Hide file tree
Showing 13 changed files with 5,485 additions and 0 deletions.
5 changes: 5 additions & 0 deletions mavgen/mavgen.go
Original file line number Diff line number Diff line change
Expand Up @@ -561,6 +561,7 @@ func (d *Dialect) generateGo(dialectPath string, packageName string, commonPacka
if len(d.Enums) > 0 {
return []string{
"fmt",
"strconv",
}
}
return nil
Expand Down Expand Up @@ -644,6 +645,10 @@ func (d *Dialect) generateEnums(w io.Writer) error {
// {{$enumName}} type{{if .Description}}. {{.Description}}{{end}}
type {{.Name}} int
func (e {{.Name}}) MarshalBinary() (data []byte, err error) {
return []byte(strconv.Itoa(int(e))), nil
}
const ({{range .Entries}}
// {{.Name}} enum{{if .Description}}. {{.Description}}{{end}}
{{.Name}} {{$enumName}} = {{.Value}} {{end}}
Expand Down
Loading

0 comments on commit be15b97

Please sign in to comment.