Skip to content

Commit

Permalink
Apply suggestions
Browse files Browse the repository at this point in the history
  • Loading branch information
macladson committed Oct 31, 2023
1 parent 8e64236 commit 6a187e6
Showing 1 changed file with 13 additions and 15 deletions.
28 changes: 13 additions & 15 deletions src/optional.rs
Original file line number Diff line number Diff line change
Expand Up @@ -109,10 +109,6 @@ where
false
}

fn ssz_fixed_len() -> usize {
<T>::ssz_fixed_len() + 1
}

fn ssz_bytes_len(&self) -> usize {
match &self.optional {
None => 0,
Expand Down Expand Up @@ -141,18 +137,20 @@ where
}

fn from_ssz_bytes(bytes: &[u8]) -> Result<Self, ssz::DecodeError> {
if bytes.is_empty() {
Ok(Optional { optional: None })
} else if bytes[0] == 0x01 {
Ok(Optional {
optional: Some(T::from_ssz_bytes(&bytes[1..])?),
})
if let Some((first, rest)) = bytes.split_first() {
if first == &0x01 {
return Ok(Optional {
optional: Some(T::from_ssz_bytes(&rest)?),
});
} else {
// An `Optional` must always contains `0x01` as the first byte.
// Might be worth having an explicit error variant in ssz::DecodeError.
return Err(ssz::DecodeError::BytesInvalid(
"Missing Optional identifier byte".to_string(),
));
}
} else {
// An `Optional` must always contains `0x01` as the first byte.
// Might be worth having an explicit error variant in ssz::DecodeError.
Err(ssz::DecodeError::BytesInvalid(
"Missing Optional identifier byte".to_string(),
))
Ok(Optional { optional: None })
}
}
}
Expand Down

0 comments on commit 6a187e6

Please sign in to comment.