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§
Sourcetype Error: Error + From<UnknownMessageType> + Send + Sync + 'static
type Error: Error + From<UnknownMessageType> + Send + Sync + 'static
The error type for the transformation.
Sourcetype Address: CheapClone + Send + Sync + 'static
type Address: CheapClone + Send + Sync + 'static
The Address type.
Required Methods§
Sourcefn encode_filter(filter: &Filter<Self::Id>) -> Result<Bytes, Self::Error>
fn encode_filter(filter: &Filter<Self::Id>) -> Result<Bytes, Self::Error>
Encodes the filter into bytes.
Sourcefn decode_filter(bytes: &[u8]) -> Result<(usize, Filter<Self::Id>), Self::Error>
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.
Sourcefn node_encoded_len(node: &Node<Self::Id, Self::Address>) -> usize
fn node_encoded_len(node: &Node<Self::Id, Self::Address>) -> usize
Returns the encoded length of the node.
Sourcefn encode_node(
node: &Node<Self::Id, Self::Address>,
dst: &mut [u8],
) -> Result<usize, Self::Error>
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.
Sourcefn decode_node(
bytes: impl AsRef<[u8]>,
) -> Result<(usize, Node<Self::Id, Self::Address>), Self::Error>
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.
Sourcefn id_encoded_len(id: &Self::Id) -> usize
fn id_encoded_len(id: &Self::Id) -> usize
Returns the encoded length of the id.
Sourcefn encode_id(id: &Self::Id, dst: &mut [u8]) -> Result<usize, Self::Error>
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.
Sourcefn decode_id(bytes: &[u8]) -> Result<(usize, Self::Id), Self::Error>
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.
Sourcefn address_encoded_len(address: &Self::Address) -> usize
fn address_encoded_len(address: &Self::Address) -> usize
Returns the encoded length of the address.
Sourcefn encode_address(
address: &Self::Address,
dst: &mut [u8],
) -> Result<usize, Self::Error>
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.
Sourcefn decode_address(bytes: &[u8]) -> Result<(usize, Self::Address), Self::Error>
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.
Sourcefn coordinate_encoded_len(coordinate: &Coordinate) -> usize
fn coordinate_encoded_len(coordinate: &Coordinate) -> usize
Encoded length of the coordinate.
Sourcefn encode_coordinate(
coordinate: &Coordinate,
dst: &mut [u8],
) -> Result<usize, Self::Error>
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.
Sourcefn decode_coordinate(bytes: &[u8]) -> Result<(usize, Coordinate), Self::Error>
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.
Encoded length of the tags.
Encodes the tags into the given buffer, returning the number of bytes written.
Decodes the tags from the given bytes, returning the number of bytes consumed and the tags.
Sourcefn message_encoded_len(msg: impl AsMessageRef<Self::Id, Self::Address>) -> usize
fn message_encoded_len(msg: impl AsMessageRef<Self::Id, Self::Address>) -> usize
Encoded length of the message.
Sourcefn encode_message(
msg: impl AsMessageRef<Self::Id, Self::Address>,
dst: impl AsMut<[u8]>,
) -> Result<usize, Self::Error>
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:
- 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. - A message type byte will be automatically prepended to the buffer, so users do not need to encode the message type byte by themselves.
Sourcefn decode_message(
ty: MessageType,
bytes: impl AsRef<[u8]>,
) -> Result<(usize, SerfMessage<Self::Id, Self::Address>), Self::Error>
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.