Skip to content

Commit

Permalink
feat(s2n-quic-core): Add ability to create an incremental reader init…
Browse files Browse the repository at this point in the history
…ialized with an offset (#2184)

* feat(s2n-quic-core): Add ability to create an incremental reader initialized with an offset

* add to test
  • Loading branch information
WesleyRosenblum committed Apr 18, 2024
1 parent 23b07e4 commit bfb921d
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion quic/s2n-quic-core/src/buffer/reader/incremental.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ use crate::{

/// Implements an incremental [`Reader`] that joins to temporary [`Storage`] as the stream data
///
/// This is useful for scenarios where the the stream isn't completely buffered in memory and
/// This is useful for scenarios where the stream isn't completely buffered in memory and
/// data come in gradually.
#[derive(Debug, Default)]
pub struct Incremental {
Expand All @@ -21,6 +21,14 @@ pub struct Incremental {
}

impl Incremental {
#[inline]
pub fn new(current_offset: VarInt) -> Self {
Self {
current_offset,
final_offset: None,
}
}

#[inline]
pub fn with_storage<'a, C: Storage>(
&'a mut self,
Expand Down Expand Up @@ -172,5 +180,8 @@ mod tests {
assert!(reader.buffer_is_empty());
assert!(reader.is_consumed());
}

let incremental = Incremental::new(VarInt::from_u8(100));
assert_eq!(incremental.current_offset(), VarInt::from_u8(100));
}
}

0 comments on commit bfb921d

Please sign in to comment.