Skip to content

Commit

Permalink
gocyclo
Browse files Browse the repository at this point in the history
  • Loading branch information
amyasnikov committed Feb 4, 2021
1 parent fc27ae7 commit 6daf3d8
Show file tree
Hide file tree
Showing 12 changed files with 19,189 additions and 11,166 deletions.
25 changes: 17 additions & 8 deletions mavgen/mavgen.go
Original file line number Diff line number Diff line change
Expand Up @@ -687,14 +687,23 @@ const ({{range .Messages}}
func (d *Dialect) generateInit(w io.Writer) error {
initTmpl := `
{{if .Messages}}
func init() { {{range .Messages}}
register.Register(MSG_ID_{{.Name}}, "MSG_ID_{{.Name}}", {{.Size}}, {{.CRCExtra}}, func(p packet.Packet) (message.Message, error) {
msg := new({{.Name | UpperCamelCase}})
if err := msg.Unmarshal(p.Payload()); err != nil {
return nil, err
}
return msg, nil
}){{end}}
func init() {
for msgID, info := range map[message.MessageID]register.MessageInfo{ {{range .Messages}}
MSG_ID_{{.Name}}: {
"MSG_ID_{{.Name}}",
{{.Size}},
{{.CRCExtra}},
func(p packet.Packet) (message.Message, error) {
msg := new({{.Name | UpperCamelCase}})
if err := msg.Unmarshal(p.Payload()); err != nil {
return nil, err
}
return msg, nil
},
},{{end}}
} {
register.Register(msgID, info.Name, info.Size, info.Extra, info.Constructor)
}
} {{end}}
`
return template.Must(template.New("init").Funcs(funcMap).Parse(initTmpl)).Execute(w, d)
Expand Down
Loading

0 comments on commit 6daf3d8

Please sign in to comment.