Separate handling of the files data when encoding pcd
This commit is contained in:
parent
f905d8c6b5
commit
8a95dbffda
20
src/pcd.rs
20
src/pcd.rs
@ -128,6 +128,12 @@ impl AnkPcdHash {
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Serialize, Deserialize)]
|
||||
pub struct FileBlob {
|
||||
r#type: String,
|
||||
data: Vec<u8>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Default, Clone, Serialize, Deserialize, PartialEq, Tsify)]
|
||||
#[tsify(into_wasm_abi, from_wasm_abi)]
|
||||
pub struct Pcd(BTreeMap<String, Vec<u8>>);
|
||||
@ -155,6 +161,20 @@ impl TryFrom<Value> for Pcd {
|
||||
}
|
||||
}
|
||||
|
||||
impl TryFrom<BTreeMap<String, FileBlob>> for Pcd {
|
||||
type Error = Error;
|
||||
|
||||
fn try_from(file_blob_map: BTreeMap<String, FileBlob>) -> Result<Self> {
|
||||
let map: Result<BTreeMap<String, Vec<u8>>> = 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<String, Vec<u8>>) -> Self {
|
||||
Self(map)
|
||||
|
Loading…
x
Reference in New Issue
Block a user