Hello all,
I am very new to GO and so I would be really grateful if you can guide me with this:
This is the formatter.go file:
package formatters
import (
"go.thethings.network/lorawan-stack/pkg/ttnpb"
)
// Formatter formats upstream and downstream messages.
type Formatter interface {
FromUp(*ttnpb.ApplicationUp) ([]byte, error)
ToDownlinks([]byte) (*ttnpb.ApplicationDownlinks, error)
ToDownlinkQueueRequest([]byte) (*ttnpb.DownlinkQueueRequest, error)
}
and this is the json.go file:
package formatters
import (
"go.thethings.network/lorawan-stack/pkg/jsonpb"
"go.thethings.network/lorawan-stack/pkg/ttnpb"
)
type json struct {
}
func (json) FromUp(msg *ttnpb.ApplicationUp) ([]byte, error) {
return jsonpb.TTN().Marshal(msg)
}
func (json) ToDownlinks(data []byte) (*ttnpb.ApplicationDownlinks, error) {
res := &ttnpb.ApplicationDownlinks{}
if err := jsonpb.TTN().Unmarshal(data, &res); err != nil {
return nil, err
}
return res, nil
}
func (json) ToDownlinkQueueRequest(data []byte) (*ttnpb.DownlinkQueueRequest, error) {
res := &ttnpb.DownlinkQueueRequest{}
if err := jsonpb.TTN().Unmarshal(data, &res); err != nil {
return nil, err
}
return res, nil
}
// JSON is a formatter that uses JSON marshaling.
var JSON Formatter = &json{}
Now, in the *ttnpb.ApplicationUp I would like to return [][]byte instead of just []byte. How can I do that?
Thank you so much in advance.