Trait TransformDelegate

Source
pub trait TransformDelegate:
    Send
    + Sync
    + 'static {
    type Error: Error + From<UnknownMessageType> + Send + Sync + 'static;
    type Id: Id;
    type Address: CheapClone + Send + Sync + 'static;

Show 20 methods // Required methods fn encode_filter(filter: &Filter<Self::Id>) -> Result<Bytes, Self::Error>; fn decode_filter( bytes: &[u8], ) -> Result<(usize, Filter<Self::Id>), Self::Error>; fn node_encoded_len(node: &Node<Self::Id, Self::Address>) -> usize; fn encode_node( node: &Node<Self::Id, Self::Address>, dst: &mut [u8], ) -> Result<usize, Self::Error>; fn decode_node( bytes: impl AsRef<[u8]>, ) -> Result<(usize, Node<Self::Id, Self::Address>), Self::Error>; fn id_encoded_len(id: &Self::Id) -> usize; fn encode_id(id: &Self::Id, dst: &mut [u8]) -> Result<usize, Self::Error>; fn decode_id(bytes: &[u8]) -> Result<(usize, Self::Id), Self::Error>; fn address_encoded_len(address: &Self::Address) -> usize; fn encode_address( address: &Self::Address, dst: &mut [u8], ) -> Result<usize, Self::Error>; fn decode_address( bytes: &[u8], ) -> Result<(usize, Self::Address), Self::Error>; fn coordinate_encoded_len(coordinate: &Coordinate) -> usize; fn encode_coordinate( coordinate: &Coordinate, dst: &mut [u8], ) -> Result<usize, Self::Error>; fn decode_coordinate( bytes: &[u8], ) -> Result<(usize, Coordinate), Self::Error>; fn tags_encoded_len(tags: &Tags) -> usize; fn encode_tags(tags: &Tags, dst: &mut [u8]) -> Result<usize, Self::Error>; fn decode_tags(bytes: &[u8]) -> Result<(usize, Tags), Self::Error>; fn message_encoded_len( msg: impl AsMessageRef<Self::Id, Self::Address>, ) -> usize; fn encode_message( msg: impl AsMessageRef<Self::Id, Self::Address>, dst: impl AsMut<[u8]>, ) -> Result<usize, Self::Error>; fn decode_message( ty: MessageType, bytes: impl AsRef<[u8]>, ) -> Result<(usize, SerfMessage<Self::Id, Self::Address>), Self::Error>;
}
Expand description

A delegate for encoding and decoding.

Required Associated Types§

Source

type Error: Error + From<UnknownMessageType> + Send + Sync + 'static

The error type for the transformation.

Source

type Id: Id

The Id type.

Source

type Address: CheapClone + Send + Sync + 'static

The Address type.

Required Methods§

Source

fn encode_filter(filter: &Filter<Self::Id>) -> Result<Bytes, Self::Error>

Encodes the filter into bytes.

Source

fn decode_filter(bytes: &[u8]) -> Result<(usize, Filter<Self::Id>), Self::Error>

Decodes the filter from the given bytes, returning the number of bytes consumed and the filter.

Source

fn node_encoded_len(node: &Node<Self::Id, Self::Address>) -> usize

Returns the encoded length of the node.

Source

fn encode_node( node: &Node<Self::Id, Self::Address>, dst: &mut [u8], ) -> Result<usize, Self::Error>

Encodes the node into the given buffer, returning the number of bytes written.

Source

fn decode_node( bytes: impl AsRef<[u8]>, ) -> Result<(usize, Node<Self::Id, Self::Address>), Self::Error>

Decodes Node from the given bytes, returning the number of bytes consumed and the node.

Source

fn id_encoded_len(id: &Self::Id) -> usize

Returns the encoded length of the id.

Source

fn encode_id(id: &Self::Id, dst: &mut [u8]) -> Result<usize, Self::Error>

Encodes the id into the given buffer, returning the number of bytes written.

Source

fn decode_id(bytes: &[u8]) -> Result<(usize, Self::Id), Self::Error>

Decodes the id from the given bytes, returning the number of bytes consumed and the id.

Source

fn address_encoded_len(address: &Self::Address) -> usize

Returns the encoded length of the address.

Source

fn encode_address( address: &Self::Address, dst: &mut [u8], ) -> Result<usize, Self::Error>

Encodes the address into the given buffer, returning the number of bytes written.

Source

fn decode_address(bytes: &[u8]) -> Result<(usize, Self::Address), Self::Error>

Decodes the address from the given bytes, returning the number of bytes consumed and the address.

Source

fn coordinate_encoded_len(coordinate: &Coordinate) -> usize

Encoded length of the coordinate.

Source

fn encode_coordinate( coordinate: &Coordinate, dst: &mut [u8], ) -> Result<usize, Self::Error>

Encodes the coordinate into the given buffer, returning the number of bytes written.

Source

fn decode_coordinate(bytes: &[u8]) -> Result<(usize, Coordinate), Self::Error>

Decodes the coordinate from the given bytes, returning the number of bytes consumed and the coordinate.

Source

fn tags_encoded_len(tags: &Tags) -> usize

Encoded length of the tags.

Source

fn encode_tags(tags: &Tags, dst: &mut [u8]) -> Result<usize, Self::Error>

Encodes the tags into the given buffer, returning the number of bytes written.

Source

fn decode_tags(bytes: &[u8]) -> Result<(usize, Tags), Self::Error>

Decodes the tags from the given bytes, returning the number of bytes consumed and the tags.

Source

fn message_encoded_len(msg: impl AsMessageRef<Self::Id, Self::Address>) -> usize

Encoded length of the message.

Source

fn encode_message( msg: impl AsMessageRef<Self::Id, Self::Address>, dst: impl AsMut<[u8]>, ) -> Result<usize, Self::Error>

Encodes the message into the given buffer, returning the number of bytes written.

NOTE:

  1. The buffer must be large enough to hold the encoded message. The length of the buffer can be obtained by calling TransformDelegate::message_encoded_len.
  2. A message type byte will be automatically prepended to the buffer, so users do not need to encode the message type byte by themselves.
Source

fn decode_message( ty: MessageType, bytes: impl AsRef<[u8]>, ) -> Result<(usize, SerfMessage<Self::Id, Self::Address>), Self::Error>

Decodes the message from the given bytes, returning the number of bytes consumed and the message.

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§

Source§

impl<I, A> TransformDelegate for LpeTransfromDelegate<I, A>
where I: Id, A: Transformable + CheapClone + Hash + Eq + Send + Sync + 'static,

Source§

impl<I, A, M, R, T> TransformDelegate for CompositeDelegate<I, A, M, R, T>
where I: Id, A: CheapClone + Send + Sync + 'static, M: Send + Sync + 'static, R: Send + Sync + 'static, T: TransformDelegate<Id = I, Address = A>,