Skip to main content

Module encoding

Module encoding 

Source
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§

encode_checked
Encodes text with 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 text the configured encoding cannot represent, in order of first appearance and without repeats.