SMS PDU Decoder
A Rust library for decoding SMS PDU (Protocol Data Unit) format as specified in GSM 03.40.
This is a Rust port of the Python library smspdudecoder by Sergey Yenchuk.
Features
- 📱 Decode SMS-DELIVER (incoming) messages
- 📤 Decode SMS-SUBMIT (outgoing) messages
- 🔤 Support for GSM 7-bit encoding (including extended characters)
- 🌍 Support for UCS-2 (Unicode) encoding
- 📦 Support for concatenated (multi-part) messages
- ⏰ Timezone-aware timestamp parsing
- 🛡️ Handles truncated PDUs gracefully
Installation
Add this to your Cargo.toml:
[]
= "0.1.0"
Usage
Simple API
For quick decoding of incoming SMS messages:
use read_incoming_sms;
Detailed API
For more control and access to all PDU fields:
use SmsDeliver;
Direct Codec Usage
You can also use the codecs directly:
use ;
Examples
Run the included example:
Supported Encodings
- GSM 7-bit: Default SMS encoding, supports basic Latin alphabet and some special characters
- GSM 7-bit Extended: Includes additional characters like
{,},[,],€, etc. - UCS-2: Unicode encoding for international characters
- 8-bit/Binary: Raw binary data
API Documentation
Main Functions
read_incoming_sms(pdu: &str)- Simple API for decoding incoming SMSread_outgoing_sms(pdu: &str)- Simple API for decoding outgoing SMSSmsDeliver::decode(pdu: &str)- Detailed API for incoming SMSSmsSubmit::decode(pdu: &str)- Detailed API for outgoing SMS
Codecs
Gsm7Bit::decode(data: &str, strip_padding: bool)- Decode GSM 7-bit encoded textGsm7Bit::encode(data: &str, with_padding: bool)- Encode text to GSM 7-bitUcs2::decode(data: &str)- Decode UCS-2 (UTF-16BE) encoded textUcs2::encode(data: &str)- Encode text to UCS-2
Testing
Run the test suite:
All tests from the original Python implementation are included and passing.
Contributing
Contributions are welcome! Please feel free to submit a Pull Request.
Acknowledgments
- Original Python implementation: smspdudecoder by Sergey Yenchuk
- This Rust port was developed with assistance from Kiro AI
License
This project is licensed under the MIT License - see the LICENSE file for details.
References
Changelog
0.1.0 (2024)
- Initial release
- Full support for SMS-DELIVER and SMS-SUBMIT PDU decoding
- GSM 7-bit and UCS-2 encoding support
- Concatenated message support
- Timezone-aware timestamp parsing