Local function to parse out values from the C mess Assumes the c_value is complete. So cmap::get() will need to check the size and re-get before calling us with a resized buffer
(value_size: usize, c_key_type: u32, c_value: *const u8)
| 543 | // Assumes the c_value is complete. So cmap::get() will need to check the size |
| 544 | // and re-get before calling us with a resized buffer |
| 545 | fn c_to_data(value_size: usize, c_key_type: u32, c_value: *const u8) -> Result<Data> { |
| 546 | unsafe { |
| 547 | match cmap_to_enum(c_key_type) { |
| 548 | DataType::UInt8 => { |
| 549 | let mut ints = [0u8; 1]; |
| 550 | copy_nonoverlapping(c_value as *mut u8, ints.as_mut_ptr(), value_size); |
| 551 | Ok(Data::UInt8(ints[0])) |
| 552 | } |
| 553 | DataType::Int8 => { |
| 554 | let mut ints = [0i8; 1]; |
| 555 | copy_nonoverlapping(c_value as *mut u8, ints.as_mut_ptr() as *mut u8, value_size); |
| 556 | Ok(Data::Int8(ints[0])) |
| 557 | } |
| 558 | DataType::UInt16 => { |
| 559 | let mut ints = [0u16; 1]; |
| 560 | copy_nonoverlapping(c_value as *mut u8, ints.as_mut_ptr() as *mut u8, value_size); |
| 561 | Ok(Data::UInt16(ints[0])) |
| 562 | } |
| 563 | DataType::Int16 => { |
| 564 | let mut ints = [0i16; 1]; |
| 565 | copy_nonoverlapping(c_value as *mut u8, ints.as_mut_ptr() as *mut u8, value_size); |
| 566 | Ok(Data::Int16(ints[0])) |
| 567 | } |
| 568 | DataType::UInt32 => { |
| 569 | let mut ints = [0u32; 1]; |
| 570 | copy_nonoverlapping(c_value as *mut u8, ints.as_mut_ptr() as *mut u8, value_size); |
| 571 | Ok(Data::UInt32(ints[0])) |
| 572 | } |
| 573 | DataType::Int32 => { |
| 574 | let mut ints = [0i32; 1]; |
| 575 | copy_nonoverlapping(c_value as *mut u8, ints.as_mut_ptr() as *mut u8, value_size); |
| 576 | Ok(Data::Int32(ints[0])) |
| 577 | } |
| 578 | DataType::UInt64 => { |
| 579 | let mut ints = [0u64; 1]; |
| 580 | copy_nonoverlapping(c_value as *mut u8, ints.as_mut_ptr() as *mut u8, value_size); |
| 581 | Ok(Data::UInt64(ints[0])) |
| 582 | } |
| 583 | DataType::Int64 => { |
| 584 | let mut ints = [0i64; 1]; |
| 585 | copy_nonoverlapping(c_value as *mut u8, ints.as_mut_ptr() as *mut u8, value_size); |
| 586 | Ok(Data::Int64(ints[0])) |
| 587 | } |
| 588 | DataType::Float => { |
| 589 | let mut ints = [0f32; 1]; |
| 590 | copy_nonoverlapping(c_value as *mut u8, ints.as_mut_ptr() as *mut u8, value_size); |
| 591 | Ok(Data::Float(ints[0])) |
| 592 | } |
| 593 | DataType::Double => { |
| 594 | let mut ints = [0f64; 1]; |
| 595 | copy_nonoverlapping(c_value as *mut u8, ints.as_mut_ptr() as *mut u8, value_size); |
| 596 | Ok(Data::Double(ints[0])) |
| 597 | } |
| 598 | DataType::String => { |
| 599 | let mut ints = vec![0u8; value_size]; |
| 600 | copy_nonoverlapping(c_value as *mut u8, ints.as_mut_ptr(), value_size); |
| 601 | // -1 here so CString doesn't see the NUL |
| 602 | let cs = match CString::new(&ints[0..value_size - 1_usize]) { |
no test coverage detected