Use PcdSerializable in TryFrom impl for Pcd

This commit is contained in:
Sosthene 2025-06-24 17:11:21 +02:00
parent 14603debb2
commit e0bc9e9036

View File

@ -234,9 +234,10 @@ impl TryFrom<Value> for Pcd {
fn try_from(value: Value) -> Result<Self> {
let as_object = value.as_object().ok_or_else(|| Error::msg("Pcd must be an object"))?;
let map: Result<BTreeMap<String, Vec<u8>>> = as_object.iter().map(|(key, value)| {
let serialized = crate::serialization::ciborium_serialize(value)?;
Ok((key.clone(), serialized))
let map: Result<BTreeMap<String, Vec<u8>>> = as_object.into_iter().map(|(key, value)| {
// Use the trait method instead of manual serialization
let compressed = value.serialize_to_pcd()?;
Ok((key.clone(), compressed))
}).collect();
Ok(Pcd(map?))
@ -247,9 +248,10 @@ 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 serialized = crate::serialization::ciborium_serialize(value)?;
Ok((key.clone(), serialized))
let map: Result<BTreeMap<String, Vec<u8>>> = file_blob_map.into_iter().map(|(key, value)| {
// Use the trait method instead of manual serialization
let compressed = value.serialize_to_pcd()?;
Ok((key, compressed))
}).collect();
Ok(Pcd(map?))