Skip to content

Commit

Permalink
more refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
danieleades committed Oct 22, 2023
1 parent 77057b1 commit 1073ea2
Showing 1 changed file with 14 additions and 20 deletions.
34 changes: 14 additions & 20 deletions build/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1379,21 +1379,21 @@ pub fn extra_crc(msg: &MavMessage) -> u8 {
let mut crc = CRCu16::crc16mcrf4cc();

crc.digest(msg.name.as_bytes());
crc.digest(" ".as_bytes());
crc.digest(b" ");

let mut f = msg.fields.clone();
// only mavlink 1 fields should be part of the extra_crc
f.retain(|f| !f.is_extension);
f.sort_by(|a, b| a.mavtype.compare(&b.mavtype));
for field in &f {
crc.digest(field.mavtype.primitive_type().as_bytes());
crc.digest(" ".as_bytes());
crc.digest(b" ");
if field.name == "mavtype" {
crc.digest("type".as_bytes());
crc.digest(b"type");
} else {
crc.digest(field.name.as_bytes());
}
crc.digest(" ".as_bytes());
crc.digest(b" ");
if let MavType::Array(_, size) = field.mavtype {
crc.digest(&[size as u8]);
}
Expand Down Expand Up @@ -1440,28 +1440,22 @@ impl MavXmlFilter {
Ok(content) => {
match content {
Event::Start(bytes) | Event::Empty(bytes) => {
let id = match identify_element(bytes.name().into_inner()) {
None => {
panic!(
"unexpected element {:?}",
String::from_utf8_lossy(bytes.name().into_inner())
);
}
Some(kind) => kind,
let Some(id) = identify_element(bytes.name().into_inner()) else {
panic!(
"unexpected element {:?}",
String::from_utf8_lossy(bytes.name().into_inner())
);
};
if id == MavXmlElement::Extensions {
self.extension_filter.is_in = true;
}
}
Event::End(bytes) => {
let id = match identify_element(bytes.name().into_inner()) {
None => {
panic!(
"unexpected element {:?}",
String::from_utf8_lossy(bytes.name().into_inner())
);
}
Some(kind) => kind,
let Some(id) = identify_element(bytes.name().into_inner()) else {
panic!(
"unexpected element {:?}",
String::from_utf8_lossy(bytes.name().into_inner())
);
};

if id == MavXmlElement::Message {
Expand Down

0 comments on commit 1073ea2

Please sign in to comment.