Skip to main content

PacketEncoder

Trait PacketEncoder 

Source
pub trait PacketEncoder {
    type Error: Error + Send + Sync + 'static;

    // Required methods
    fn encode_packet<T: AsRef<[u8]> + Send + 'static, S: Into<PacketSignals> + Send + 'static>(
        &self,
        data: T,
        routing: ResolvedTransportRouting<HoprSurb>,
        signals: S,
    ) -> Result<OutgoingPacket, Self::Error>;
    fn encode_acknowledgements(
        &self,
        acks: &[VerifiedAcknowledgement],
        destination: &OffchainPublicKey,
    ) -> Result<OutgoingPacket, Self::Error>;
}
Expand description

Trait defining encoder for outgoing HOPR packets.

These operations are done directly by the packet processing pipeline before the outgoing packet is handled to the underlying p2p transport.

Required Associated Types§

Source

type Error: Error + Send + Sync + 'static

Required Methods§

Source

fn encode_packet<T: AsRef<[u8]> + Send + 'static, S: Into<PacketSignals> + Send + 'static>( &self, data: T, routing: ResolvedTransportRouting<HoprSurb>, signals: S, ) -> Result<OutgoingPacket, Self::Error>

Encodes the given data and signals for sending.

The data MUST be already correctly sized for HOPR packets, otherwise the operation must fail.

Source

fn encode_acknowledgements( &self, acks: &[VerifiedAcknowledgement], destination: &OffchainPublicKey, ) -> Result<OutgoingPacket, Self::Error>

Encodes the given vector of VerifiedAcknowledgements as an outgoing packet to be sent to the given destination.

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.

Implementations on Foreign Types§

Source§

impl<'a, U: 'a + PacketEncoder + ?Sized> PacketEncoder for &'a U

Source§

type Error = <U as PacketEncoder>::Error

Source§

fn encode_packet<T: AsRef<[u8]> + Send + 'static, S: Into<PacketSignals> + Send + 'static>( &self, data: T, routing: ResolvedTransportRouting<HoprSurb>, signals: S, ) -> Result<OutgoingPacket, Self::Error>

Source§

fn encode_acknowledgements( &self, acks: &[VerifiedAcknowledgement], destination: &OffchainPublicKey, ) -> Result<OutgoingPacket, Self::Error>

Source§

impl<U: PacketEncoder + ?Sized> PacketEncoder for Box<U>

Source§

type Error = <U as PacketEncoder>::Error

Source§

fn encode_packet<T: AsRef<[u8]> + Send + 'static, S: Into<PacketSignals> + Send + 'static>( &self, data: T, routing: ResolvedTransportRouting<HoprSurb>, signals: S, ) -> Result<OutgoingPacket, Self::Error>

Source§

fn encode_acknowledgements( &self, acks: &[VerifiedAcknowledgement], destination: &OffchainPublicKey, ) -> Result<OutgoingPacket, Self::Error>

Source§

impl<U: PacketEncoder + ?Sized> PacketEncoder for Arc<U>

Source§

type Error = <U as PacketEncoder>::Error

Source§

fn encode_packet<T: AsRef<[u8]> + Send + 'static, S: Into<PacketSignals> + Send + 'static>( &self, data: T, routing: ResolvedTransportRouting<HoprSurb>, signals: S, ) -> Result<OutgoingPacket, Self::Error>

Source§

fn encode_acknowledgements( &self, acks: &[VerifiedAcknowledgement], destination: &OffchainPublicKey, ) -> Result<OutgoingPacket, Self::Error>

Implementors§

Source§

impl<Chain, S, T> PacketEncoder for HoprEncoder<Chain, S, T>
where Chain: ChainKeyOperations + ChainReadChannelOperations + ChainReadTicketOperations + ChainValues + Send + Sync, S: SurbStore + Send + Sync, T: TicketFactory + Send + Sync,