MCPcopy Create free account
hub / github.com/chirpstack/chirpstack / decode_from_raw

Method decode_from_raw

lrwn/src/maccommand.rs:630–800  ·  view source on GitHub ↗
(&mut self, uplink: bool)

Source from the content-addressed store, hash-verified

628 }
629
630 pub fn decode_from_raw(&mut self, uplink: bool) -> Result<()> {
631 // nothing to parse
632 if self.0.is_empty() {
633 return Ok(());
634 }
635
636 // in any other case there must be exactly one MACCommand::Raw.
637 if self.0.len() == 1
638 && let MACCommand::Raw(b) = &self.0[0]
639 {
640 let mut cur = Cursor::new(b.clone());
641 let mut commands = vec![];
642 let mut b = [0; 1];
643
644 loop {
645 // Try to read one byte to get the CID.
646 if cur.read_exact(&mut b).is_err() {
647 break;
648 }
649
650 let cid = match CID::from_u8(uplink, b[0]) {
651 Ok(v) => v,
652 Err(_) => {
653 let mut b = b.to_vec();
654 cur.read_to_end(&mut b)?;
655 commands.push(MACCommand::Raw(b));
656 break;
657 }
658 };
659
660 match cid {
661 CID::ResetInd => {
662 commands.push(MACCommand::ResetInd(ResetIndPayload::decode(&mut cur)?))
663 }
664 CID::ResetConf => {
665 commands.push(MACCommand::ResetConf(ResetConfPayload::decode(&mut cur)?))
666 }
667 CID::LinkCheckReq => commands.push(MACCommand::LinkCheckReq),
668 CID::LinkCheckAns => commands.push(MACCommand::LinkCheckAns(
669 LinkCheckAnsPayload::decode(&mut cur)?,
670 )),
671 CID::LinkADRReq => {
672 commands.push(MACCommand::LinkADRReq(LinkADRReqPayload::decode(&mut cur)?))
673 }
674 CID::LinkADRAns => {
675 commands.push(MACCommand::LinkADRAns(LinkADRAnsPayload::decode(&mut cur)?))
676 }
677 CID::DutyCycleReq => commands.push(MACCommand::DutyCycleReq(
678 DutyCycleReqPayload::decode(&mut cur)?,
679 )),
680 CID::DutyCycleAns => commands.push(MACCommand::DutyCycleAns),
681 CID::RxParamSetupReq => commands.push(MACCommand::RxParamSetupReq(
682 RxParamSetupReqPayload::decode(&mut cur)?,
683 )),
684 CID::RxParamSetupAns => commands.push(MACCommand::RxParamSetupAns(
685 RxParamSetupAnsPayload::decode(&mut cur)?,
686 )),
687 CID::DevStatusReq => commands.push(MACCommand::DevStatusReq),

Callers 4

get_pendingFunction · 0.80
test_commandFunction · 0.80
decode_frm_payloadFunction · 0.80

Calls 3

pushMethod · 0.80
decodeFunction · 0.50
to_vecMethod · 0.45

Tested by 1

test_commandFunction · 0.64