[][src]Trait airmash_protocol::Protocol

pub trait Protocol: Sync + Send {
    type SerializeError: Error;
    type DeserializeError: Error;
    fn version(&self) -> u8;
fn serialize_client(
        &self,
        packet: &ClientPacket
    ) -> Result<Box<dyn Iterator<Item = Vec<u8>>>, Self::SerializeError>;
fn serialize_server(
        &self,
        packet: &ServerPacket
    ) -> Result<Box<dyn Iterator<Item = Vec<u8>>>, Self::SerializeError>;
fn deserialize_client(
        &self,
        data: &[u8]
    ) -> Result<ClientPacket, Self::DeserializeError>;
fn deserialize_server(
        &self,
        data: &[u8]
    ) -> Result<ServerPacket, Self::DeserializeError>; }

Interface to implement for all protocols.

Associated Types

type SerializeError: Error

Error for when a packet fails to serialize.

This should be broad enough to be able to deal with failures for both ClientPacket and ServerPacket.

type DeserializeError: Error

Error for when a packet fails to deserialize.

This should be broad enough to be able to deal with failures for both ClientPacket and ServerPacket.

Loading content...

Required methods

fn version(&self) -> u8

Unique version number for the protocol.

fn serialize_client(
    &self,
    packet: &ClientPacket
) -> Result<Box<dyn Iterator<Item = Vec<u8>>>, Self::SerializeError>

Serialize a client packet into some number of binary packet bodies.

For most packets this should be a 1-to-1 deserialization but the iterator return type is there to allow for polyfilling of the packets behind the scenes if a protocol backend doesn't support them directly. This can be used (for example) to send multiple packets for when more than 255 missiles are reflected with the same goliath deflect (which is not supported by protocol-v5).

For users of this interface it will most likely be more convienient to call ProtocolSerializationExt::serialize() with a ClientPacket instead, since it provides a unified interface to serializing a ClientPacket and a ServerPacket.

Panics

This method should never panic (based on the input), instead it should return an appropriate error within the SerializeError type.

fn serialize_server(
    &self,
    packet: &ServerPacket
) -> Result<Box<dyn Iterator<Item = Vec<u8>>>, Self::SerializeError>

Serialize a server packet into some number of binary packet bodies.

For most packets this should be a 1-to-1 deserialization but the iterator return type is there to allow for polyfilling of the packets behind the scenes if a protocol backend doesn't support them directly. This can be used (for example) to send multiple packets for when more than 255 missiles are reflected with the same goliath deflect (which is not supported by protocol-v5).

For users of this interface it will most likely be more convienient to call ProtocolSerializationExt::serialize() with a ServerPacket instead, since it provides a unified interface to serializing a ServerPacket and a ClientPacket.

Panics

This method should never panic (based on the input), instead it should return an appropriate error within the SerializeError type.

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

Deserialize a binary packet into a client packet.

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

Deserialize a binary packet into a server packet.

Loading content...

Implementors

Loading content...