Skip to content

Commit

Permalink
Add Dict() func to each Message
Browse files Browse the repository at this point in the history
  • Loading branch information
amyasnikov committed Feb 26, 2021
1 parent 6ab4d32 commit d2b09c4
Show file tree
Hide file tree
Showing 18 changed files with 21,574 additions and 1 deletion.
3 changes: 2 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
module github.com/asmyasnikov/go-mavlink/v5
module github.com/asmyasnikov/go-mavlink

go 1.15

require (
github.com/howeyc/crc16 v0.0.0-20171223171357-2b2a61e366a6
github.com/pkg/errors v0.9.1 // indirect
github.com/stretchr/testify v1.7.0
github.com/tarm/serial v0.0.0-20180830185346-98f6abe2eb07
golang.org/x/sys v0.0.0-20210124154548-22da62e12c0c // indirect
Expand Down
1 change: 1 addition & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ github.com/davecgh/go-spew v1.1.0 h1:ZDRjVQ15GmhC3fiQ8ni8+OwkZQO4DARzQgrnXU1Liz8
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/howeyc/crc16 v0.0.0-20171223171357-2b2a61e366a6 h1:IIVxLyDUYErC950b8kecjoqDet8P5S4lcVRUOM6rdkU=
github.com/howeyc/crc16 v0.0.0-20171223171357-2b2a61e366a6/go.mod h1:JslaLRrzGsOKJgFEPBP65Whn+rdwDQSk0I0MCRFe2Zw=
github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
Expand Down
7 changes: 7 additions & 0 deletions mavgen/mavgen.go
Original file line number Diff line number Diff line change
Expand Up @@ -751,6 +751,13 @@ func (m *{{$name}}) String() string {
)
}
// ToMap (generated function)
func (m *{{$name}}) Dict() map[string]interface{} {
return map[string]interface{}{
{{range .Fields}}"{{$name}}.{{.Name | UpperCamelCase}}": m.{{.Name | UpperCamelCase}},
{{end}} }
}
// Marshal (generated function)
func (m *{{$name}}) Marshal() ([]byte, error) {
payload := make([]byte, {{ .Size }}){{range .Fields}}
Expand Down
2 changes: 2 additions & 0 deletions mavgen/message.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ func messageTemplate() string {
"\tMsgID() MessageID\n" +
" // String returns human-readable representation on Message\n" +
"\tString() string\n" +
"\t// Dict returns key-value dictionary of Message internal fields\n" +
"\tDict() map[string]interface{}\n" +
" // Marshal encodes Packet to byte slice\n" +
" Marshal() ([]byte, error)\n" +
" // Unmarshal parses PAYLOAD and stores the result in Packet\n" +
Expand Down
2 changes: 2 additions & 0 deletions mavgen/message.template
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ type Message interface {
MsgID() MessageID
// String returns human-readable representation on Message
String() string
// Dict returns key-value dictionary of Message internal fields
Dict() map[string]interface{}
// Marshal encodes Packet to byte slice
Marshal() ([]byte, error)
// Unmarshal parses PAYLOAD and stores the result in Packet
Expand Down
Loading

0 comments on commit d2b09c4

Please sign in to comment.