Skip to content

Instantly share code, notes, and snippets.

@pratikpc
Created January 13, 2022 15:25
Show Gist options
  • Save pratikpc/346857c7efe938abb15cfb34afcb5ff0 to your computer and use it in GitHub Desktop.
Save pratikpc/346857c7efe938abb15cfb34afcb5ff0 to your computer and use it in GitHub Desktop.
pub fn stringify_buffer(buffer: &IBuffer) -> windows::core::Result<String> {
let buffer_length = buffer.Length()?;
let reader: DataReader = DataReader::FromBuffer(buffer)?;
// Create an array of the correct size
let mut temp: Vec<u8> = vec![0; buffer_length as usize];
// Read bytes into the array
// This now contains our buffer
reader.ReadBytes(temp.as_mut())?;
let string = String::from_utf8(temp).unwrap();
Ok(string)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment