MCPcopy Create free account
hub / github.com/TheThingsNetwork/lorawan-stack / append

Method append

pkg/encoding/lorawan/mac.go:1543–1568  ·  view source on GitHub ↗
(phy band.Band, b []byte, isUplink bool, cmd *ttnpb.MACCommand)

Source from the content-addressed store, hash-verified

1541)
1542
1543func (spec MACCommandSpec) append(phy band.Band, b []byte, isUplink bool, cmd *ttnpb.MACCommand) ([]byte, error) {
1544 desc, ok := spec[cmd.Cid]
1545 if !ok || desc == nil {
1546 return nil, errUnknownMACCommand.WithAttributes("cid", fmt.Sprintf("0x%X", int32(cmd.Cid)))
1547 }
1548 b = append(b, byte(cmd.Cid))
1549
1550 var appender func(phy band.Band, b []byte, cmd *ttnpb.MACCommand) ([]byte, error)
1551 if isUplink {
1552 appender = desc.AppendUplink
1553 if appender == nil {
1554 return nil, errMACCommandUplink.WithAttributes("cid", fmt.Sprintf("0x%X", int32(cmd.Cid)))
1555 }
1556 } else {
1557 appender = desc.AppendDownlink
1558 if appender == nil {
1559 return nil, errMACCommandDownlink.WithAttributes("cid", fmt.Sprintf("0x%X", int32(cmd.Cid)))
1560 }
1561 }
1562
1563 b, err := appender(phy, b, cmd)
1564 if err != nil {
1565 return nil, errEncodingMACCommand.WithAttributes("cid", fmt.Sprintf("0x%X", int32(cmd.Cid))).WithCause(err)
1566 }
1567 return b, nil
1568}
1569
1570// AppendUplink encodes uplink MAC command cmd, appends it to b and returns any errors encountered.
1571func (spec MACCommandSpec) AppendUplink(phy band.Band, b []byte, cmd *ttnpb.MACCommand) ([]byte, error) {

Callers 2

AppendUplinkMethod · 0.95
AppendDownlinkMethod · 0.95

Calls 2

WithAttributesMethod · 0.45
WithCauseMethod · 0.45

Tested by

no test coverage detected