diff --git a/src/pcd.rs b/src/pcd.rs index 0322ed9..1c598b3 100644 --- a/src/pcd.rs +++ b/src/pcd.rs @@ -128,6 +128,12 @@ impl AnkPcdHash { } } +#[derive(Serialize, Deserialize)] +pub struct FileBlob { + r#type: String, + data: Vec, +} + #[derive(Debug, Default, Clone, Serialize, Deserialize, PartialEq, Tsify)] #[tsify(into_wasm_abi, from_wasm_abi)] pub struct Pcd(BTreeMap>); @@ -155,6 +161,20 @@ impl TryFrom for Pcd { } } +impl TryFrom> for Pcd { + type Error = Error; + + fn try_from(file_blob_map: BTreeMap) -> Result { + let map: Result>> = file_blob_map.iter().map(|(key, value)| { + let mut writer = vec![]; + ciborium::into_writer(value, &mut writer)?; + Ok((key.clone(), writer)) + }).collect(); + + Ok(Pcd(map?)) + } +} + impl Pcd { pub fn new(map: BTreeMap>) -> Self { Self(map)