Serialize node id as index

This commit is contained in:
Daniel Sanchez Quiros 2024-11-08 11:28:47 +07:00
parent 3d1bd0dc18
commit 85829519f7
2 changed files with 9 additions and 1 deletions

View File

@ -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,

View File

@ -189,3 +189,10 @@ impl NodeIdExt for NodeId {
NodeId::new(bytes)
}
}
pub fn serialize_node_id_as_index<S>(id: &NodeId, s: S) -> Result<S::Ok, S::Error>
where
S: serde::Serializer,
{
s.serialize_u64(id.index() as u64)
}