( buf: &mut &[u8], ixon_env: &super::env::Env, )
| 458 | } |
| 459 | |
| 460 | /// Data values for KVMap metadata. |
| 461 | #[derive(Clone, Debug, PartialEq, Eq, Hash)] |
| 462 | pub enum DataValue { |
| 463 | OfString(Address), |
| 464 | OfBool(bool), |
| 465 | OfName(Address), |
| 466 | OfNat(Address), |
| 467 | OfInt(Address), |
| 468 | OfSyntax(Address), |
| 469 | } |
| 470 | |
| 471 | /// Resolve an Ixon KVMap (address-based) to Lean-level MData (name/value pairs). |
| 472 | /// |
| 473 | /// Used by kernel ingress to convert expression metadata from the |
| 474 | /// content-addressed Ixon representation to the named kernel representation. |
| 475 | pub fn resolve_kvmap( |
| 476 | kvm: &KVMap, |
| 477 | ixon_env: &super::env::Env, |
| 478 | ) -> Vec<(Name, env::DataValue)> { |
| 479 | kvm |
| 480 | .iter() |
| 481 | .filter_map(|(addr, dv)| { |
| 482 | let name = ixon_env.get_name(addr)?; |
| 483 | let resolved = match dv { |
| 484 | DataValue::OfString(a) => { |
| 485 | let bytes = ixon_env.get_blob(a)?; |
| 486 | env::DataValue::OfString(String::from_utf8(bytes).ok()?) |
| 487 | }, |
| 488 | DataValue::OfBool(b) => env::DataValue::OfBool(*b), |
| 489 | DataValue::OfName(a) => { |
| 490 | let n = ixon_env.get_name(a)?; |
| 491 | env::DataValue::OfName(n) |
| 492 | }, |
| 493 | DataValue::OfNat(a) => { |
| 494 | let bytes = ixon_env.get_blob(a)?; |
| 495 | env::DataValue::OfNat(bignat::Nat::from_le_bytes(&bytes)) |
| 496 | }, |
| 497 | DataValue::OfInt(a) => { |
| 498 | let bytes = ixon_env.get_blob(a)?; |
no test coverage detected