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, first call the fallible
my_packet.as_packet(&serde_context)?, then
outgoing.as_frames(security_context)?. To turn frames into a packet, use
IncomingPacket::from_frames(frames, security_context) followed by the
packet’s TryFromPacket implementation. Receiver-controlled frame-count and
payload-byte limits can be enforced with
IncomingPacket::from_frames_with_limits or IncomingPacketReframer.
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§
- Incoming
Packet - 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.
- Incoming
Packet Reframer - Incrementally constructs logical packets from incoming frames.
- Reframing
Limits - Receiver policy for constructing one logical packet from frames.
- Security
Bytes - Container for MessageCounter and Checksum.
- Security
Context - Provides a complete security context to handle packets.
Enums§
- Framing
Error - Outgoing
Packet - A packet on its way out, before having been turned into a frame.
- Packet
Error - Reframing
Error
Traits§
- AsFrames
- A procedure to turn an element into actual SilkroadFrames, which can be written by the codec onto the wire.
- From
Frames - Provides a way to turn SilkroadFrames into an IncomingPacket.
- Packet
- Defines associated constants with this packet, which can be used to turn this struct into a packet.