vec_to_i_buffer

Function vec_to_i_buffer 

Source
pub fn vec_to_i_buffer(vec: &Vec<u8>) -> Result<IBuffer, Error>
Expand description

Convert Vec<u8> to [IBuffer].

ยงExamples

use windows::Storage::Streams::{DataReader, DataWriter};
use ble_data_struct::windows::buffer::vec_to_i_buffer;

let data = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9].to_vec();
 
let result = vec_to_i_buffer(&data);
assert!(result.is_ok());
 
let i_buffer = result.unwrap();
let reader = DataReader::FromBuffer(&i_buffer).unwrap();
let length = reader.UnconsumedBufferLength().unwrap();
let mut read_buffer = vec![0u8; length as usize];
reader.ReadBytes(read_buffer.as_mut()).unwrap();
assert_eq!(data.to_vec(), read_buffer);