diff options
author | Jesse Luehrs <doy@tozt.net> | 2019-10-27 08:07:09 -0400 |
---|---|---|
committer | Jesse Luehrs <doy@tozt.net> | 2019-10-27 08:07:09 -0400 |
commit | 17fc6b3eda370f99fee48420532ada8b497ecd8c (patch) | |
tree | cf8067dc80e700bf3056e22e86942e13e4fd3795 /src/parser.rs | |
parent | 9739318498f8b78788923986d77a7b436d6af12a (diff) | |
download | ttyrec-17fc6b3eda370f99fee48420532ada8b497ecd8c.tar.gz ttyrec-17fc6b3eda370f99fee48420532ada8b497ecd8c.zip |
docs
Diffstat (limited to 'src/parser.rs')
-rw-r--r-- | src/parser.rs | 14 |
1 files changed, 14 insertions, 0 deletions
diff --git a/src/parser.rs b/src/parser.rs index d3c3861..a473931 100644 --- a/src/parser.rs +++ b/src/parser.rs @@ -18,6 +18,13 @@ impl Header { } } +/// Parses ttyrec streams. +/// +/// Designed to be able to be used in a streaming/asynchronous fashion. As you +/// read bytes from the ttyrec stream (whether from a file or whatever else), +/// call the `add_bytes` method to add them to the internal buffer. At any +/// point, you can call `next_frame` to then return the next complete frame if +/// one has been read. #[derive(Debug, Clone)] pub struct Parser { reading: std::collections::VecDeque<u8>, @@ -25,14 +32,21 @@ pub struct Parser { } impl Parser { + /// Create a new `Parser`. pub fn new() -> Self { Default::default() } + /// Add more bytes to the internal buffer. pub fn add_bytes(&mut self, bytes: &[u8]) { self.reading.extend(bytes.iter()); } + /// Try to read a frame from the internal buffer. + /// + /// If a complete frame is found, the bytes for that frame will be removed + /// from the internal buffer and the frame object will be returned. If a + /// complete frame is not found, this method will return `None`. pub fn next_frame(&mut self) -> Option<crate::frame::Frame> { let header = if let Some(header) = &self.read_state { header |