risa.codecs¶
How InMessage state is written into custom_id characters.
BASE85, the default, is built in and keeps every character printable ASCII.
BASE32768 and URO14 come with the [radixly] extra and carry more than twice as
many bytes per character.
BASE32768
module-attribute
¶
15 bits per character, the densest codec; needs the [radixly] extra.
BASE85
module-attribute
¶
BASE85: Final[Codec] = Codec(
tag="a",
name="base85",
encode=_b85_encode,
decode=_b85_decode,
max_bytes=_b85_max_bytes,
)
The default codec: printable ASCII, built in, needs no extra.
RADIXLY_EXTRA
module-attribute
¶
The name of the extra (hikari-risa[radixly]) that BASE32768 and URO14 need.
URO14
module-attribute
¶
14 bits per CJK character behind a length prefix; needs the [radixly] extra.
Codec
¶
Codec(
tag: str,
name: str,
encode: Callable[[bytes], str],
decode: Callable[[str], bytes],
max_bytes: Callable[[int], int],
)
Bases: Struct
A way of writing bytes as custom_id characters.
Attributes:
-
tag(str) –One character, written ahead of the state, that names the codec on the wire.
-
name(str) –A human-readable name for messages and logs.
-
encode(Callable[[bytes], str]) –Turns bytes into text.
-
decode(Callable[[str], bytes]) –Turns that text back into the same bytes.
-
max_bytes(Callable[[int], int]) –How many bytes fit into a given number of characters.
by_tag
¶
ensure_available
¶
ensure_available(codec: Codec) -> None
Raise CodecUnavailableError if codec needs an extra that is not installed.
Parameters:
-
codec(Codec) –The codec to check.
BASE85always passes.
Raises:
-
CodecUnavailableError–If the codec needs the
[radixly]extra and it is not installed.
register
¶
register(codec: Codec) -> None
Make codec known under its tag, so state written with it can be read back.
Parameters:
-
codec(Codec) –The codec to register, under its one-character
tag.
Raises:
-
ValueError–If a different codec already has the tag.