From 076d6e0915ab6a46f76bc343a6be4b2b67068917 Mon Sep 17 00:00:00 2001 From: Jake Probst Date: Tue, 20 Aug 2019 10:59:32 -0700 Subject: [PATCH] pktvec --- src/common/mod.rs | 3 ++ src/common/pktvec.rs | 90 ++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 93 insertions(+) create mode 100644 src/common/pktvec.rs diff --git a/src/common/mod.rs b/src/common/mod.rs index 29ec690..781e7a0 100644 --- a/src/common/mod.rs +++ b/src/common/mod.rs @@ -1,3 +1,6 @@ +#[macro_use] +pub mod pktvec; + pub mod cipherkeys; pub mod network; pub mod serverstate; diff --git a/src/common/pktvec.rs b/src/common/pktvec.rs new file mode 100644 index 0000000..bdb20fb --- /dev/null +++ b/src/common/pktvec.rs @@ -0,0 +1,90 @@ +use std::collections::VecDeque; +use libpso::PSOPacket; + +pub struct PktVec { + pkts: VecDeque>, +} + +impl PktVec { + pub fn new() -> PktVec { + PktVec { + pkts: VecDeque::new(), + } + } + + pub fn push(&mut self, pkt: Box) { + self.pkts.push_back(pkt); + } + + pub fn append(&mut self, pkts: Vec>) { + self.pkts.append(&mut VecDeque::from(pkts)); + } + /*pub fn append(&mut self, pkts: &mut Vec>) { + self.pkts.append(&mut pkts.into()); + }*/ +} + + +impl Iterator for PktVec { + type Item = Box; + + fn next(&mut self) -> Option { + /*if self.index < self.pkts.len() { + let pkt = Some(self.pkts[self.index]); + self.index += 1; + pkt + } + else { + None + }*/ + self.pkts.pop_front() + } +} + +#[macro_export] +macro_rules! pktvec { + ( $( $pkt:expr ),* ) => { + { + let mut pkts = Box::new(PktVec::new()); + $( + pkts.push(Box::new($pkt)); + )* + pkts + } + }; +} + +/* +struct PktVecIter { + iter: Box>>, +} + +impl Iterator for PktVecIter { + type Item = Box; + + fn next(&mut self) -> Option { + self.iter.next() + } +} + + + + + +struct PktVec { + pkts: Vec> +} + +impl PktVec { + fn push(&mut self, pkt: impl PSOPacket) { + self.pkts.push(Box::new(pkt)) + } + + fn iter(&self) -> PktVecIter { + PktVecIter { + iter: self.pkts.iter() + } + } +} + +*/