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

Function MarshalMessage

pkg/encoding/lorawan/messages.go:539–561  ·  view source on GitHub ↗

MarshalMessage returns encoded msg.

(msg *ttnpb.Message)

Source from the content-addressed store, hash-verified

537
538// MarshalMessage returns encoded msg.
539func MarshalMessage(msg *ttnpb.Message) ([]byte, error) {
540 if msg.MHdr == nil {
541 return nil, errMissing("MHDR")
542 }
543 switch msg.MHdr.MType {
544 case ttnpb.MType_CONFIRMED_DOWN, ttnpb.MType_UNCONFIRMED_DOWN, ttnpb.MType_CONFIRMED_UP, ttnpb.MType_UNCONFIRMED_UP:
545 // MHDR(1) + Payload(up to 250) + MIC(4)
546 return AppendMessage(make([]byte, 0, 255), msg)
547 case ttnpb.MType_JOIN_REQUEST:
548 // MHDR(1) + Payload(18) + MIC(4)
549 return AppendMessage(make([]byte, 0, 23), msg)
550 case ttnpb.MType_REJOIN_REQUEST:
551 // MHDR(1) + Payload(14|19) + MIC(4)
552 return AppendMessage(make([]byte, 0, 24), msg)
553 case ttnpb.MType_JOIN_ACCEPT:
554 // MHDR(1) + Encrypted payload(16|32)
555 return AppendMessage(make([]byte, 0, 33), msg)
556 case ttnpb.MType_PROPRIETARY:
557 return nil, errProprietary.New()
558 default:
559 return nil, errUnknown("MType")(msg.MHdr.MType.String())
560 }
561}
562
563// UnmarshalMessage unmarshals b into msg.
564func UnmarshalMessage(b []byte, msg *ttnpb.Message) error {

Callers 13

randomUpDataPayloadFunction · 0.92
randomUpDataPayloadFunction · 0.92
randomJoinRequestPayloadFunction · 0.92
randomDownDataPayloadFunction · 0.92
toUplinkMessageMethod · 0.92
toUplinkMessageMethod · 0.92
TestGenerateDataDownlinkFunction · 0.92
generateDataDownlinkMethod · 0.92
MakeDataUplinkFunction · 0.92
MakeDataDownlinkFunction · 0.92
simulate.goFile · 0.92

Calls 5

AppendMessageFunction · 0.85
errUnknownFunction · 0.85
errMissingFunction · 0.70
NewMethod · 0.65
StringMethod · 0.65

Tested by 4

randomUpDataPayloadFunction · 0.74
TestGenerateDataDownlinkFunction · 0.74
TestLoRaWANEncodingRawFunction · 0.68