rdp/model/
unicode.rs

1use model::data::{Message, U16};
2use std::io::Cursor;
3
4/// Use to to_unicode function for String
5pub trait Unicode {
6    fn to_unicode(&self) -> Vec<u8>;
7}
8
9impl Unicode for String {
10    /// Convert any string into utf-16le string
11    ///
12    /// # Example
13    /// ```
14    /// use rdp::model::unicode::Unicode;
15    /// let s = "foo".to_string();
16    /// assert_eq!(s.to_unicode(), [102, 0, 111, 0, 111, 0])
17    /// ```
18    fn to_unicode(&self) -> Vec<u8> {
19        let mut result = Cursor::new(Vec::new());
20        for c in self.encode_utf16() {
21            let encode_char = U16::LE(c);
22            encode_char.write(&mut result).unwrap();
23        }
24        return result.into_inner()
25    }
26}