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

Function AppendCFList

pkg/encoding/lorawan/messages.go:227–261  ·  view source on GitHub ↗

AppendCFList appends encoded msg to dst.

(dst []byte, msg *ttnpb.CFList)

Source from the content-addressed store, hash-verified

225
226// AppendCFList appends encoded msg to dst.
227func AppendCFList(dst []byte, msg *ttnpb.CFList) ([]byte, error) {
228 switch msg.Type {
229 case 0:
230 n := len(msg.Freq)
231 if n > 5 {
232 return nil, errExpectedLengthLowerOrEqual("CFListFreq", 5)(n)
233 }
234 for _, freq := range msg.Freq {
235 if freq > byteutil.MaxUint24 {
236 return nil, errMaxCFListFrequency(freq)
237 }
238 dst = byteutil.AppendUint32(dst, freq, 3)
239 }
240 // Fill remaining space with zeros.
241 dst = append(dst, bytes.Repeat([]byte{0x0}, 15-n*3)...)
242 case 1:
243 n := uint(len(msg.ChMasks))
244 if n > 96 {
245 return nil, errExpectedLengthLowerOrEqual("CFListChMasks", 96)(n)
246 }
247 for i := uint(0); i < n; i += 8 {
248 var b byte
249 for j := uint(0); j < 8 && i+j < n; j++ {
250 if msg.ChMasks[i+j] {
251 b |= (1 << j)
252 }
253 }
254 dst = append(dst, b)
255 }
256 // Fill remaining space with zeros.
257 dst = append(dst, bytes.Repeat([]byte{0x0}, int(15-(n+7)/8))...)
258 }
259 dst = append(dst, byte(msg.Type))
260 return dst, nil
261}
262
263// MarshalCFList returns encoded msg.
264func MarshalCFList(msg *ttnpb.CFList) ([]byte, error) {

Callers 2

MarshalCFListFunction · 0.85
AppendJoinAcceptPayloadFunction · 0.85

Calls 2

AppendUint32Function · 0.92

Tested by

no test coverage detected