Ucs2

Struct Ucs2 

Source
pub struct Ucs2 { /* private fields */ }
Available on crate feature encoding only.
Expand description

UCS2 codec.

Implementations§

Source§

impl Ucs2

Source

pub fn encode_to_vec(&self, input: &str) -> Result<Vec<u8>, Ucs2EncodeError>

Available on crate feature alloc only.

Encodes the given message into a vector of bytes.

Source§

impl Ucs2

Source

pub const fn new() -> Self

Creates a new Ucs2 codec.

§Defaults
  • allow_split_character: false
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
Hide additional 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}
Source

pub const fn allow_split_character(&self) -> bool

Returns whether splitting characters is allowed.

Source

pub const fn with_allow_split_character(self, allow: bool) -> Self

Sets whether to allow splitting characters across message parts.

Source

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.
Source§

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>

Available on crate feature concatenation only.
Splits the encoded message into concatenated parts and their associated DataCoding. Read more
Source§

impl Debug for Ucs2

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for Ucs2

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl Encoder for Ucs2

Available on crate feature alloc only.
Source§

type Error = Ucs2EncodeError

The type of errors that can occur during encoding.
Source§

fn encode(&self, message: &str) -> Result<(Vec<u8>, DataCoding), Self::Error>

Encodes the given message into a vector of bytes and its associated DataCoding.

Auto Trait Implementations§

§

impl Freeze for Ucs2

§

impl RefUnwindSafe for Ucs2

§

impl Send for Ucs2

§

impl Sync for Ucs2

§

impl Unpin for Ucs2

§

impl UnwindSafe for Ucs2

Blanket Implementations§

§

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

§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
§

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

§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
§

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

§

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

Mutably borrows from an owned value. Read more
§

impl<T> From<T> for T

§

fn from(t: T) -> T

Returns the argument unchanged.

§

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

§

fn into(self) -> U

Calls U::from(self).

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

§

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

§

type Error = Infallible

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

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

Performs the conversion.
§

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

§

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

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

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

Performs the conversion.