Serialize node id as index (#35)

This commit is contained in:
Daniel Sanchez 2024-11-08 05:40:23 +01:00 committed by GitHub
parent fb1894fb8c
commit 21d648b7ff
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 9 additions and 1 deletions

View File

@ -3,7 +3,7 @@ use std::any::Any;
use serde::Serialize; use serde::Serialize;
use netrunner::{ use netrunner::{
node::NodeId, node::{serialize_node_id_as_index, NodeId},
output_processors::{Record, RecordType, Runtime}, output_processors::{Record, RecordType, Runtime},
settings::SimulationSettings, settings::SimulationSettings,
warding::SimulationState, warding::SimulationState,
@ -11,6 +11,7 @@ use netrunner::{
#[derive(Debug, Clone, Serialize)] #[derive(Debug, Clone, Serialize)]
pub struct MixnodeState { pub struct MixnodeState {
#[serde(serialize_with = "serialize_node_id_as_index")]
pub node_id: NodeId, pub node_id: NodeId,
pub step_id: usize, pub step_id: usize,
pub num_messages_broadcasted: usize, pub num_messages_broadcasted: usize,

View File

@ -189,3 +189,10 @@ impl NodeIdExt for NodeId {
NodeId::new(bytes) 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)
}