History

Revert "[protocol] an alternative version with external buffer"

This reverts commit a862d22aaadbd1f096400d4bcd06bc5c1ce17425.

Sebastian Thiel committed 6 years ago

Commit 157d8101 parent 579a6973 files · +67 −69Browse files

Showing the changes to git-protocol/src (2 of 3 files). Show all

Unified · Split

2 files
  1. git-protocol/src/packet_line/mod.rs +1 −1
  2. git-protocol/src/packet_line/read.rs +39 −39
git-protocol/src/packet_line/mod.rs+1−1
@@ -1,6 +1,6 @@
11 pub(crate) const U16_HEX_BYTES: usize = 4;
22 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;
44 pub(crate) const FLUSH_LINE: &[u8] = b"0000";
55 pub(crate) const DELIMITER_LINE: &[u8] = b"0001";
66 pub(crate) const RESPONSE_END_LINE: &[u8] = b"0002";
git-protocol/src/packet_line/read.rs+39−39
@@ -5,20 +5,20 @@ use std::io; · 4 unmodified lines
55 /// Read pack lines one after another, without consuming more than needed from the underlying
66 /// `Read`. `Flush` lines cause the reader to stop producing lines forever, leaver `Read` at the
77 /// start of whatever comes next.
8−pub struct Reader<'a, T> {
8+pub struct Reader<T> {
99 pub inner: T,
10− buf: &'a mut [u8; MAX_LINE_LEN],
10+ buf: Vec<u8>,
1111 is_done: bool,
1212 }
1313
14−impl<'a, T> Reader<'a, T>
14+impl<T> Reader<T>
1515 where
1616 T: io::Read,
1717 {
18− pub fn new(inner: T, buf: &'a mut [u8; MAX_LINE_LEN]) -> Self {
18+ pub fn new(inner: T) -> Self {
1919 Reader {
2020 inner,
21− buf,
21+ buf: vec![0; MAX_LINE_LEN],
2222 is_done: false,
2323 }
2424 }
@@ -28,7 +28,7 @@ where · 3 unmodified lines
2828 self.is_done = false;
2929 }
3030
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>> {
3232 let (hex_bytes, data_bytes) = buf.split_at_mut(4);
3333 reader.read_exact(hex_bytes)?;
3434 let num_data_bytes = match decode::hex_prefix(hex_bytes) {
@@ -49,7 +49,7 @@ where · 14 unmodified lines
4949 if self.is_done {
5050 return None;
5151 }
52− match Self::read_line_inner(&mut self.inner, &mut self.buf[..]) {
52+ match Self::read_line_inner(&mut self.inner, &mut self.buf) {
5353 Ok(Ok(line)) if line == Borrowed::Flush => {
5454 self.is_done = true;
5555 None
@@ -58,36 +58,36 @@ where · 2 unmodified lines
5858 }
5959 }
6060
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+ }
6493 }
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−// }

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t