pub struct Ucs2 { /* private fields */ }Available on crate feature
encoding only.Expand description
UCS2 codec.
Implementations§
Source§impl Ucs2
impl Ucs2
Sourcepub fn encode_to_vec(&self, input: &str) -> Result<Vec<u8>, Ucs2EncodeError>
Available on crate feature alloc only.
pub fn encode_to_vec(&self, input: &str) -> Result<Vec<u8>, Ucs2EncodeError>
alloc only.Encodes the given message into a vector of bytes.
Source§impl Ucs2
impl Ucs2
Sourcepub const fn new() -> Self
pub const fn new() -> Self
Examples found in repository?
examples/submit_sm_multipart_fallback.rs (line 31)
22fn main() -> Result<(), Box<dyn core::error::Error>> {
23 let multipart = SubmitSm::builder()
24 .source_addr_ton(Ton::Unknown)
25 .source_addr_npi(Npi::Unknown)
26 .source_addr(COctetString::from_str("12345")?)
27 .destination_addr(COctetString::from_str("491701234567")?)
28 .build()
29 .multipart("Hi This message can not be encoded in gsm 7-bit default alphabet so it will fallback to ucs2: 你好")
30 .encoder(Gsm7BitUnpacked::new().with_alphabet(Gsm7BitAlphabet::default()))
31 .fallback(Ucs2::new())
32 .build()?;
33
34 let total = multipart.len();
35
36 println!("Submitting multipart message: total {total}");
37
38 for (i, sm) in multipart.into_iter().enumerate() {
39 assert_eq!(sm.data_coding, Ucs2::new().data_coding());
40
41 println!(
42 "Submitting part {}: short_message_len = {}, esm_class = {:?}, data_coding = {:?}, short_message = {:?}",
43 i + 1,
44 sm.short_message().len(),
45 sm.esm_class,
46 sm.data_coding,
47 sm.short_message()
48 );
49 println!()
50 }
51
52 Ok(())
53}More examples
examples/submit_sm_encode.rs (line 37)
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}Sourcepub const fn allow_split_character(&self) -> bool
pub const fn allow_split_character(&self) -> bool
Returns whether splitting characters is allowed.
Sourcepub const fn with_allow_split_character(self, allow: bool) -> Self
pub const fn with_allow_split_character(self, allow: bool) -> Self
Sets whether to allow splitting characters across message parts.
Sourcepub const fn data_coding(&self) -> DataCoding
pub const fn data_coding(&self) -> DataCoding
Returns the associated DataCoding.
Examples found in repository?
examples/submit_sm_multipart_fallback.rs (line 39)
22fn main() -> Result<(), Box<dyn core::error::Error>> {
23 let multipart = SubmitSm::builder()
24 .source_addr_ton(Ton::Unknown)
25 .source_addr_npi(Npi::Unknown)
26 .source_addr(COctetString::from_str("12345")?)
27 .destination_addr(COctetString::from_str("491701234567")?)
28 .build()
29 .multipart("Hi This message can not be encoded in gsm 7-bit default alphabet so it will fallback to ucs2: 你好")
30 .encoder(Gsm7BitUnpacked::new().with_alphabet(Gsm7BitAlphabet::default()))
31 .fallback(Ucs2::new())
32 .build()?;
33
34 let total = multipart.len();
35
36 println!("Submitting multipart message: total {total}");
37
38 for (i, sm) in multipart.into_iter().enumerate() {
39 assert_eq!(sm.data_coding, Ucs2::new().data_coding());
40
41 println!(
42 "Submitting part {}: short_message_len = {}, esm_class = {:?}, data_coding = {:?}, short_message = {:?}",
43 i + 1,
44 sm.short_message().len(),
45 sm.esm_class,
46 sm.data_coding,
47 sm.short_message()
48 );
49 println!()
50 }
51
52 Ok(())
53}Trait Implementations§
Source§impl Concatenator for Ucs2
Available on crate feature alloc only.
impl Concatenator for Ucs2
Available on crate feature
alloc only.Source§type Error = Ucs2ConcatenateError
type Error = Ucs2ConcatenateError
Available on crate feature
concatenation only.The type of errors that can occur during concatenation.
Source§fn concatenate(
&self,
message: &str,
max_message_size: usize,
part_header_size: usize,
) -> Result<(Concatenation, DataCoding), Self::Error>
fn concatenate( &self, message: &str, max_message_size: usize, part_header_size: usize, ) -> Result<(Concatenation, DataCoding), Self::Error>
Available on crate feature
concatenation only.Splits the encoded message into concatenated parts and their associated
DataCoding. Read moreSource§impl Encoder for Ucs2
Available on crate feature alloc only.
impl Encoder for Ucs2
Available on crate feature
alloc only.Source§type Error = Ucs2EncodeError
type Error = Ucs2EncodeError
The type of errors that can occur during encoding.
Source§fn encode(&self, message: &str) -> Result<(Vec<u8>, DataCoding), Self::Error>
fn encode(&self, message: &str) -> Result<(Vec<u8>, DataCoding), Self::Error>
Encodes the given message into a vector of bytes and its associated
DataCoding.