Created
November 8, 2023 16:22
-
-
Save tommilligan/1b4bf3c44029383b8892fc83b89ca4b1 to your computer and use it in GitHub Desktop.
Decoding UTF16LE String from Vec<u8>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| extern crate encoding_rs; // 0.8.33 | |
| fn main() { | |
| let data: Vec<u8> = vec![46, 0, 120, 0, 108, 0, 115, 0, 120, 0]; | |
| let mut buffer: String = String::with_capacity(data.len() * 2); | |
| let mut decoder = encoding_rs::UTF_16LE.new_decoder(); | |
| let (coder_result, read, replaced) = decoder.decode_to_string(&data, &mut buffer, true); | |
| assert!(coder_result == encoding_rs::CoderResult::InputEmpty); | |
| println!("String: {}", buffer); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment