From 3701a0c57ce0d2ac9227275c7eeb755a1485f9dc Mon Sep 17 00:00:00 2001 From: Ian Jackson Date: Sun, 22 Aug 2021 16:46:14 +0100 Subject: [PATCH] rename methods etc. Signed-off-by: Ian Jackson --- client/client.rs | 2 +- src/queue.rs | 25 ++++++++++++------------- 2 files changed, 13 insertions(+), 14 deletions(-) diff --git a/client/client.rs b/client/client.rs index cd87c8a..887645d 100644 --- a/client/client.rs +++ b/client/client.rs @@ -281,7 +281,7 @@ async fn run_client( if addr != ic.link.client.0 { throw!(PE::Dst(addr)) } Ok(()) }, - |(o,())| future::ready(Ok({ rx_queue.push(o); })), + |(o,())| future::ready(Ok({ rx_queue.push_esc(o); })), |e| Ok::<_,SlipFramesError>( { error!("{} #{}: rx discarding: {}", &ic, req_num, e); })).await diff --git a/src/queue.rs b/src/queue.rs index 5e22de9..f32a472 100644 --- a/src/queue.rs +++ b/src/queue.rs @@ -53,7 +53,7 @@ impl QueueBuf where E: AsRef<[u8]> { pub fn push>(&mut self, b: B) { self.push_(b.into()); } - pub fn push_(&mut self, b: E) { + fn push_(&mut self, b: E) { let l = b.as_ref().len(); self.queue.push_back(b); self.content += l; @@ -63,25 +63,24 @@ impl QueueBuf where E: AsRef<[u8]> { } impl FrameQueueBuf { - pub fn push>>(&mut self, b: B) { - self.push_(b.into()); + pub fn push_esc>>(&mut self, b: B) { + self.push_esc_(b.into()); } - pub fn push_(&mut self, b: Box<[u8]>) { + fn push_esc_(&mut self, b: Box<[u8]>) { self.queue.push_(Cervine::Owned(b)); self.queue.push_(Cervine::Borrowed(&SLIP_END_SLICE)); } + pub fn esc_push(&mut self, b: Box<[u8]>) { + self.queue.push_(Cervine::Borrowed(&SLIP_END_SLICE)); + self.queue.push_(Cervine::Owned(b)); + } + pub fn push_raw(&mut self, b: Box<[u8]>) { + self.queue.push_(Cervine::Owned(b)); + } pub fn is_empty(&self) -> bool { self.queue.is_empty() } pub fn len(&self) -> usize { self.queue.len() } } -impl Extend for FrameQueueBuf where E: Into> { - fn extend(&mut self, it: I) - where I: IntoIterator - { - for b in it { self.push(b) } - } -} - impl hyper::body::Buf for QueueBuf where E: AsRef<[u8]> { fn remaining(&self) -> usize { self.content } fn chunk(&self) -> &[u8] { @@ -119,7 +118,7 @@ impl BufBody { pub fn display(s: S) -> Self { let s = s.to_string().into_bytes(); let mut buf: FrameQueueBuf = default(); - buf.push(s); + buf.push_raw(s.into()); Self::new(buf) } } -- 2.30.2