| Crates.io | sms-pdu-decoder |
| lib.rs | sms-pdu-decoder |
| version | 0.1.1 |
| created_at | 2025-11-28 18:46:24.076656+00 |
| updated_at | 2025-11-28 18:52:58.769709+00 |
| description | A Rust library for decoding SMS PDU (Protocol Data Unit) format as specified in GSM 03.40 |
| homepage | |
| repository | https://github.com/fazalrasel/sms-pdu-decoder |
| max_upload_size | |
| id | 1955866 |
| size | 90,905 |
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.
Add this to your Cargo.toml:
[dependencies]
sms-pdu-decoder = "0.1.0"
For quick decoding of incoming SMS messages:
use sms_pdu_decoder::read_incoming_sms;
fn main() {
let pdu = "07916407058099F9040B916407950303F100008921222140140004D4E2940A";
match read_incoming_sms(pdu) {
Ok(sms) => {
println!("From: {}", sms.sender);
println!("Message: {}", sms.content);
println!("Date: {}", sms.date);
}
Err(e) => eprintln!("Error: {}", e),
}
}
For more control and access to all PDU fields:
use sms_pdu_decoder::SmsDeliver;
fn main() {
let pdu = "07916407058099F9040B916407950303F100008921222140140004D4E2940A";
match SmsDeliver::decode(pdu) {
Ok(sms) => {
println!("SMSC: {}", sms.smsc.number.unwrap_or_default());
println!("Sender: {}", sms.sender.number);
println!("Encoding: {}", sms.dcs.encoding);
println!("Timestamp: {}", sms.scts);
println!("Message: {}", sms.user_data.data);
}
Err(e) => eprintln!("Error: {}", e),
}
}
You can also use the codecs directly:
use sms_pdu_decoder::{Gsm7Bit, Ucs2};
fn main() {
// GSM 7-bit decoding
let text = Gsm7Bit::decode("C8F71D14969741F977FD07", false).unwrap();
println!("GSM 7-bit: {}", text); // "How are you?"
// UCS-2 (Unicode) decoding
let text = Ucs2::decode("004C006F00720065006D").unwrap();
println!("UCS-2: {}", text); // "Lorem"
}
Run the included example:
cargo run --example decode_sms
{, }, [, ], €, etc.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 SMSGsm7Bit::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-2Run the test suite:
cargo test
All tests from the original Python implementation are included and passing.
Contributions are welcome! Please feel free to submit a Pull Request.
This project is licensed under the MIT License - see the LICENSE file for details.