diff --git a/simlib/mixnet-sims/src/node/mix/state.rs b/simlib/mixnet-sims/src/node/mix/state.rs index ced1420..e075344 100644 --- a/simlib/mixnet-sims/src/node/mix/state.rs +++ b/simlib/mixnet-sims/src/node/mix/state.rs @@ -3,7 +3,7 @@ use std::any::Any; use serde::Serialize; use netrunner::{ - node::NodeId, + node::{serialize_node_id_as_index, NodeId}, output_processors::{Record, RecordType, Runtime}, settings::SimulationSettings, warding::SimulationState, @@ -11,6 +11,7 @@ use netrunner::{ #[derive(Debug, Clone, Serialize)] pub struct MixnodeState { + #[serde(serialize_with = "serialize_node_id_as_index")] pub node_id: NodeId, pub step_id: usize, pub num_messages_broadcasted: usize, diff --git a/simlib/netrunner/src/node/mod.rs b/simlib/netrunner/src/node/mod.rs index 2de43cd..c5b1c0e 100644 --- a/simlib/netrunner/src/node/mod.rs +++ b/simlib/netrunner/src/node/mod.rs @@ -189,3 +189,10 @@ impl NodeIdExt for NodeId { NodeId::new(bytes) } } + +pub fn serialize_node_id_as_index(id: &NodeId, s: S) -> Result +where + S: serde::Serializer, +{ + s.serialize_u64(id.index() as u64) +}