Module parser

Source
Expand description

Contains all the type and interfaces for the parser sub-crates.

The parsing system in socketioxide is split in three phases for serialization and deserialization:

§Deserialization

  • The SocketIO server receives a packet and calls Parse::decode_str or Parse::decode_bin to decode the incoming packet. If a ParseError::NeedsMoreBinaryData is returned, the server keeps the packet and waits for new incoming data.
  • Once the packet is complete, the server dispatches the packet to the appropriate namespace and calls Parse::read_event to route the data to the appropriate event handler.
  • If the user-provided handler has a Data extractor with a provided T type, the server calls Parse::decode_value to deserialize the data. This function will handle the event name as the first argument of the array, as well as variadic arguments.

§Serialization

  • The user calls emit from the socket or namespace with custom Serializable data. The server calls Parse::encode_value to convert this to a raw Value to be included in the packet. The function will take care of handling the event name as the first argument of the array, along with variadic arguments.
  • The server then calls Parse::encode to convert the payload provided by the user, along with other metadata (namespace, ack ID, etc.), into a fully serialized packet ready to be sent.

Structs§

FirstElement
A seed that can be used to deserialize only the 1st element of a sequence
ParserError
A parser error that wraps any error that can occur during parsing.
ParserState
The parser state that is shared between the parser and the socket.io system. Used to handle partial binary packets when receiving binary packets that have adjacent binary attachments

Enums§

ParseError
Errors when parsing/serializing socket.io packets

Traits§

Parse
All socket.io parser should implement this trait. Parsers should be stateless.

Functions§

is_de_tuple
Returns true if the type is a tuple-like type according to the serde model.
is_ser_tuple
Returns true if the value is a tuple-like type according to the serde model.