Skip to content

Commit

Permalink
Formatting pass
Browse files Browse the repository at this point in the history
  • Loading branch information
harrison-e committed Dec 10, 2024
1 parent 452b595 commit a760579
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 9 deletions.
18 changes: 10 additions & 8 deletions libs/calypso-cangen/src/can_gen_decode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -151,22 +151,22 @@ impl CANGenDecode for CANPoint {
0..=8 => quote! { i8 },
9..=16 => quote! { i16 },
_ => quote! { i32 },
}
},
_ => match self.size {
0..=8 => quote! { u8 },
9..=16 => quote! { u16 },
_ => quote! { u32 },
}
}
};
},
},
};

// Prefix to call potential format function
let format_prefix = match &self.format {
Some(format) => {
let id = format_ident!("{}_d", format);
quote! { FormatData::#id }
}
_ => quote! {}
_ => quote! {},
};

// Endianness and signedness affect which read to use
Expand All @@ -177,15 +177,17 @@ impl CANGenDecode for CANPoint {
}
}
_ => match self.signed {
Some(true) if self.ieee754_f32 == None => quote! { reader.read_signed_in::<#size_literal, i32>().unwrap() },
Some(true) if self.ieee754_f32 == None => {
quote! { reader.read_signed_in::<#size_literal, i32>().unwrap() }
}
_ => quote! { reader.read_in::<#size_literal, u32>().unwrap() },
}
},
};

// Transmute if point is IEEE754 f32, else convert
match self.ieee754_f32 {
Some(true) => quote! { #format_prefix (f32::from_bits(#read_func)) },
_ => quote! { #format_prefix (#read_func as f32) },
_ => quote! { #format_prefix (#read_func as f32) },
}
}
}
2 changes: 1 addition & 1 deletion libs/calypso-cangen/src/can_types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ pub struct CANPoint {
pub endianness: Option<String>,
pub format: Option<String>,
pub default_value: Option<f32>,
pub ieee754_f32: Option<bool>,
pub ieee754_f32: Option<bool>,
}

#[derive(Deserialize, Debug)]
Expand Down

0 comments on commit a760579

Please sign in to comment.