Serde API Reference#

class flare.internal.serde.Serde(sep: str = '\x81', null: str = '\x82', esc: str = '\\', increment_length: int = 3, version: int | None = 0)[source]#

Bases: SerdeABC

A class that handles serialization and deserialization of component custom_id encoded data.

For simple behaviour changes it may be sufficient to subclass this class, but if you desire to completely overhaul serialization and deserialization, you may wish to only subclass SerdeABC instead.

Parameters:
  • sep – The character used to serperate fields.

  • null – The character used to signify None.

  • esc – The escape character.

  • increment_lengthincrement is a unique number to allow buttons for the same values in the same message. increment_length can be set to 0 if identical buttons are never used in the same message.

  • version – The serializer version number.

async deserialize(custom_id: str, map: dict[str, t.Any]) tuple[type[base.SupportsCallback[t.Any]], dict[str, t.Any]][source]#

Decode a custom_id for a component.

Parameters:
  • custom_id – The custom_id of the component.

  • map – A dictionary of cookies to components.

escape(string: str) str[source]#

Escape a string using self.ESC, self.NULL and self.SEP.

async serialize(cookie: str, types: dict[str, Any], kwargs: dict[str, Any]) str[source]#

Encode a custom_id for a component.

Parameters:
  • cookie – A unique identifier for the component.

  • types – A dictionary of argument names to argument type hints. The type hint is used to encode a value to a string.

  • kwargs – Values that the user passes to save state.

split_on_sep(string: list[tuple[str, bool]]) list[list[tuple[str, bool]]][source]#

Split the provided string on the separator, but ignore separators that are escaped.

Parameters:

string – The provided string.

Returns:

list[str]

The split string.

static tuple_list_to_string(string: list[tuple[str, bool]]) str[source]#

Combine a list of tuples into a string, ignoring the second value.

unescape(string: str) list[tuple[str, bool]][source]#

Returns a list of tuples signifying (the character, whether it was escaped)

property ESC: str#

The escape character.

property NULL: str#

Character used to represent a missing value.

property SEP: str#

The separator used to separate arguments.

property VER: int | None#

The version of the serialization format. If None, the serializer will not attempt to verify the version of the serialized data.