diff --git a/src/runtime/serde.rs b/src/runtime/serde.rs index 87fd04a704e8c5b9b2318e9bcd1119d73d22798d..c9a4ec1cc7c843c8452e1058dda4d79bab2866d2 100644 --- a/src/runtime/serde.rs +++ b/src/runtime/serde.rs @@ -1,8 +1,5 @@ use crate::common::*; -use crate::runtime::{ - endpoint::{CommMsg, CommMsgContents, Decision, EndpointInfo, Msg, SetupMsg}, - Predicate, -}; +use crate::runtime::*; use byteorder::{BigEndian, ReadBytesExt, WriteBytesExt}; use std::io::{ErrorKind::InvalidData, Read, Write}; @@ -53,6 +50,19 @@ macro_rules! ser_seq { } ///////////////////////////////////////// +impl Ser for W { + fn ser(&mut self, t: &PortId) -> Result<(), std::io::Error> { + self.ser(&t.controller_id)?; + self.ser(&VarLenInt(t.port_index as u64)) + } +} + +impl De for R { + fn de(&mut self) -> Result { + Ok(PortId { controller_id: self.de()?, port_index: De::::de(self)?.0 as u32 }) + } +} + impl Ser for W { fn ser(&mut self, t: &bool) -> Result<(), std::io::Error> { self.ser(&match t { @@ -147,21 +157,6 @@ impl De for R { } } -impl Ser for W { - fn ser(&mut self, t: &ChannelId) -> Result<(), std::io::Error> { - self.ser(&t.controller_id)?; - self.ser(&VarLenInt(t.channel_index as u64)) - } -} -impl De for R { - fn de(&mut self) -> Result { - Ok(ChannelId { - controller_id: self.de()?, - channel_index: De::::de(self)?.0 as ChannelIndex, - }) - } -} - impl Ser for W { fn ser(&mut self, t: &Predicate) -> Result<(), std::io::Error> { self.ser(&VarLenInt(t.assigned.len() as u64))?; @@ -174,7 +169,7 @@ impl Ser for W { impl De for R { fn de(&mut self) -> Result { let VarLenInt(len) = self.de()?; - let mut assigned = BTreeMap::::default(); + let mut assigned = BTreeMap::::default(); for _ in 0..len { assigned.insert(self.de()?, self.de()?); } @@ -221,26 +216,13 @@ impl De for R { }) } } - -impl Ser for W { - fn ser(&mut self, t: &EndpointInfo) -> Result<(), std::io::Error> { - let EndpointInfo { channel_id, polarity } = t; - ser_seq![self, channel_id, polarity] - } -} -impl De for R { - fn de(&mut self) -> Result { - Ok(EndpointInfo { channel_id: self.de()?, polarity: self.de()? }) - } -} - impl Ser for W { fn ser(&mut self, t: &Msg) -> Result<(), std::io::Error> { use {CommMsgContents::*, SetupMsg::*}; match t { Msg::SetupMsg(s) => match s { // [flag, data] - ChannelSetup { info } => ser_seq![self, &0u8, info], + MyPortInfo { polarity, port } => ser_seq![self, &0u8, polarity, port], LeaderEcho { maybe_leader } => ser_seq![self, &1u8, maybe_leader], LeaderAnnounce { leader } => ser_seq![self, &2u8, leader], YouAreMyParent => ser_seq![self, &3u8], @@ -267,7 +249,7 @@ impl De for R { Ok(match b { 0..=3 => Msg::SetupMsg(match b { // [flag, data] - 0u8 => ChannelSetup { info: self.de()? }, + 0u8 => MyPortInfo { polarity: self.de()?, port: self.de()? }, 1u8 => LeaderEcho { maybe_leader: self.de()? }, 2u8 => LeaderAnnounce { leader: self.de()? }, 3u8 => YouAreMyParent,