define_protocol

Macro define_protocol 

Source
macro_rules! define_protocol {
    ($name:ident => $($enumValue:ident),*) => { ... };
    ($name:ident => $($enumValue:ident),* + $($innerProto:ident),*) => { ... };
}
Expand description

Defines a protocol from a list of packets and/or other protocols.

A protocol always has a name and may contain packets and/or other protocols. This protocol will then be represented as an enum, where each of the packets/protocols is its own variant. With this enum, all the necessary traits for usage with skrillax_stream will then be implemented. In particular, the following traits will be implement by the generated enum:

The basic macro invokation looks like this:

define_protocol! { MyProtocolName =>
    MyPacket,
    MyOtherPacket
    +
    MyProtocol
}

This assumes MyPacket & MyOtherPacket derive skrillax_packet::Packet and MyProtocol has also been created using define_protocol!.

(!) One limitation of define_protocol! is, because it always provides an implementation for InputProtocol & OutputProtocol, it requires all packets and protocols to be both Serialize & Derserialize. For some packets, that may not be possible, for example when there’s a zero-length optional field. Any protocols those packets are included would also automatically not be both serialize and deserialize and could thus also not be used.