From e5cac20d5e253e9d5943b0b19fad89114636514f Mon Sep 17 00:00:00 2001 From: Vaibhav Nagarnaik Date: Fri, 8 Oct 2021 16:01:37 -0700 Subject: [PATCH] Fix CIMTYPE `CHAR16` support The `CHAR16` fields are saved as `u16` numbers. Add support for conversion of `u16` into a `String` if the CIMTYPE is `CIM_CHAR16`. --- src/variant.rs | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/variant.rs b/src/variant.rs index 8ee4326..8fd9d9c 100644 --- a/src/variant.rs +++ b/src/variant.rs @@ -63,6 +63,8 @@ macro_rules! cast_num { Ok(Variant::R4($var as f32)) } else if $cim_type == wbemcli::CIM_REAL64 { Ok(Variant::R8($var as f64)) + } else if $cim_type == wbemcli::CIM_CHAR16 { + Ok(Variant::String(String::from_utf16(&[$var as u16])?)) } else { Err(WMIError::ConvertVariantError(format!( "Value {:?} cannot be turned into a CIMTYPE {}", @@ -438,6 +440,14 @@ mod tests { assert_eq!(converted, Variant::R8(1.0)); } + #[test] + fn it_convert_into_cim_char16() { + let cim_type = wbemcli::CIM_CHAR16; + let variant = Variant::UI2(67); + let converted = variant.convert_into_cim_type(cim_type).unwrap(); + assert_eq!(converted, Variant::String("C".to_string())); + } + #[test] fn it_convert_into_cim_type_datetime() { let cim_type = wbemcli::CIM_DATETIME;