Skip to content

Commit 8d6e993

Browse files
Might as well use a buffered writer too.
1 parent 67fe65a commit 8d6e993

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

src/slip.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@ const ESC: u8 = 0xDB;
55
const ESC_END: u8 = 0xDC;
66
const ESC_ESC: u8 = 0xDD;
77

8-
pub fn encode_frame(buf: &[u8], mut writer: impl Write) -> io::Result<()> {
8+
pub fn encode_frame(buf: &[u8], writer: impl Write) -> io::Result<()> {
9+
let mut writer = std::io::BufWriter::new(writer);
910
for &byte in buf {
1011
match byte {
1112
END => writer.write_all(&[ESC, ESC_END])?,
@@ -15,6 +16,7 @@ pub fn encode_frame(buf: &[u8], mut writer: impl Write) -> io::Result<()> {
1516
}
1617

1718
writer.write_all(&[END])?;
19+
writer.flush()?;
1820

1921
Ok(())
2022
}

0 commit comments

Comments
 (0)