From 8417c596a4a093079777cab75b577d9109fe3382 Mon Sep 17 00:00:00 2001 From: printfn Date: Sat, 16 Mar 2024 09:35:08 +0000 Subject: [PATCH] Make usize byte serialisation platform-independent --- core/src/lib.rs | 3 +-- core/src/serialize.rs | 15 ++++++++++++++- windows-wix/main.wxs | 7 ------- 3 files changed, 15 insertions(+), 10 deletions(-) diff --git a/core/src/lib.rs b/core/src/lib.rs index cbd36c32..4a9089bc 100644 --- a/core/src/lib.rs +++ b/core/src/lib.rs @@ -294,8 +294,7 @@ impl Context { /// Serializes all variables defined in this context to a stream of bytes. /// Note that the specific format is NOT stable, and can change with any - /// minor update. It is also not compatible between 32-bit and - /// 64-bit architectures. + /// minor update. /// /// # Errors /// This function returns an error if the input cannot be serialized. diff --git a/core/src/serialize.rs b/core/src/serialize.rs index 7fa6d23b..0a168e95 100644 --- a/core/src/serialize.rs +++ b/core/src/serialize.rs @@ -34,7 +34,20 @@ macro_rules! impl_serde { }; } -impl_serde!(u8 i32 u64 usize); +impl_serde!(u8 i32 u64); + +impl Serialize for usize { + fn serialize(&self, write: &mut impl io::Write) -> FResult<()> { + (*self as u64).serialize(write) + } +} + +impl Deserialize for usize { + fn deserialize(read: &mut impl io::Read) -> FResult { + let val = u64::deserialize(read)?; + Self::try_from(val).map_err(|_| FendError::DeserializationError) + } +} impl Serialize for &str { fn serialize(&self, write: &mut impl io::Write) -> FResult<()> { diff --git a/windows-wix/main.wxs b/windows-wix/main.wxs index 2f03d6b1..72212984 100644 --- a/windows-wix/main.wxs +++ b/windows-wix/main.wxs @@ -16,13 +16,6 @@ limitations under the License. --> - -