Skip to content

Commit

Permalink
core: use <int>::next_multiple_of(4) for padding calculation
Browse files Browse the repository at this point in the history
  • Loading branch information
MaxVerevkin committed Jan 12, 2025
1 parent fb0bc02 commit a59a516
Showing 1 changed file with 3 additions and 8 deletions.
11 changes: 3 additions & 8 deletions wayrs-core/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -112,11 +112,6 @@ pub enum ArgValue {
impl ArgValue {
/// The size of the argument in bytes.
pub fn size(&self) -> usize {
fn len_with_padding(len: usize) -> usize {
let padding = (4 - (len % 4)) % 4;
4 + len + padding
}

match self {
Self::Int(_)
| Self::Uint(_)
Expand All @@ -126,12 +121,12 @@ impl ArgValue {
| Self::NewId(_)
| Self::OptString(None) => 4,
Self::AnyNewId(iface, _version, _id) => {
len_with_padding(iface.to_bytes_with_nul().len()) + 8
iface.to_bytes_with_nul().len().next_multiple_of(4) + 12
}
Self::String(string) | Self::OptString(Some(string)) => {
len_with_padding(string.to_bytes_with_nul().len())
string.to_bytes_with_nul().len().next_multiple_of(4) + 4
}
Self::Array(array) => len_with_padding(array.len()),
Self::Array(array) => array.len().next_multiple_of(4) + 4,
Self::Fd(_) => 0,
}
}
Expand Down

0 comments on commit a59a516

Please sign in to comment.