mirror of
https://github.com/nestriness/nestri.git
synced 2026-11-03 22:22:39 +02:00
feat: let a frame reader hand back what it read past a frame
The end that reads the first frame of an attach stream to learn whom the connection is for then forwards the rest untouched, and what arrived behind that frame in the same read belongs to the stream. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Sonnet 5.5
parent
d0ec87a139
commit
86249001db
@@ -135,6 +135,15 @@ impl FrameReader {
|
||||
self.buf.extend_from_slice(bytes);
|
||||
}
|
||||
|
||||
/// What has arrived and is not yet a frame, handing the reader up.
|
||||
///
|
||||
/// For the end that reads the first frame to learn whom a connection is for
|
||||
/// and then forwards the rest untouched: whatever came in behind that frame
|
||||
/// in the same read belongs to the stream, and is not to be lost.
|
||||
pub fn into_remaining(self) -> Vec<u8> {
|
||||
self.buf
|
||||
}
|
||||
|
||||
/// The next whole frame, if one has arrived.
|
||||
///
|
||||
/// `Ok(None)` is "not yet". After an error the reader is poisoned in the
|
||||
@@ -256,6 +265,19 @@ mod tests {
|
||||
}
|
||||
}
|
||||
|
||||
/// The first frame is read to learn who is calling; whatever came in behind it
|
||||
/// in the same read is the stream's, and is not dropped.
|
||||
#[test]
|
||||
fn what_arrived_behind_a_frame_is_handed_on() {
|
||||
let mut reader = FrameReader::new();
|
||||
let mut wire = Frame::Hello("a".into()).encode().unwrap();
|
||||
wire.extend(Frame::Data(b"prompt$ ".to_vec()).encode().unwrap());
|
||||
reader.push(&wire);
|
||||
assert_eq!(reader.next_frame().unwrap(), Some(Frame::Hello("a".into())));
|
||||
let rest = reader.into_remaining();
|
||||
assert_eq!(rest, Frame::Data(b"prompt$ ".to_vec()).encode().unwrap());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn two_frames_in_one_read_come_out_as_two() {
|
||||
let mut reader = FrameReader::new();
|
||||
|
||||
Reference in New Issue
Block a user