chiark / gitweb /
packetframe: Provide methods for (partial) disassembly
authorIan Jackson <ijackson@chiark.greenend.org.uk>
Sun, 30 May 2021 20:19:36 +0000 (21:19 +0100)
committerIan Jackson <ijackson@chiark.greenend.org.uk>
Mon, 31 May 2021 21:16:45 +0000 (22:16 +0100)
Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
src/packetframe.rs

index 654f7d4b554a2b24e2efd65b3109d3dd2e2a1cdd..28fc540022af0b7b7a650cb133f8dd410fdc5b15 100644 (file)
@@ -202,6 +202,12 @@ impl<R:Read> FrameReader<R> {
     Some(ReadFrame { fr: self })
   }
 
+  #[throws(io::Error)]
+  pub fn into_stream(mut self) -> BufReader<Fuse<R>> {
+    self.finish_reading_frame()?;
+    self.inner
+  }
+
   #[throws(io::Error)]
   fn finish_reading_frame(&mut self) {
     while matches_doesnot!(
@@ -357,6 +363,12 @@ impl<W:Write> FrameWriter<W> {
     FrameWriter { inner: Fuse::new(w), in_frame: None }
   }
 
+  #[throws(io::Error)]
+  pub fn into_stream(mut self) -> Fuse<W> {
+    self.tidy()?;
+    self.inner
+  }
+
   #[throws(io::Error)]
   pub fn new_frame<'w>(&'w mut self) -> WriteFrame<'w,W> {
     self.tidy()?;