Trait airmash_protocol::Protocol [−][src]
pub trait Protocol: Sync + Send { type SerializeError: Error; type DeserializeError: Error; fn version(&self) -> u8; fn serialize_client(
&self,
packet: &ClientPacket
) -> Result<Box<Iterator<Item = Vec<u8>>>, Self::SerializeError>; fn serialize_server(
&self,
packet: &ServerPacket
) -> Result<Box<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
type DeserializeError: Error
Required Methods
fn version(&self) -> u8
Unique version number for the protocol.
fn serialize_client(
&self,
packet: &ClientPacket
) -> Result<Box<Iterator<Item = Vec<u8>>>, Self::SerializeError>
&self,
packet: &ClientPacket
) -> Result<Box<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<Iterator<Item = Vec<u8>>>, Self::SerializeError>
&self,
packet: &ServerPacket
) -> Result<Box<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>
&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>
&self,
data: &[u8]
) -> Result<ServerPacket, Self::DeserializeError>
Deserialize a binary packet into a server packet.