Skip to content

Commit

Permalink
change constructor signature
Browse files Browse the repository at this point in the history
  • Loading branch information
amyasnikov committed Feb 25, 2021
1 parent f7b7f02 commit 46311ce
Show file tree
Hide file tree
Showing 20 changed files with 3,202 additions and 3,218 deletions.
5 changes: 2 additions & 3 deletions mavgen/mavgen.go
Original file line number Diff line number Diff line change
Expand Up @@ -625,7 +625,6 @@ func (d *Dialect) generateGo(dialectPath string, packageName string, commonPacka
if len(d.Messages) > 0 {
return []string{
commonPackage + "/message",
commonPackage + "/packet",
commonPackage + "/register",
}
}
Expand Down Expand Up @@ -710,9 +709,9 @@ func init() {
"MSG_ID_{{.Name}}",
{{.Size}},
{{.CRCExtra}},
func(p packet.Packet) (message.Message, error) {
func(bytes []byte) (message.Message, error) {
msg := new({{.Name | UpperCamelCase}})
return msg, msg.Unmarshal(p.Payload())
return msg, msg.Unmarshal(bytes)
},
},{{end}}
} {
Expand Down
2 changes: 1 addition & 1 deletion mavgen/packetV.go
Original file line number Diff line number Diff line change
Expand Up @@ -300,7 +300,7 @@ func packetVTemplate() string {
"\tif err != nil {\n" +
"\t\treturn nil, err\n" +
"\t}\n" +
"\treturn info.Constructor(p)\n" +
"\treturn info.Constructor(p.payload)\n" +
"}\n" +
"\n" +
"// String function return string view of Packet struct\n" +
Expand Down
2 changes: 1 addition & 1 deletion mavgen/packetV.template
Original file line number Diff line number Diff line change
Expand Up @@ -289,7 +289,7 @@ func (p *packet{{.MavlinkVersion}}) Message() (message.Message, error) {
if err != nil {
return nil, err
}
return info.Constructor(p)
return info.Constructor(p.payload)
}

// String function return string view of Packet struct
Expand Down
5 changes: 2 additions & 3 deletions mavgen/register.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,21 +15,20 @@ func registerTemplate() string {
" \"strconv\"\n" +
" \"{{.CommonPackageURL}}/errors\"\n" +
" \"{{.CommonPackageURL}}/message\"\n" +
" \"{{.CommonPackageURL}}/packet\"\n" +
")\n" +
"\n" +
"// MessageInfo type\n" +
"type MessageInfo struct {\n" +
" Name string\n" +
" Size int\n" +
" Extra uint8\n" +
" Constructor func(p packet.Packet) (message.Message, error)\n" +
" Constructor func(bytes []byte) (message.Message, error)\n" +
"}\n" +
"\n" +
"var supported = make(map[message.MessageID]*MessageInfo)\n" +
"\n" +
"// Register method provide register dialect message on decoder knowledge\n" +
"func Register(msgID message.MessageID, msgName string, msgSize int, crcExtra uint8, msgConstructor func(p packet.Packet) (message.Message, error)) {\n" +
"func Register(msgID message.MessageID, msgName string, msgSize int, crcExtra uint8, msgConstructor func(bytes []byte) (message.Message, error)) {\n" +
"\tif info, ok := supported[msgID]; ok {\n" +
"\t\tpanic(\"Message with ID = \" + strconv.Itoa(int(msgID)) + \" already exists. Fix collision '\" + msgName + \"' vs '\" + info.Name + \"' and re-run mavgen\")\n" +
"\t} else {\n" +
Expand Down
5 changes: 2 additions & 3 deletions mavgen/register.template
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,20 @@ import (
"strconv"
"{{.CommonPackageURL}}/errors"
"{{.CommonPackageURL}}/message"
"{{.CommonPackageURL}}/packet"
)

// MessageInfo type
type MessageInfo struct {
Name string
Size int
Extra uint8
Constructor func(p packet.Packet) (message.Message, error)
Constructor func(bytes []byte) (message.Message, error)
}

var supported = make(map[message.MessageID]*MessageInfo)

// Register method provide register dialect message on decoder knowledge
func Register(msgID message.MessageID, msgName string, msgSize int, crcExtra uint8, msgConstructor func(p packet.Packet) (message.Message, error)) {
func Register(msgID message.MessageID, msgName string, msgSize int, crcExtra uint8, msgConstructor func(bytes []byte) (message.Message, error)) {
if info, ok := supported[msgID]; ok {
panic("Message with ID = " + strconv.Itoa(int(msgID)) + " already exists. Fix collision '" + msgName + "' vs '" + info.Name + "' and re-run mavgen")
} else {
Expand Down
Loading

0 comments on commit 46311ce

Please sign in to comment.