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

Function UnmarshalFHDR

pkg/encoding/lorawan/messages.go:118–137  ·  view source on GitHub ↗

UnmarshalFHDR unmarshals b into msg.

(b []byte, msg *ttnpb.FHDR, isUplink bool)

Source from the content-addressed store, hash-verified

116
117// UnmarshalFHDR unmarshals b into msg.
118func UnmarshalFHDR(b []byte, msg *ttnpb.FHDR, isUplink bool) error {
119 n := len(b)
120 if n < 7 || n > 23 {
121 return errExpectedLengthEncodedBound("FHDR", 7, 23)(n)
122 }
123 msg.DevAddr = make([]byte, 4)
124 copyReverse(msg.DevAddr, b[0:4])
125 msg.FCtrl = &ttnpb.FCtrl{}
126 if err := UnmarshalFCtrl(b[4:5], msg.FCtrl, isUplink); err != nil {
127 return errFailedDecoding("FCtrl").WithCause(err)
128 }
129 msg.FCnt = byteutil.ParseUint32(b[5:7])
130 if n == 7 {
131 // No FOpts
132 return nil
133 }
134 msg.FOpts = make([]byte, 0, n-7)
135 msg.FOpts = append(msg.FOpts, b[7:n]...)
136 return nil
137}
138
139// AppendMACPayload appends encoded msg to dst.
140func AppendMACPayload(dst []byte, msg *ttnpb.MACPayload, isUplink bool) ([]byte, error) {

Callers 1

UnmarshalMACPayloadFunction · 0.85

Calls 6

ParseUint32Function · 0.92
copyReverseFunction · 0.85
UnmarshalFCtrlFunction · 0.85
errFailedDecodingFunction · 0.85
WithCauseMethod · 0.45

Tested by

no test coverage detected