Skip to main content

MessageSplitter

Struct MessageSplitter 

Source
pub struct MessageSplitter;

Implementations§

Source§

impl MessageSplitter

Source

pub fn split( text: String, encoding: EncodingType, mode: SplitMode, ) -> Result<(Vec<Vec<u8>>, u8), String>

Split a long message into multiple chunks.

Returns a tuple of (Chunks, DataCoding).

  • For SplitMode::Udh, chunks include the User Data Header.
  • For SplitMode::Sar, chunks are raw payload; caller must add SAR TLVs.
  • For SplitMode::Payload, returns a single chunk (no splitting).
Examples found in repository?
examples/submit_sm.rs (line 12)
3fn main() {
4    println!("=== SMPP Submit SM Example (with Splitter) ===");
5
6    let text = "This is a very long message that will need to be split into multiple parts because it exceeds the standard SMS length limit of 160 characters for GSM 7-bit encoding. The MessageSplitter utility handles this automatically.".to_string();
7
8    println!("Original Text Length: {}", text.len());
9
10    // 1. Split message (handles encoding and valid chunking with UDH)
11    let (parts, data_coding) =
12        MessageSplitter::split(text, EncodingType::Gsm7Bit, SplitMode::Udh).unwrap();
13
14    println!("Split into {} parts using UDH concatenation.", parts.len());
15    let parts_len = parts.len();
16
17    // 2. Iterate over parts and create/encode PDUs
18    for (i, part) in parts.into_iter().enumerate() {
19        let sequence_number = (i + 1) as u32;
20        let mut submit_req = SubmitSmRequest::new(
21            sequence_number,
22            "source_addr".to_string(),
23            "dest_addr".to_string(),
24            part,
25        );
26        submit_req.data_coding = data_coding;
27
28        // If UDH is present, set the UDHI bit (0x40) in esm_class
29        if parts_len > 1 {
30            submit_req.esm_class |= 0x40;
31        }
32
33        let mut buffer = Vec::new();
34        submit_req.encode(&mut buffer).unwrap();
35
36        println!(
37            "Part {}: Sequence {}, Encoded {} bytes",
38            i + 1,
39            sequence_number,
40            buffer.len()
41        );
42    }
43}
More examples
Hide additional examples
examples/deliver_sm.rs (line 13)
3fn main() {
4    println!("=== SMPP Deliver SM Example (Incoming Message) ===");
5
6    // Simulate a long incoming message content
7    let text = "This is a simulated long incoming message that behaves exactly like SubmitSM. The MessageSplitter is used to chunk it, and the DeliverSmRequest struct is used to represent each chunk sent to the ESME.".to_string();
8
9    println!("Incoming Text Length: {}", text.len());
10
11    // 1. Split message
12    let (parts, data_coding) =
13        MessageSplitter::split(text, EncodingType::Gsm7Bit, SplitMode::Udh).unwrap();
14
15    println!("Split into {} parts.", parts.len());
16    let parts_len = parts.len();
17
18    // 2. Create DeliverSm PDUs for each part
19    for (i, part) in parts.into_iter().enumerate() {
20        let sequence_number = (i + 100) as u32;
21        let mut deliver_req = DeliverSmRequest::new(
22            sequence_number,
23            "sender_number".to_string(),
24            "my_shortcode".to_string(),
25            part,
26        );
27        deliver_req.data_coding = data_coding;
28
29        // CRITICAL: Set UDHI bit (0x40) in esm_class if UDH is present (parts > 1)
30        if parts_len > 1 {
31            deliver_req.esm_class |= 0x40;
32        }
33
34        let mut buffer = Vec::new();
35        deliver_req.encode(&mut buffer).unwrap();
36
37        println!(
38            "Part {}: Sequence {}, Encoded {} bytes. UDHI bit set: {}",
39            i + 1,
40            sequence_number,
41            buffer.len(),
42            (deliver_req.esm_class & 0x40) != 0
43        );
44    }
45}

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V