Skip to main content

Serialiser

Trait Serialiser 

Source
pub trait Serialiser<T>: Send + TryClone {
    // Required methods
    fn ser_id(&self) -> u64;
    fn serialise(&self, v: &T, buf: &mut dyn BufMut) -> Result<(), SerError>;

    // Provided methods
    fn size_hint(&self) -> Option<usize> { ... }
    fn try_clone_data(&self, _v: &T) -> Option<T> { ... }
}
Expand description

A trait for types that can serialise data of type T

Required Methods§

Source

fn ser_id(&self) -> u64

The serialisation id for this serialiser

Serialisation ids are used to determine the deserialiser to use with a particular byte buffer. They are prepended to the actual serialised data and read first during deserialisation. Serialisation ids must be globally unique within a distributed Kompact system.

Source

fn serialise(&self, v: &T, buf: &mut dyn BufMut) -> Result<(), SerError>

Serialise v into buf.

Serialisation should produce a copy, and not consume the original value.

Returns a SerError if unsuccessful.

Provided Methods§

Source

fn size_hint(&self) -> Option<usize>

An indicator how many bytes must be reserved in a buffer for a value to be serialsed into it with this serialiser

If the total size is unknown, None should be returned.

Generally, size hints should be cheap to calculate, compared to the actual serialisation, since they are simply optimisations to avoid many small memory allocations during the serialisation process.

Source

fn try_clone_data(&self, _v: &T) -> Option<T>

Produce a copy of v, if possible

If it can’t be done cheaply, simply return None (which is the default implementation).

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementors§