diff --git a/common/Cargo.toml b/common/Cargo.toml index 82ef7469f..a66070670 100644 --- a/common/Cargo.toml +++ b/common/Cargo.toml @@ -15,8 +15,10 @@ postgres-types = { version = "0.2.1", optional = true } bytes = { version = "1", optional = true } rusqlite = { version = "0.30.0", optional = true } rkyv = { version = "0.7", optional = true, default-features = false, features = ["validation"] } +rend = { version = "0.4", optional = true, default-features = false } [features] default = ["std"] pg = ["postgres-types", "bytes"] std = ["rkyv?/std"] +rkyv = ["dep:rkyv", "rend"] diff --git a/common/src/lib.rs b/common/src/lib.rs index 4dbe7e598..5e8f3a14f 100644 --- a/common/src/lib.rs +++ b/common/src/lib.rs @@ -6,6 +6,9 @@ extern crate alloc; #[cfg(feature = "rkyv")] pub extern crate rkyv; +#[cfg(feature = "rkyv")] +pub extern crate rend; + pub extern crate serde_shims; pub mod db; diff --git a/common/src/ser.rs b/common/src/ser.rs index 6ed86a508..ca0f07852 100644 --- a/common/src/ser.rs +++ b/common/src/ser.rs @@ -94,12 +94,12 @@ macro_rules! impl_rkyv_for_enum_codes { use $crate::rkyv::{Archive, Deserialize, Fallible, Serialize, Archived, bytecheck::{EnumCheckError, CheckBytes}}; impl Archive for $name { - type Archived = $repr; + type Archived = $crate::rend::LittleEndian<$repr>; type Resolver = (); #[inline] unsafe fn resolve(&self, _pos: usize, _resolver: Self::Resolver, out: *mut Self::Archived) { - *out = *self as $repr; + *out = $crate::rend::LittleEndian::<$repr>::new(*self as $repr); } } @@ -112,11 +112,11 @@ macro_rules! impl_rkyv_for_enum_codes { impl Deserialize<$name, D> for Archived<$name> { fn deserialize(&self, _deserializer: &mut D) -> Result<$name, D::Error> { - Ok(match *self { + Ok(match self.value() { $($code => $name::$variant,)* $(_ => $name::$unknown,)? - _ => panic!("Unknown code: {self}"), + u @ _ => panic!("Unknown code: {u}"), }) } } @@ -128,12 +128,12 @@ macro_rules! impl_rkyv_for_enum_codes { value: *const Self, context: &mut C ) -> Result<&'a Self, Self::Error> { - let tag = *value.cast::<$repr>(); - match tag { + let tag = *value.cast::<$crate::rend::LittleEndian<$repr>>(); + match tag.value() { $(| $code)* => Ok(&*value), $(_ => Ok(&$name::$unknown),)? - _ => Err(EnumCheckError::InvalidTag(tag)) + tag @ _ => Err(EnumCheckError::InvalidTag(tag)) } } }