Expand description
This crate mainly provides one trait: Packet. While you can implement it
yourself, you might as well use the derive macro to derive it instead (which
requires the derive
feature).
#[derive(Packet)]
#[packet(opcode = 0x5001)]
struct MyPacket {
content: String,
}
The rest of this crate focuses around converting a Packet into a
SilkroadFrame, or vice-versa. This currently takes a small detour through
using either an IncomingPacket or OutgoingPacket, depending on the
direction. This is done because we often first need to apply some kind of
transformation to the frames, before we can easily turn them into structs
representing the packet. This would include combining multiple massive
frames into one large buffer as well as decrypting the content of frames to
figure out their opcodes. Thus, the chain goes something like this, in a
simplified way. To turn a packet into frames:
myPacket.serialize().as_frames(context)
To turn frames into a packet:
IncomingPacket::from_frames(frames, context).try_into_packet::<MyPacket>()
However, this does require a bit more than just the Packet implementation. Either you need to implement the TryFromPacket and AsPacket traits yourself, or you need to implement/derive skrillax_serde::Serialize, skrillax_serde::Deserialize, and skrillax_serde::ByteSize from the skrillax_serde crate. With these, AsPacket and TryFromPacket are automatically implemented for you. They are necessary to serialize/deserialize the packet content into bytes, which can be sent using the frames.
§Derive
The derive macro currently has three options, for all the options the trait provides:
#[derive(Packet)]
#[packet(opcode = 0x5001, encrypted = true, massive = false)]
struct MyPacket {
content: String,
}
encrypted
and massive
are false
by default and are mutually exclusive.
opcode
is a required attribute, this is also considered the ID
of a
packet. The name is automatically considered to be the structure’s name.
Structs§
- An incoming packet that has already gone through re-framing of massive packets or decryption. It is essentially a collection of bytes for a given opcode, nothing more.
- Container for MessageCounter and Checksum.
- Provides a complete security context to handle packets.
Enums§
- A packet on its way out, before having been turned into a frame.
Traits§
- A procedure to turn an element into actual SilkroadFrames, which can be written by the codec onto the wire.
- Defines something that can be turned into a packet, which then can be sent out.
- Provides a way to turn SilkroadFrames into an IncomingPacket.
- Defines associated constants with this packet, which can be used to turn this struct into a packet.
- Defines something that can be created from a packet, after it has been received.