pub trait SphinxPayload: LightningEncode + LightningDecode + StrictEncode + StrictDecode + Debug + Clone + Hash + Eq {
    type DecodeError: Error;

    // Required methods
    fn serialized_len(&self) -> usize;
    fn encode(&self, writer: impl Write) -> Result<usize, Error>;
    fn decode(reader: impl Read) -> Result<Self, Self::DecodeError>
where Self: Sized; // Provided method fn serialize(&self) -> Vec<u8> { ... } }
Expand description

Sphinx is abstracted from a specific encoding used by a packed payload: it may be BOLT-4 lightning, strict encoding or any other encoding. Specific payload types must implement this trait to provide Internet2 crate with a proper encoding implementation.

Required Associated Types§

source

type DecodeError: Error

Errors during payload decoding

Required Methods§

source

fn serialized_len(&self) -> usize

Calculate total size of the payload encoded data.

Must not call SphinxPayload::serialize otherwise this will result in infinite call loop.

source

fn encode(&self, writer: impl Write) -> Result<usize, Error>

Encodes payload data into a binary byte stream. Must return number of bytes added to the stream.

source

fn decode(reader: impl Read) -> Result<Self, Self::DecodeError>where
Self: Sized,

Decodes payload from a binary byte stream

Provided Methods§

source

fn serialize(&self) -> Vec<u8>

Serialize payload as a byte vector

Implementors§