| 84 | } |
| 85 | |
| 86 | fn prim_v(&self, ty: &str, b: &[u8]) -> RValue { |
| 87 | RValue::Prim(match ty { |
| 88 | "bool" => PValue::bool(b[0] != 0), |
| 89 | "char" => PValue::char( |
| 90 | match char::from_u32(u32::from_ne_bytes(b[..].try_into().unwrap())) { |
| 91 | Some(c) => c, |
| 92 | None => return RValue::Opaque, |
| 93 | }, |
| 94 | ), |
| 95 | "u8" => PValue::u8(u8::from_ne_bytes(b[..].try_into().unwrap())), |
| 96 | "i8" => PValue::i8(i8::from_ne_bytes(b[..].try_into().unwrap())), |
| 97 | "u16" => PValue::u16(u16::from_ne_bytes(b[..].try_into().unwrap())), |
| 98 | "i16" => PValue::i16(i16::from_ne_bytes(b[..].try_into().unwrap())), |
| 99 | "u32" => PValue::u32(u32::from_ne_bytes(b[..].try_into().unwrap())), |
| 100 | "i32" => PValue::i32(i32::from_ne_bytes(b[..].try_into().unwrap())), |
| 101 | "u64" => PValue::u64(u64::from_ne_bytes(b[..].try_into().unwrap())), |
| 102 | "i64" => PValue::i64(i64::from_ne_bytes(b[..].try_into().unwrap())), |
| 103 | "usize" => PValue::usize(match b.len() { |
| 104 | 4 => u32::from_ne_bytes(b[..].try_into().unwrap()) as u64, |
| 105 | 8 => u64::from_ne_bytes(b[..].try_into().unwrap()), |
| 106 | _ => panic!("Not a usize: {b:?}"), |
| 107 | }), |
| 108 | "isize" => PValue::isize(match b.len() { |
| 109 | 4 => i32::from_ne_bytes(b[..].try_into().unwrap()) as i64, |
| 110 | 8 => i64::from_ne_bytes(b[..].try_into().unwrap()), |
| 111 | _ => panic!("Not a isize: {b:?}"), |
| 112 | }), |
| 113 | "u128" => PValue::u128(u128::from_ne_bytes(b[..].try_into().unwrap())), |
| 114 | "i128" => PValue::i128(i128::from_ne_bytes(b[..].try_into().unwrap())), |
| 115 | "f32" => PValue::f32(f32::from_ne_bytes(b[..].try_into().unwrap())), |
| 116 | "f64" => PValue::f64(f64::from_ne_bytes(b[..].try_into().unwrap())), |
| 117 | _ => panic!("unknown ty `{ty}`"), |
| 118 | }) |
| 119 | } |
| 120 | |
| 121 | fn bytes_v(&self, ty: &str, val: Bytes) -> RValue { |
| 122 | RValue::Bytes { |