From a59a516fd7f6ef20ca3f265571873ec4ab4b5035 Mon Sep 17 00:00:00 2001 From: MaxVerevkin Date: Sun, 12 Jan 2025 22:57:29 +0200 Subject: [PATCH] core: use ::next_multiple_of(4) for padding calculation --- wayrs-core/src/lib.rs | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) diff --git a/wayrs-core/src/lib.rs b/wayrs-core/src/lib.rs index ca65d5c..e092c11 100644 --- a/wayrs-core/src/lib.rs +++ b/wayrs-core/src/lib.rs @@ -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(_) @@ -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, } }