Skip to content

Commit

Permalink
handle marshalling better
Browse files Browse the repository at this point in the history
  • Loading branch information
monoxane committed Mar 7, 2023
1 parent 89489cb commit 89408a2
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
6 changes: 2 additions & 4 deletions matrix.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,10 @@ package nk

import (
"encoding/json"
"log"
"sort"
)

func (matrix *Matrix) MarshalJSON() ([]byte, error) {
log.Print("marshalling matrix")
type res struct {
Destinations []*Destination `json:"destinations,omitempty"`
Sources []*Source `json:"sources,omitempty"`
Expand All @@ -16,7 +14,7 @@ func (matrix *Matrix) MarshalJSON() ([]byte, error) {
var result res

for _, dst := range matrix.destinations {
if dst != nil {
if dst != nil && dst.Id != 0 {
result.Destinations = append(result.Destinations, dst)
}
}
Expand All @@ -26,7 +24,7 @@ func (matrix *Matrix) MarshalJSON() ([]byte, error) {
})

for _, src := range matrix.sources {
if src != nil {
if src != nil && src.Id != 0 {
result.Sources = append(result.Sources, src)
}
}
Expand Down
2 changes: 2 additions & 0 deletions nk.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,8 @@ func New(IP string, RTRAddress uint8, model Model) *Router {
}
}

rtr.Matrix.sources[0].Setlabel("DISCONNECTED")

for i := 0; i < int(rtr.Destinations)+1; i++ {
rtr.Matrix.destinations[uint16(i)] = &Destination{
Id: uint16(i),
Expand Down

0 comments on commit 89408a2

Please sign in to comment.