Skip to main content

Serialisable

Trait Serialisable 

Source
pub trait Serialisable: Send + Debug {
    // Required methods
    fn ser_id(&self) -> u64;
    fn size_hint(&self) -> Option<usize>;
    fn serialise(&self, buf: &mut dyn BufMut) -> Result<(), SerError>;
    fn local(
        self: Box<Self>,
    ) -> Result<Box<dyn Any + Send>, Box<dyn Serialisable>>;

    // Provided methods
    fn serialised(&self) -> Result<Serialised, SerError> { ... }
    fn cloned(&self) -> Option<Box<dyn Serialisable>> { ... }
}
Expand description

A trait for values that can serialise themselves into a buffer

Required Methods§

Source

fn ser_id(&self) -> u64

The serialisation id for this serialisable

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 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 serialise(&self, buf: &mut dyn BufMut) -> Result<(), SerError>

Serialises this object (self) into buf

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

Returns a SerError if unsuccessful.

Source

fn local(self: Box<Self>) -> Result<Box<dyn Any + Send>, Box<dyn Serialisable>>

Try move this object onto the heap for reflection, instead of serialising

Returns the original object if the move fails, so that it can still be serialised.

Provided Methods§

Source

fn serialised(&self) -> Result<Serialised, SerError>

Serialise with a one-off buffer

Calls serialise internally by default.

Source

fn cloned(&self) -> Option<Box<dyn Serialisable>>

Try to produce a cheap in-memory copy of this

The default implementation returns None.

Trait Implementations§

Source§

impl<T, S> From<(T, S)> for Box<dyn Serialisable>
where T: Send + Debug + 'static, S: Serialiser<T> + 'static,

Turns a pair of a Serialiser and value of it’s type T into a heap-allocated Serialisable

Source§

fn from(t: (T, S)) -> Box<dyn Serialisable>

Converts to this type from the input type.
Source§

impl<T> From<T> for Box<dyn Serialisable>
where T: Send + Debug + Serialisable + 'static,

Turns a stack-allocated Serialisable into a heap-allocated Serialisable

Source§

fn from(t: T) -> Box<dyn Serialisable>

Converts to this type from the input type.
Source§

impl TryFrom<&dyn Serialisable> for Serialised

Source§

type Error = SerError

The type returned in the event of a conversion error.
Source§

fn try_from( ser: &dyn Serialisable, ) -> Result<Serialised, <Serialised as TryFrom<&dyn Serialisable>>::Error>

Performs the conversion.

Implementations on Foreign Types§

Source§

impl Serialisable for u64

Source§

fn ser_id(&self) -> u64

Source§

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

Source§

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

Source§

fn local(self: Box<u64>) -> Result<Box<dyn Any + Send>, Box<dyn Serialisable>>

Source§

impl Serialisable for ()

Source§

fn ser_id(&self) -> u64

Source§

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

Source§

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

Source§

fn local(self: Box<()>) -> Result<Box<dyn Any + Send>, Box<dyn Serialisable>>

Source§

impl Serialisable for String

Source§

fn ser_id(&self) -> u64

Source§

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

Source§

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

Source§

fn local( self: Box<String>, ) -> Result<Box<dyn Any + Send>, Box<dyn Serialisable>>

Implementors§

Source§

impl Serialisable for ActorPath

Source§

impl Serialisable for SystemPath

§Actor Path Serialization

An actor path is either Unique or Named and contains a SystemPath. The SystemPath’s header disambiguates the type (Path type).

§Unique Actor Paths

+---------------------------+
| System path (*)         ...
+---------------+-----------+
|      UUID (16 bytes)      |
+---------------------------+

§Named Actor Paths

+---------------------------+
| System path (*)         ...
+---------------+-----------+-------------------------------+
|      Named path (2 bytes prefix + variable length)      ...
+-----------------------------------------------------------+

§System Paths

+-------------------+-------------------+-----------------------+
| Path type (1 bit) | Protocol (5 bits) | Address Type (2 bits) |
+-------------------+-------------------+-----------------------+----------------+
|                   Address (4/16/ * bytes)                  ...| Port (2 bytes) |
+---------------------------------------------------------------+----------------+
Source§

impl<T, S> Serialisable for SerialisableValue<T, S>
where T: Send + Debug + 'static, S: Serialiser<T> + 'static,