Trait TryFromPacket

Source
pub trait TryFromPacket {
    // Required method
    fn try_deserialize(data: &[u8]) -> Result<(usize, Self), PacketError>
       where Self: Sized;
}
Expand description

Defines something that can be created from a packet, after it has been received.

Once a re-framing, decryption and other parts have completed, we want to turn the contained data into a usable structure.

The analog is AsPacket.

Required Methods§

Source

fn try_deserialize(data: &[u8]) -> Result<(usize, Self), PacketError>
where Self: Sized,

Tries to create Self from the given data. Unlike AsPacket, we do not deal with the opcode here. It is expected that we have already matched the opcode to Self and know it matches.

data may contain more data than necessary to form a single packet, for example if we were inside a massive frame. Thus, we need to return the amount of consumed bytes such that the remainder may be used to create more elements of Self if the caller wants to.

Implementors§

Source§

impl<T> TryFromPacket for T
where T: Packet + Deserialize + Send,