use super::Control; use byteorder::{LittleEndian, WriteBytesExt}; use integer_encoding::VarIntWriter; use std::io::{self, Write}; pub const MAGIC: u32 = 0xB1DF; pub const VERSION: u32 = 0x1000; pub struct Writer where W: Write, { w: W, } impl Writer where W: Write, { pub fn new(mut w: W) -> Result { w.write_u32::(MAGIC)?; w.write_u32::(VERSION)?; Ok(Self { w }) } pub fn write(&mut self, c: &Control) -> Result<(), io::Error> { let w = &mut self.w; w.write_varint(c.add.len())?; w.write_all(c.add)?; w.write_varint(c.copy.len())?; w.write_all(c.copy)?; w.write_varint(c.seek)?; Ok(()) } pub fn flush(&mut self) -> Result<(), io::Error> { self.w.flush() } pub fn into_inner(self) -> W { self.w } }