Skip to content

Commit

Permalink
use double underscores to indicate temporary variables
Browse files Browse the repository at this point in the history
  • Loading branch information
danieleades committed Oct 24, 2023
1 parent 13cfa20 commit 5802b07
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 20 deletions.
1 change: 1 addition & 0 deletions build/binder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ pub fn generate<W: Write>(modules: Vec<String>, out: &mut W) {
#[allow(clippy::field_reassign_with_default)]
#[allow(non_snake_case)]
#[allow(clippy::unnecessary_cast)]
#[allow(clippy::bad_bit_mask)]
#[cfg(feature = #module)]
pub mod #module_ident;
}
Expand Down
24 changes: 12 additions & 12 deletions build/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -500,13 +500,13 @@ impl MavMessage {
fn emit_serialize_vars(&self) -> TokenStream {
let ser_vars = self.fields.iter().map(|f| f.rust_writer());
quote! {
let mut _tmp = BytesMut::new(bytes);
let mut __tmp = BytesMut::new(bytes);
#(#ser_vars)*
if matches!(version, MavlinkVersion::V2) {
let len = _tmp.len();
crate::remove_trailing_zeroes(&mut bytes[..len])
let len = __tmp.len();
crate::remove_trailing_zeroes(&bytes[..len])
} else {
_tmp.len()
__tmp.len()
}
}
}
Expand All @@ -525,21 +525,21 @@ impl MavMessage {
}
} else {
quote! {
let avail_len = _input.len();
let avail_len = __input.len();

let mut payload_buf = [0; Self::ENCODED_LEN];
let mut buf = if avail_len < Self::ENCODED_LEN {
//copy available bytes into an oversized buffer filled with zeros
payload_buf[0..avail_len].copy_from_slice(_input);
payload_buf[0..avail_len].copy_from_slice(__input);
Bytes::new(&payload_buf)
} else {
// fast zero copy
Bytes::new(_input)
Bytes::new(__input)
};

let mut _struct = Self::default();
let mut __struct = Self::default();
#(#deser_vars)*
Ok(_struct)
Ok(__struct)
}
}
}
Expand Down Expand Up @@ -604,7 +604,7 @@ impl MavMessage {
const EXTRA_CRC: u8 = #extra_crc;
const ENCODED_LEN: usize = #msg_encoded_len;

fn deser(_version: MavlinkVersion, _input: &[u8]) -> Result<Self, ParserError> {
fn deser(_version: MavlinkVersion, __input: &[u8]) -> Result<Self, ParserError> {
#deser_vars
}

Expand Down Expand Up @@ -692,15 +692,15 @@ impl MavField {
}
let ts = TokenStream::from_str(&name).unwrap();
let name = quote!(#ts);
let buf = format_ident!("_tmp");
let buf = format_ident!("__tmp");
self.mavtype.rust_writer(&name, buf)
}

/// Emit reader
fn rust_reader(&self) -> TokenStream {
let _name = TokenStream::from_str(&self.name).unwrap();

let name = quote!(_struct.#_name);
let name = quote!(__struct.#_name);
let buf = format_ident!("buf");
if let Some(enum_name) = &self.enumtype {
// TODO: handle enum arrays properly, rather than just generating
Expand Down
14 changes: 7 additions & 7 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ impl<M: Message> MavFrame<M> {

let msg_id = match version {
MavlinkVersion::V2 => buf.get_u24_le(),
MavlinkVersion::V1 => buf.get_u8() as u32,
MavlinkVersion::V1 => buf.get_u8().into(),
};

match M::parse(version, msg_id, buf.remaining_bytes()) {
Expand Down Expand Up @@ -498,10 +498,10 @@ impl MAVLinkV2MessageRaw {
let payload_length: usize = self.payload_length().into();

// Signature to ensure the link is tamper-proof.
let signature_size = if (self.incompatibility_flags() & MAVLINK_IFLAG_SIGNED) != 0 {
Self::SIGNATURE_SIZE
} else {
let signature_size = if (self.incompatibility_flags() & MAVLINK_IFLAG_SIGNED) == 0 {
0
} else {
Self::SIGNATURE_SIZE
};

&mut self.0
Expand All @@ -521,10 +521,10 @@ impl MAVLinkV2MessageRaw {
pub fn raw_bytes(&self) -> &[u8] {
let payload_length = self.payload_length() as usize;

let signature_size = if (self.incompatibility_flags() & MAVLINK_IFLAG_SIGNED) != 0 {
Self::SIGNATURE_SIZE
} else {
let signature_size = if (self.incompatibility_flags() & MAVLINK_IFLAG_SIGNED) == 0 {
0
} else {
Self::SIGNATURE_SIZE
};

&self.0[..(1 + Self::HEADER_SIZE + payload_length + signature_size + 2)]
Expand Down
2 changes: 1 addition & 1 deletion src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
///
/// There must always be at least one remaining byte even if it is a
/// zero byte.
pub(crate) fn remove_trailing_zeroes(data: &mut [u8]) -> usize {
pub(crate) fn remove_trailing_zeroes(data: &[u8]) -> usize {
let mut len = data.len();

for b in data[1..].iter().rev() {
Expand Down

0 comments on commit 5802b07

Please sign in to comment.