More idiomatic logic

This commit is contained in:
Marcel 2023-01-13 11:40:16 +01:00
parent d11d5e921d
commit 0569cfc771
2 changed files with 5 additions and 10 deletions

View file

@ -55,10 +55,11 @@ pub fn encode(bytes: &[u8], length: usize) -> String {
fn encode_base38(mut value: u32, char_count: u8) -> String {
let mut result = String::new();
let chars = BASE38_CHARS.chars();
for _ in 0..char_count {
let mut chars = BASE38_CHARS.chars();
let mut use_chars = chars.clone();
let remainder = value % 38;
result.push(chars.nth(remainder as usize).unwrap());
result.push(use_chars.nth(remainder as usize).unwrap());
value = (value - remainder) / 38;
}
result

View file

@ -492,14 +492,8 @@ fn populate_tlv_bits(
) -> Result<(), Error> {
if let (Some(data), Some(data_length_in_bytes)) = (tlv_data.data, tlv_data.data_length_in_bytes)
{
for pos in 0..data_length_in_bytes {
populate_bits(
bits,
offset,
data[pos] as u64,
8,
total_payload_size_in_bits,
)?;
for b in data.iter().take(data_length_in_bytes) {
populate_bits(bits, offset, *b as u64, 8, total_payload_size_in_bits)?;
}
} else {
return Err(Error::InvalidArgument);