use epserde::{deser::DeserType, prelude::*, ser::SerType};
type Type = Option<Vec<i32>>;
type TypeBoxed = Option<Box<[i32]>>;
fn main() -> Result<(), Box<dyn std::error::Error>> {
println!("Serializable type: {}", core::any::type_name::<Type>());
println!(
"Associated serialization type: {}",
core::any::type_name::<SerType<Type>>()
);
println!();
let data = Some(vec![0, 1, 2, 3]);
let mut cursor = <AlignedCursor<Aligned16>>::new();
#[cfg(feature = "schema")]
{
let schema = unsafe { data.serialize_with_schema(&mut cursor)? };
println!("{}", schema.debug(cursor.as_bytes()));
println!();
}
#[cfg(not(feature = "schema"))]
let _bytes_written = unsafe { data.serialize(&mut cursor)? };
cursor.set_position(0);
let full = unsafe { <Type>::deserialize_full(&mut cursor)? };
println!(
"Full-copy deserialization: returns the deserializable type {}",
core::any::type_name::<Type>(),
);
println!("Value: {:x?}", full);
println!();
cursor.set_position(0);
let full = unsafe { <TypeBoxed>::deserialize_full(&mut cursor)? };
println!(
"Full-copy deserialization: returns the deserializable type {}",
core::any::type_name::<TypeBoxed>(),
);
println!("Value: {:x?}", full);
println!();
let eps = unsafe { <Type>::deserialize_eps(cursor.as_bytes())? };
println!(
"ε-copy deserialization: returns the associated deserialization type {}",
core::any::type_name::<DeserType<'_, Type>>(),
);
println!("Value: {:x?}", eps);
let mut cursor = <AlignedCursor<Aligned16>>::new();
println!("\n");
let data: Type = None;
#[cfg(feature = "schema")]
{
let schema = unsafe { data.serialize_with_schema(&mut cursor)? };
println!("{}", schema.debug(cursor.as_bytes()));
println!();
}
#[cfg(not(feature = "schema"))]
let _bytes_written = unsafe { data.serialize(&mut cursor)? };
cursor.set_position(0);
let full = unsafe { <Type>::deserialize_full(&mut cursor)? };
println!(
"Full-copy deserialization: returns the deserializable type {}",
core::any::type_name::<Type>(),
);
println!("Value: {:x?}", full);
println!();
cursor.set_position(0);
let full = unsafe { <TypeBoxed>::deserialize_full(&mut cursor)? };
println!(
"Full-copy deserialization: returns the deserializable type {}",
core::any::type_name::<TypeBoxed>(),
);
println!("Value: {:x?}", full);
println!();
let eps = unsafe { <Type>::deserialize_eps(cursor.as_bytes())? };
println!(
"ε-copy deserialization: returns the associated deserialization type {}",
core::any::type_name::<DeserType<'_, Type>>(),
);
println!("Value: {:x?}", eps);
#[cfg(not(feature = "schema"))]
println!("\nPlease compile with the \"schema\" feature to see the schema output");
Ok(())
}