change rkyv behavior in xous-ipc from panic to failure

this allows for more graceful error handling in case of
serialization failures
This commit is contained in:
bunnie 2024-09-23 22:01:02 +08:00
parent 047ffe31e9
commit 0ecfa80bac

View file

@ -4,7 +4,7 @@ use std::marker::PhantomData;
use rkyv::{ use rkyv::{
Archive, Deserialize, Place, Portable, Serialize, Archive, Deserialize, Place, Portable, Serialize,
api::low::LowSerializer, api::low::LowSerializer,
rancor::{Panic, Strategy}, rancor::{Failure, Strategy},
ser::{Positional, allocator::SubAllocator, writer::Buffer as RkyvBuffer}, ser::{Positional, allocator::SubAllocator, writer::Buffer as RkyvBuffer},
with::{ArchiveWith, Identity, SerializeWith}, with::{ArchiveWith, Identity, SerializeWith},
}; };
@ -23,7 +23,7 @@ pub struct Buffer<'buf> {
} }
const PAGE_SIZE: usize = 0x1000; const PAGE_SIZE: usize = 0x1000;
type Serializer<'a, 'b> = LowSerializer<RkyvBuffer<'b>, SubAllocator<'a>, Panic>; type Serializer<'a, 'b> = LowSerializer<RkyvBuffer<'b>, SubAllocator<'a>, Failure>;
impl<'buf> Buffer<'buf> { impl<'buf> Buffer<'buf> {
#[allow(dead_code)] #[allow(dead_code)]
@ -198,7 +198,7 @@ impl<'buf> Buffer<'buf> {
fn serialize( fn serialize(
&self, &self,
serializer: &mut Serializer<'a, 'b>, serializer: &mut Serializer<'a, 'b>,
) -> core::result::Result<Self::Resolver, Panic> { ) -> core::result::Result<Self::Resolver, Failure> {
F::serialize_with(self.0, serializer) F::serialize_with(self.0, serializer)
} }
} }
@ -210,7 +210,7 @@ impl<'buf> Buffer<'buf> {
let alloc = SubAllocator::new(&mut scratch); let alloc = SubAllocator::new(&mut scratch);
let serialized_buf = let serialized_buf =
rkyv::api::low::to_bytes_in_with_alloc::<_, _, Panic>(&wrap, writer, alloc).map_err(|_| ())?; rkyv::api::low::to_bytes_in_with_alloc::<_, _, Failure>(&wrap, writer, alloc).map_err(|_| ())?;
xous_buf.used = serialized_buf.pos(); xous_buf.used = serialized_buf.pos();
Ok(xous_buf) Ok(xous_buf)
} }
@ -225,7 +225,7 @@ impl<'buf> Buffer<'buf> {
rkyv::ser::allocator::SubAllocator<'a>, rkyv::ser::allocator::SubAllocator<'a>,
(), (),
>, >,
rkyv::rancor::Panic, rkyv::rancor::Failure,
>, >,
>, >,
{ {
@ -257,7 +257,7 @@ impl<'buf> Buffer<'buf> {
fn serialize( fn serialize(
&self, &self,
serializer: &mut Serializer<'a, 'b>, serializer: &mut Serializer<'a, 'b>,
) -> core::result::Result<Self::Resolver, Panic> { ) -> core::result::Result<Self::Resolver, Failure> {
F::serialize_with(self.0, serializer) F::serialize_with(self.0, serializer)
} }
} }
@ -269,7 +269,7 @@ impl<'buf> Buffer<'buf> {
let alloc = SubAllocator::new(&mut scratch); let alloc = SubAllocator::new(&mut scratch);
let serialized_buf = let serialized_buf =
rkyv::api::low::to_bytes_in_with_alloc::<_, _, Panic>(&wrap, writer, alloc).unwrap(); rkyv::api::low::to_bytes_in_with_alloc::<_, _, Failure>(&wrap, writer, alloc).unwrap();
self.used = serialized_buf.pos(); self.used = serialized_buf.pos();
if let Some(ref mut msg) = self.memory_message.as_mut() { if let Some(ref mut msg) = self.memory_message.as_mut() {
@ -288,7 +288,7 @@ impl<'buf> Buffer<'buf> {
rkyv::ser::allocator::SubAllocator<'a>, rkyv::ser::allocator::SubAllocator<'a>,
(), (),
>, >,
rkyv::rancor::Panic, rkyv::rancor::Failure,
>, >,
>, >,
{ {