Skip to content

Commit

Permalink
Simplify fixed decoding in derive macro
Browse files Browse the repository at this point in the history
  • Loading branch information
paulhauner committed Dec 5, 2024
1 parent 576bb81 commit c01cd75
Showing 1 changed file with 7 additions and 17 deletions.
24 changes: 7 additions & 17 deletions ssz_derive/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -821,20 +821,13 @@ fn ssz_decode_derive_struct(item: &DeriveInput, struct_data: &DataStruct) -> Tok
}

fixed_decodes.push(quote! {
let #ident = {
start = end;
end = end
.checked_add(#ssz_fixed_len)
.ok_or_else(|| ssz::DecodeError::OutOfBoundsByte {
i: usize::max_value()
})?;
let slice = bytes.get(start..end)
.ok_or_else(|| ssz::DecodeError::InvalidByteLength {
len: bytes.len(),
expected: end
})?;
#from_ssz_bytes?
};
let (slice, bytes) = bytes
.split_at_checked(#ssz_fixed_len)
.ok_or_else(|| ssz::DecodeError::InvalidByteLength {
len: bytes.len(),
expected: #ssz_fixed_len
})?;
let #ident = #from_ssz_bytes?;
});
is_fixed_lens.push(is_ssz_fixed_len);
fixed_lens.push(ssz_fixed_len);
Expand Down Expand Up @@ -872,9 +865,6 @@ fn ssz_decode_derive_struct(item: &DeriveInput, struct_data: &DataStruct) -> Tok
});
}

let mut start: usize = 0;
let mut end = start;

#(
#fixed_decodes
)*
Expand Down

0 comments on commit c01cd75

Please sign in to comment.