pub enum Packet {
Open(OpenPacket),
Close,
Ping,
Pong,
PingUpgrade,
PongUpgrade,
Message(Str),
Upgrade,
Noop,
Binary(Bytes),
BinaryV3(Bytes),
}Expand description
A Packet type to use when receiving and sending data from the client
Variants§
Open(OpenPacket)
Open packet used to initiate a connection
Close
Close packet used to close a connection
Ping
Ping packet used to check if the connection is still alive The client never sends this packet, it is only used by the server
Pong
Pong packet used to respond to a Ping packet The server never sends this packet, it is only used by the client
PingUpgrade
Special Ping packet used to initiate a connection
PongUpgrade
Special Pong packet used to respond to a PingUpgrade packet and upgrade the connection
Message(Str)
Message packet used to send a message to the client
Upgrade
Upgrade packet to upgrade the connection from polling to websocket
Noop
Noop packet used to send something to a opened polling connection so it gracefully closes to allow the client to upgrade to websocket
Binary(Bytes)
Binary packet used to send binary data to the client Converts to a String using base64 encoding when using polling connection Or to a websocket binary frame when using websocket connection
When receiving, it is only used with polling connection, websocket use binary frame
BinaryV3(Bytes)
Binary packet used to send binary data to the client Converts to a String using base64 encoding when using polling connection Or to a websocket binary frame when using websocket connection
When receiving, it is only used with polling connection, websocket use binary frame
This is a special packet, excepionally specific to the V3 protocol.
Implementations§
Source§impl Packet
impl Packet
Sourcepub fn into_message(self) -> Str
pub fn into_message(self) -> Str
If the packet is a message packet (text), it returns the message
Sourcepub fn into_binary(self) -> Bytes
pub fn into_binary(self) -> Bytes
If the packet is a binary packet, it returns the binary data
Sourcepub fn get_size_hint(&self, b64: bool) -> usize
pub fn get_size_hint(&self, b64: bool) -> usize
Get the max size the packet could have when serialized
If b64 is true, it returns the max size when serialized to base64
The base64 max size factor is ceil(n / 3) * 4