Skip to content

Commit

Permalink
Fix serialization
Browse files Browse the repository at this point in the history
  • Loading branch information
JulianGCalderon committed Sep 19, 2024
1 parent 6991904 commit deab241
Showing 1 changed file with 25 additions and 0 deletions.
25 changes: 25 additions & 0 deletions vm/src/air_private_input.rs
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,8 @@ pub struct ModInputInstance {
pub values_ptr: usize,
pub offsets_ptr: usize,
pub n: usize,
#[serde(deserialize_with = "mod_input_instance_batch_serde::deserialize")]
#[serde(serialize_with = "mod_input_instance_batch_serde::serialize")]
pub batch: BTreeMap<usize, ModInputMemoryVars>,
}

Expand Down Expand Up @@ -205,6 +207,29 @@ impl AirPrivateInputSerializable {
}
}

mod mod_input_instance_batch_serde {
use super::*;

use serde::{Deserializer, Serializer};

pub(crate) fn serialize<S: Serializer>(
value: &BTreeMap<usize, ModInputMemoryVars>,
s: S,
) -> Result<S::Ok, S::Error> {
let value = value.iter().map(|v| v.1).collect::<Vec<_>>();

value.serialize(s)
}

pub(crate) fn deserialize<'de, D: Deserializer<'de>>(
d: D,
) -> Result<BTreeMap<usize, ModInputMemoryVars>, D::Error> {
let value = Vec::<ModInputMemoryVars>::deserialize(d)?;

Ok(value.into_iter().enumerate().collect())
}
}

#[cfg(test)]
mod tests {
use crate::types::layout_name::LayoutName;
Expand Down

0 comments on commit deab241

Please sign in to comment.