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 @@
1pub(crate) const U16_HEX_BYTES: usize = 4;1pub(crate) const U16_HEX_BYTES: usize = 4;
2pub(crate) const MAX_DATA_LEN: usize = 65516;2pub(crate) const MAX_DATA_LEN: usize = 65516;
3pub const MAX_LINE_LEN: usize = MAX_DATA_LEN + U16_HEX_BYTES;3pub(crate) const MAX_LINE_LEN: usize = MAX_DATA_LEN + U16_HEX_BYTES;
4pub(crate) const FLUSH_LINE: &[u8] = b"0000";4pub(crate) const FLUSH_LINE: &[u8] = b"0000";
5pub(crate) const DELIMITER_LINE: &[u8] = b"0001";5pub(crate) const DELIMITER_LINE: &[u8] = b"0001";
6pub(crate) const RESPONSE_END_LINE: &[u8] = b"0002";6pub(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
5/// Read pack lines one after another, without consuming more than needed from the underlying5/// Read pack lines one after another, without consuming more than needed from the underlying
6/// `Read`. `Flush` lines cause the reader to stop producing lines forever, leaver `Read` at the6/// `Read`. `Flush` lines cause the reader to stop producing lines forever, leaver `Read` at the
7/// start of whatever comes next.7/// start of whatever comes next.
8pub struct Reader<'a, T> {8pub struct Reader<T> {
9 pub inner: T,9 pub inner: T,
10 buf: &'a mut [u8; MAX_LINE_LEN],10 buf: Vec<u8>,
11 is_done: bool,11 is_done: bool,
12}12}
13 13
14impl<'a, T> Reader<'a, T>14impl<T> Reader<T>
15where15where
16 T: io::Read,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 Reader {19 Reader {
20 inner,20 inner,
21 buf,21 buf: vec![0; MAX_LINE_LEN],
22 is_done: false,22 is_done: false,
23 }23 }
24 }24 }
@@ -28,7 +28,7 @@ where · 3 unmodified lines
28 self.is_done = false;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 let (hex_bytes, data_bytes) = buf.split_at_mut(4);32 let (hex_bytes, data_bytes) = buf.split_at_mut(4);
33 reader.read_exact(hex_bytes)?;33 reader.read_exact(hex_bytes)?;
34 let num_data_bytes = match decode::hex_prefix(hex_bytes) {34 let num_data_bytes = match decode::hex_prefix(hex_bytes) {
@@ -49,7 +49,7 @@ where · 14 unmodified lines
49 if self.is_done {49 if self.is_done {
50 return None;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 Ok(Ok(line)) if line == Borrowed::Flush => {53 Ok(Ok(line)) if line == Borrowed::Flush => {
54 self.is_done = true;54 self.is_done = true;
55 None55 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> {61 pub fn to_read<P: Progress>(&mut self, progress: P) -> ToRead<T, P> {
62 // ToRead { parent: self, progress }62 ToRead { parent: self, progress }
63 // }63 }
64}
65
66pub struct ToRead<'a, T, P> {
67 parent: &'a mut Reader<T>,
68 progress: P,
69}
70
71impl<'a, T, P> io::BufRead for ToRead<'a, T, P>
72where
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
85impl<'a, T, P> io::Read for ToRead<'a, T, P>
86where
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// }

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