[][src]Trait airmash_protocol::ProtocolSerializationExt

pub trait ProtocolSerializationExt<T>: Protocol {
    fn serialize<U>(
        &self,
        packet: U
    ) -> Result<Box<dyn Iterator<Item = Vec<u8>>>, Self::SerializeError>
    where
        U: Into<T>
;
fn deserialize(&self, data: &[u8]) -> Result<T, Self::DeserializeError>; }

Helper trait to make working with protocols easier.

This allows for ServerPacket and ClientPacket to be serialized and deserialized without using the serialize_* or deserialize_* methods within the Protocol trait. Instead they can use serialize and deserialize and let type inference deduce the correct type.

This trait should not be implemented by client code.

Required methods

fn serialize<U>(
    &self,
    packet: U
) -> Result<Box<dyn Iterator<Item = Vec<u8>>>, Self::SerializeError> where
    U: Into<T>, 

Serialize a packet. This can be either a ClientPacket or a ServerPacket depending on the instantiation of this trait.

fn deserialize(&self, data: &[u8]) -> Result<T, Self::DeserializeError>

Deserialize a packet. This can be either a ClientPacket or a ServerPacket depending on the instantiation of this trait.

Loading content...

Implementors

impl<T> ProtocolSerializationExt<ClientPacket> for T where
    T: Protocol + Sync + Send
[src]

impl<T> ProtocolSerializationExt<ServerPacket> for T where
    T: Protocol + Sync + Send
[src]

Loading content...