Crates.io | message_segment_calculator |
lib.rs | message_segment_calculator |
version | 0.1.1 |
source | src |
created_at | 2024-09-02 16:10:16.081149 |
updated_at | 2024-09-02 16:50:58.385836 |
description | Utility package to calculate SMS message segments. |
homepage | |
repository | https://github.com/trozzelle/rust-message-segment-calculator |
max_upload_size | |
id | 1360741 |
size | 61,047 |
A Rust implementation of Twilio's Message Segment Calculator, originally written in JavaScript.
This library provides functionality to segment SMS messages, detect their character set, encoding, and other properties. It's particularly useful for applications that need to work with SMS messages at a low level, ensuring proper encoding and segmentation for delivery.
Add the following to your Cargo.toml
:
[dependencies]
message_segment_calculator = "0.1.0"
Here's a basic example of how to use the library:
use message_segment_calculator::{SegmentedMessage, Encoding};
fn main() {
let message = "Hello, world! 👋";
let encoding = Encoding::Auto;
let smart_encoding = true;
match SegmentedMessage::new(message, encoding, smart_encoding) {
Ok(segmented_message) => {
println!("Encoding: {:?}", segmented_message.get_encoding_name());
println!("Number of segments: {}", segmented_message.segments_count());
println!("Total size in bits: {}", segmented_message.total_size());
}
Err(e) => println!("Error: {}", e),
}
}
The main struct is SegmentedMessage
. Here are some of its key methods:
new(message: &str, encoding: Encoding, smart_encoding: bool) -> Result<SegmentedMessage, String>
get_encoding_name() -> Encoding
total_size() -> u16
message_size() -> u16
segments_count() -> usize
get_non_gsm_characters() -> HashSet<String>
The other structs are exposed and can be used for their specific operations.
A simple CLI tool is included and can be accessed with cargo run -- "Message
. It will print out the statistics for a
given string.
Contributions are welcome! Please feel free to submit a Pull Request.
This project is licensed under the MIT License - see the LICENSE.md file for details.