MCPcopy Create free account
hub / github.com/FutureSDR/FutureSDR / parse_implicit_header

Method parse_implicit_header

examples/lora/src/utils.rs:748–773  ·  view source on GitHub ↗
(passed: &str, ignore_case: bool)

Source from the content-addressed store, hash-verified

746
747 fn from_str(input: &str, ignore_case: bool) -> Result<Self, String> {
748 fn parse_implicit_header(passed: &str, ignore_case: bool) -> Result<HeaderMode, String> {
749 let re = Regex::new(
750 r#"^"??(?<uppercase>[Ii])mplicit\((?<payload_len>[0-9]{1,3}), ?(?<has_crc>[tT]rue|(?:[fF]alse)), ?(?<code_rate>CR_4_[5678])\)"?$"#,
751 )
752 .unwrap();
753 let regex_match = re.captures(passed);
754 match regex_match {
755 Some(regex_match) => {
756 let is_uppercase = "I" == &regex_match["uppercase"];
757 if !is_uppercase && !ignore_case {
758 return Err(format!(
759 "invalid variant (has to be uppercase 'Implicit[...]'): {passed}"
760 ));
761 }
762 let payload_len: u8 = regex_match["payload_len"].parse().unwrap();
763 let has_crc = "true" == regex_match["has_crc"].to_lowercase();
764 let code_rate = CodeRate::from_str(&regex_match["code_rate"], ignore_case)?;
765 Ok(HeaderMode::Implicit {
766 payload_len: payload_len as usize,
767 has_crc,
768 code_rate,
769 })
770 }
771 None => Err(format!("invalid variant: {passed}")),
772 }
773 }
774 let input_lowercase = input.to_lowercase();
775 if ignore_case {
776 match input_lowercase.as_str() {

Callers

nothing calls this directly

Calls 1

parseMethod · 0.45

Tested by

no test coverage detected