diff options
author | Kostya Shishkov <kostya.shishkov@gmail.com> | 2021-11-12 17:38:28 +0100 |
---|---|---|
committer | Kostya Shishkov <kostya.shishkov@gmail.com> | 2021-11-15 11:57:58 +0100 |
commit | 1ebf572dc8cdbf6e1440d90295b3e69eb76339df (patch) | |
tree | c780ffa3ad89c075f89fd6c6cc0d978b3063b587 /nihav-core/src/frame.rs | |
parent | 77e60c6aab17aa851199fe3d8ab9a93c0e333680 (diff) | |
download | nihav-1ebf572dc8cdbf6e1440d90295b3e69eb76339df.tar.gz |
add interfaces for raw data stream handling
Diffstat (limited to 'nihav-core/src/frame.rs')
-rw-r--r-- | nihav-core/src/frame.rs | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/nihav-core/src/frame.rs b/nihav-core/src/frame.rs index f596dc9..70a054d 100644 --- a/nihav-core/src/frame.rs +++ b/nihav-core/src/frame.rs @@ -1444,6 +1444,37 @@ impl fmt::Display for NAPacket { } } +/// Packet with a piece of data for a raw stream. +pub struct NARawData { + stream: NAStreamRef, + buffer: NABufferRef<Vec<u8>>, +} + +impl NARawData { + /// Constructs a new `NARawData` instance. + pub fn new(stream: NAStreamRef, vec: Vec<u8>) -> Self { + Self { stream, buffer: NABufferRef::new(vec) } + } + /// Constructs a new `NARawData` instance reusing a buffer reference. + pub fn new_from_refbuf(stream: NAStreamRef, buffer: NABufferRef<Vec<u8>>) -> Self { + Self { stream, buffer } + } + /// Returns information about the stream this data belongs to. + pub fn get_stream(&self) -> NAStreamRef { self.stream.clone() } + /// Returns a reference to packet data. + pub fn get_buffer(&self) -> NABufferRef<Vec<u8>> { self.buffer.clone() } + /// Assigns raw data to a new stream. + pub fn reassign(&mut self, stream: NAStreamRef) { + self.stream = stream; + } +} + +impl fmt::Display for NARawData { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + write!(f, "[raw data for {} size {}]", self.stream, self.buffer.len()) + } +} + #[cfg(test)] mod test { use super::*; |