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§
Sourcefn ser_id(&self) -> u64
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.
Sourcefn size_hint(&self) -> Option<usize>
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.
Provided Methods§
Sourcefn serialised(&self) -> Result<Serialised, SerError>
fn serialised(&self) -> Result<Serialised, SerError>
Serialise with a one-off buffer
Calls serialise internally by default.
Sourcefn cloned(&self) -> Option<Box<dyn Serialisable>>
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>
Turns a pair of a Serialiser and value of it’s type T into a
heap-allocated Serialisable
impl<T, S> From<(T, S)> for Box<dyn Serialisable>
Turns a pair of a Serialiser and value of it’s type T into a
heap-allocated Serialisable
Source§impl<T> From<T> for Box<dyn Serialisable>
Turns a stack-allocated Serialisable into a
heap-allocated Serialisable
impl<T> From<T> for Box<dyn Serialisable>
Turns a stack-allocated Serialisable into a heap-allocated Serialisable
Source§fn from(t: T) -> Box<dyn Serialisable>
fn from(t: T) -> Box<dyn Serialisable>
Source§impl TryFrom<&dyn Serialisable> for Serialised
impl TryFrom<&dyn Serialisable> for Serialised
Source§fn try_from(
ser: &dyn Serialisable,
) -> Result<Serialised, <Serialised as TryFrom<&dyn Serialisable>>::Error>
fn try_from( ser: &dyn Serialisable, ) -> Result<Serialised, <Serialised as TryFrom<&dyn Serialisable>>::Error>
Implementations on Foreign Types§
Source§impl Serialisable for u64
impl Serialisable for u64
Source§impl Serialisable for ()
impl Serialisable for ()
Source§impl Serialisable for String
impl Serialisable for String
Implementors§
impl Serialisable for ActorPath
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) |
+---------------------------------------------------------------+----------------+