Expand description
Global encoding for Rust <-> AMX conversion (only with the encoding feature).
The original SA-MP operates on 8-bit encodings (Western Windows-1252 by
default, Windows-1251 for Cyrillic on Russian servers). This module lets the
plugin configure the encoding once in on_load — after that, AmxString
decodes and Buffer::write_str encodes using it automatically.
set_default_encoding takes any &'static Encoding, so every encoding
encoding_rs implements is available; the ones SA-MP and Open Multiplayer
servers actually run are re-exported here, and
set_default_encoding_by_label resolves one by name for a plugin that
reads it from configuration.
§Multi-byte encodings
Pawn assumes one cell holds one character. That holds for every 8-bit
encoding above, and not for UTF-8, GBK, Big5, Shift_JIS or EUC-KR, where
one character may take several bytes. Converting in and out of Rust stays
correct, but on the Pawn side strlen then counts bytes rather than
characters and text[3] is the fourth byte, not the fourth character. Use a
multi-byte encoding only when the script is written for it.
Statics§
- ISO_
8859_ 2 - The ISO-8859-2 encoding.
- UTF_8
- The UTF-8 encoding.
- WINDOWS_
1250 - The windows-1250 encoding.
- WINDOWS_
1251 - The windows-1251 encoding.
- WINDOWS_
1252 - The windows-1252 encoding.
- WINDOWS_
1253 - The windows-1253 encoding.
- WINDOWS_
1254 - The windows-1254 encoding.
- WINDOWS_
1256 - The windows-1256 encoding.
- WINDOWS_
1257 - The windows-1257 encoding.
Functions§
- current
- The encoding every AMX string conversion currently uses.
- encode_
checked - Encodes
textwith the configured encoding, reporting whether anything was lost on the way. - set_
default_ encoding - Sets the global encoding used in every AMX string conversion.
- set_
default_ encoding_ by_ label - Sets the global encoding from a label, the way a configuration file names it.
- unmappable_
chars - The characters of
textthe configured encoding cannot represent, in order of first appearance and without repeats.