Trait DataTransform
pub trait DataTransform {
// Required methods
fn inbound_transform(
&self,
raw_message: RawMessage,
) -> Result<Message, Error>;
fn outbound_transform(
&self,
topic: &TopicHash,
data: Vec<u8>,
) -> Result<Vec<u8>, Error>;
}Available on crate feature
gossipsub only.Expand description
A general trait of transforming a RawMessage into a Message. The
RawMessage is obtained from the wire and the Message is used to
calculate the crate::MessageId of the message and is what is sent to the application.
The inbound/outbound transforms must be inverses. Applying the inbound transform and then the outbound transform MUST leave the underlying data un-modified.
By default, this is the identity transform for all fields in Message.
Required Methods§
fn inbound_transform(&self, raw_message: RawMessage) -> Result<Message, Error>
fn inbound_transform(&self, raw_message: RawMessage) -> Result<Message, Error>
Takes a RawMessage received and converts it to a Message.
fn outbound_transform(
&self,
topic: &TopicHash,
data: Vec<u8>,
) -> Result<Vec<u8>, Error>
fn outbound_transform( &self, topic: &TopicHash, data: Vec<u8>, ) -> Result<Vec<u8>, Error>
Takes the data to be published (a topic and associated data) transforms the data. The
transformed data will then be used to create a crate::RawMessage to be sent to peers.