Struct rkyv::ser::serializers::BufferSerializer [−][src]
pub struct BufferSerializer<T> { /* fields omitted */ }
Expand description
Wraps a byte buffer and equips it with Serializer
.
Common uses include archiving in #![no_std]
environments and archiving small objects without
allocating.
Examples
use rkyv::{ archived_value, ser::{Serializer, serializers::BufferSerializer}, AlignedBytes, AlignedVec, Archive, Archived, Serialize, }; #[derive(Archive, Serialize)] enum Event { Spawn, Speak(String), Die, } let mut serializer = BufferSerializer::new(AlignedBytes([0u8; 256])); let pos = serializer.serialize_value(&Event::Speak("Help me!".to_string())) .expect("failed to archive event"); let buf = serializer.into_inner(); let archived = unsafe { archived_value::<Event>(buf.as_ref(), pos) }; if let Archived::<Event>::Speak(message) = archived { assert_eq!(message.as_str(), "Help me!"); } else { panic!("archived event was of the wrong type"); }
Implementations
Creates a new archive buffer from a byte buffer. The buffer will start writing at the given position, but the buffer must contain all bytes (otherwise the alignments of types may not be correct).
Consumes the serializer and returns the underlying type.
Trait Implementations
type Error = BufferSerializerError
type Error = BufferSerializerError
The error produced by any failing methods.
Attempts to write the given bytes to the serializer.
Advances the given number of bytes as padding.
Aligns the position of the serializer to the given alignment.
Aligns the position of the serializer to be suitable to write the given type.
Resolves the given value with its resolver and writes the archived type. Read more
Archives the given object and returns the position it was archived at.
unsafe fn resolve_unsized_aligned<T: ArchiveUnsized + ?Sized>(
&mut self,
value: &T,
to: usize,
metadata_resolver: T::MetadataResolver
) -> Result<usize, Self::Error>
unsafe fn resolve_unsized_aligned<T: ArchiveUnsized + ?Sized>(
&mut self,
value: &T,
to: usize,
metadata_resolver: T::MetadataResolver
) -> Result<usize, Self::Error>
Resolves the given reference with its resolver and writes the archived reference. Read more
fn serialize_unsized_value<T: SerializeUnsized<Self> + ?Sized>(
&mut self,
value: &T
) -> Result<usize, Self::Error>
fn serialize_unsized_value<T: SerializeUnsized<Self> + ?Sized>(
&mut self,
value: &T
) -> Result<usize, Self::Error>
Archives a reference to the given object and returns the position it was archived at.
Auto Trait Implementations
impl<T> RefUnwindSafe for BufferSerializer<T> where
T: RefUnwindSafe,
impl<T> Send for BufferSerializer<T> where
T: Send,
impl<T> Sync for BufferSerializer<T> where
T: Sync,
impl<T> Unpin for BufferSerializer<T> where
T: Unpin,
impl<T> UnwindSafe for BufferSerializer<T> where
T: UnwindSafe,
Blanket Implementations
type ArchivedMetadata = ()
type ArchivedMetadata = ()
The archived version of the pointer metadata for this type.
Converts some archived metadata to the pointer metadata for itself.
Mutably borrows from an owned value. Read more