This reverts commit a862d22aaadbd1f096400d4bcd06bc5c1ce17425.
Showing the changes to git-protocol/src (2 of 3 files). Show all
Unified · Split
| @@ -1,6 +1,6 @@ | ||
| 1 | 1 | pub(crate) const U16_HEX_BYTES: usize = 4; |
| 2 | 2 | pub(crate) const MAX_DATA_LEN: usize = 65516; |
| 3 | −pub const MAX_LINE_LEN: usize = MAX_DATA_LEN + U16_HEX_BYTES; | |
| 3 | +pub(crate) const MAX_LINE_LEN: usize = MAX_DATA_LEN + U16_HEX_BYTES; | |
| 4 | 4 | pub(crate) const FLUSH_LINE: &[u8] = b"0000"; |
| 5 | 5 | pub(crate) const DELIMITER_LINE: &[u8] = b"0001"; |
| 6 | 6 | pub(crate) const RESPONSE_END_LINE: &[u8] = b"0002"; |
| @@ -5,20 +5,20 @@ use std::io; · 4 unmodified lines | ||
| 5 | 5 | /// Read pack lines one after another, without consuming more than needed from the underlying |
| 6 | 6 | /// `Read`. `Flush` lines cause the reader to stop producing lines forever, leaver `Read` at the |
| 7 | 7 | /// start of whatever comes next. |
| 8 | −pub struct Reader<'a, T> { | |
| 8 | +pub struct Reader<T> { | |
| 9 | 9 | pub inner: T, |
| 10 | − buf: &'a mut [u8; MAX_LINE_LEN], | |
| 10 | + buf: Vec<u8>, | |
| 11 | 11 | is_done: bool, |
| 12 | 12 | } |
| 13 | 13 | |
| 14 | −impl<'a, T> Reader<'a, T> | |
| 14 | +impl<T> Reader<T> | |
| 15 | 15 | where |
| 16 | 16 | T: io::Read, |
| 17 | 17 | { |
| 18 | − pub fn new(inner: T, buf: &'a mut [u8; MAX_LINE_LEN]) -> Self { | |
| 18 | + pub fn new(inner: T) -> Self { | |
| 19 | 19 | Reader { |
| 20 | 20 | inner, |
| 21 | − buf, | |
| 21 | + buf: vec![0; MAX_LINE_LEN], | |
| 22 | 22 | is_done: false, |
| 23 | 23 | } |
| 24 | 24 | } |
| @@ -28,7 +28,7 @@ where · 3 unmodified lines | ||
| 28 | 28 | self.is_done = false; |
| 29 | 29 | } |
| 30 | 30 | |
| 31 | − fn read_line_inner<'b>(reader: &mut T, buf: &'b mut [u8]) -> io::Result<Result<Borrowed<'b>, decode::Error>> { | |
| 31 | + fn read_line_inner<'a>(reader: &mut T, buf: &'a mut Vec<u8>) -> io::Result<Result<Borrowed<'a>, decode::Error>> { | |
| 32 | 32 | let (hex_bytes, data_bytes) = buf.split_at_mut(4); |
| 33 | 33 | reader.read_exact(hex_bytes)?; |
| 34 | 34 | let num_data_bytes = match decode::hex_prefix(hex_bytes) { |
| @@ -49,7 +49,7 @@ where · 14 unmodified lines | ||
| 49 | 49 | if self.is_done { |
| 50 | 50 | return None; |
| 51 | 51 | } |
| 52 | − match Self::read_line_inner(&mut self.inner, &mut self.buf[..]) { | |
| 52 | + match Self::read_line_inner(&mut self.inner, &mut self.buf) { | |
| 53 | 53 | Ok(Ok(line)) if line == Borrowed::Flush => { |
| 54 | 54 | self.is_done = true; |
| 55 | 55 | None |
| @@ -58,36 +58,36 @@ where · 2 unmodified lines | ||
| 58 | 58 | } |
| 59 | 59 | } |
| 60 | 60 | |
| 61 | − // pub fn to_read<P: Progress>(&mut self, progress: P) -> ToRead<T, P> { | |
| 62 | − // ToRead { parent: self, progress } | |
| 63 | − // } | |
| 61 | + pub fn to_read<P: Progress>(&mut self, progress: P) -> ToRead<T, P> { | |
| 62 | + ToRead { parent: self, progress } | |
| 63 | + } | |
| 64 | +} | |
| 65 | + | |
| 66 | +pub struct ToRead<'a, T, P> { | |
| 67 | + parent: &'a mut Reader<T>, | |
| 68 | + progress: P, | |
| 69 | +} | |
| 70 | + | |
| 71 | +impl<'a, T, P> io::BufRead for ToRead<'a, T, P> | |
| 72 | +where | |
| 73 | + T: io::Read, | |
| 74 | + P: Progress, | |
| 75 | +{ | |
| 76 | + fn fill_buf(&mut self) -> io::Result<&[u8]> { | |
| 77 | + unimplemented!() | |
| 78 | + } | |
| 79 | + | |
| 80 | + fn consume(&mut self, amt: usize) { | |
| 81 | + unimplemented!() | |
| 82 | + } | |
| 83 | +} | |
| 84 | + | |
| 85 | +impl<'a, T, P> io::Read for ToRead<'a, T, P> | |
| 86 | +where | |
| 87 | + T: io::Read, | |
| 88 | + P: Progress, | |
| 89 | +{ | |
| 90 | + fn read(&mut self, buf: &mut [u8]) -> io::Result<usize> { | |
| 91 | + unimplemented!() | |
| 92 | + } | |
| 64 | 93 | } |
| 65 | −// | |
| 66 | −// pub struct ToRead<'a, T, P> { | |
| 67 | −// parent: &'a mut Reader<T>, | |
| 68 | −// progress: P, | |
| 69 | −// } | |
| 70 | −// | |
| 71 | −// impl<'a, T, P> io::BufRead for ToRead<'a, T, P> | |
| 72 | −// where | |
| 73 | −// T: io::Read, | |
| 74 | −// P: Progress, | |
| 75 | −// { | |
| 76 | −// fn fill_buf(&mut self) -> io::Result<&[u8]> { | |
| 77 | −// unimplemented!() | |
| 78 | −// } | |
| 79 | −// | |
| 80 | −// fn consume(&mut self, amt: usize) { | |
| 81 | −// unimplemented!() | |
| 82 | −// } | |
| 83 | −// } | |
| 84 | −// | |
| 85 | −// impl<'a, T, P> io::Read for ToRead<'a, T, P> | |
| 86 | −// where | |
| 87 | −// T: io::Read, | |
| 88 | −// P: Progress, | |
| 89 | −// { | |
| 90 | −// fn read(&mut self, buf: &mut [u8]) -> io::Result<usize> { | |
| 91 | −// unimplemented!() | |
| 92 | −// } | |
| 93 | −// } | |