submit_sm_encode/
submit_sm_encode.rs

1//! Run with
2//!
3//! ```not_rust
4//! cargo run -p rusmpp-extra --example submit_sm_encode --features="alloc,concatenation"
5//! ```
6
7use std::str::FromStr;
8
9use rusmpp_core::{
10    pdus::owned::SubmitSm,
11    types::owned::{COctetString, OctetString},
12    values::{DataCoding, Npi, Ton},
13};
14use rusmpp_extra::encoding::{owned::EncodedSubmitSmExt, ucs2::Ucs2};
15
16fn main() -> Result<(), Box<dyn core::error::Error>> {
17    // c-spell: disable
18    let message = r##"Hello world!
19
20@£$¥èéùìòÇØøÅåΔ_ΦΓΛΩΠΨΣΘΞÆæßÉ !"#¤%&'()*+,-./0123456789:;<=>?¡ABCDEFGHIJKLMNOPQRSTUVWXYZÄÖÑܧ¿abcdefghijklmnopqrstuvwxyzäöñüà
21
22^{}\[~]|€"##;
23    // c-spell: enable
24
25    let sm = SubmitSm::builder()
26        .source_addr_ton(Ton::Unknown)
27        .source_addr_npi(Npi::Unknown)
28        .source_addr(COctetString::from_str("12345")?)
29        .destination_addr(COctetString::from_str("491701234567")?)
30        // data_coding will be overridden by the encoding builder to match the encoder.
31        .data_coding(DataCoding::default())
32        // short_message will be overridden by `short_message` of the encoding builder.
33        .short_message(OctetString::from_str("Hi, I am a short message.")?)
34        .build()
35        .encode(message)
36        .gsm7bit_unpacked()
37        .fallback(Ucs2::new())
38        .build()?;
39
40    println!(
41        "Encoded: short_message_len = {}, data_coding = {:?}, short_message = {:?}",
42        sm.short_message().len(),
43        sm.data_coding,
44        sm.short_message()
45    );
46
47    Ok(())
48}