Encode::GSM0338(3)
π NAME π
Encode::GSM0338 β ETSI GSM 03.38 Encoding, bestie. That's the whole vibe of this page (it's from the User Contributed Perl Documentation, iykyk π).
β¨ SYNOPSIS β¨
Okay so here's how you actually use it, no cap:
use Encode qw/encode decode/;
$gsm0338 = encode("gsm0338", $unicode); # loads Encode::GSM0338 implicitly
$unicode = decode("gsm0338", $gsm0338); # ditto
Notice both comments say the module gets loaded implicitly β like it just shows up to the party uninvited but in a slay way π
. And yes, the # ditto is doing the same thing for decode. πΈ
π¦ DESCRIPTION π¦
So GSM0338 is for GSM handsets β phones, basically. It shares alphanumerals with ASCII, which sounds cute and normal, but then the control character ranges and other parts are mapped very differently from ASCII, mainly so it can store Greek characters. Iconic but chaotic.
There are also escape sequences (starting with 0x1B) to cover stuff like the Euro sign. πΆβ¨
Fun lore: this was once handled by Encode::Bytes, but because of all those unusual specifications, Encode 2.20 relocated the support to this module. Glow-up moment, honestly. π
Real talk though: this module implements only GSM 7 bit Default Alphabet and GSM 7 bit default alphabet extension table according to standard 3GPP TS 23.038 version 16. Therefore National Language Single Shift and National Language Locking Shift are not implemented nor supported. Not me giving you the boundary β it's giving healthy communication π«Ά.
π Septets π
This module operates with octets (like any other Encode module) and not with packed septets (unlike other GSM standards). So if you're processing binary SMS or parts of GSM TPDU payload (3GPP TS 23.040), you literally need to do conversion between octets and packed septets yourself. For this purpose perl's pack and unpack functions may be useful:
$bytes = substr(pack('(b*)*', unpack '(A7)*', unpack 'b*', $septets), 0, $num_of_septets);
$unicode = decode('GSM0338', $bytes);
$bytes = encode('GSM0338', $unicode);
$septets = pack 'b*', join '', map { substr $_, 0, 7 } unpack '(A8)*', unpack 'b*', $bytes;
$num_of_septets = length $bytes;
β οΈ Heads up bestie: for correct decoding of packed septets it is required to know the number of septets packed in the binary buffer, because the binary buffer is always padded with zero bits β and 7 zero bits represents the character"@". So a trailing"@"situation is lowkey a trap if you don't track your count. π
Also, number of septets is stored in TPDU payload when dealing with 3GPP TS 23.040. So the info is there, you just gotta read it. π
π BUGS π
Okay so this is the important one. Encode::GSM0338 2.7 and older versions (part of Encode 3.06) incorrectly handled zero bytes (character "@"). This was fixed in Encode::GSM0338 version 2.8 (part of Encode 3.07). So if you're on the old one and your "@" chars are acting sus β that's why. Update and slay. π₯
β SEE ALSO β
- 3GPP TS 23.038
<https://www.3gpp.org/dynareport/23038.htm>β the source material, the blueprint π - ETSI TS 123 038 V16.0.0 (2020-07)
<https://www.etsi.org/deliver/etsi_ts/123000_123099/123038/16.00.00_60/ts_123038v160000p.pdf>β yes she's a PDF, yes she's iconic π Encodeβ the mothership module π§
and that's the page, bestie π written by perl v5.42.0, dated 2024-03-08, mwah π
π¦ where this page comes from
- opensuse-leap 16.0: perl-Encode 3.210.0-bp160.1.12 Β· Artistic-1.0 OR GPL-1.0-or-later
- opensuse-leap 16.0: perl-Encode 3.210.0-bp160.1.12 Β· Artistic-1.0 OR GPL-1.0-or-later
- opensuse-leap 16.0: perl-Encode 3.210.0-bp160.1.12 Β· Artistic-1.0 OR GPL-1.0-or-later
- opensuse-leap 16.0: perl-Encode 3.210.0-bp160.1.12 Β· Artistic-1.0 OR GPL-1.0-or-later
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms