Skip to content

Commit 73e24c9

Browse files
committed
refactor
1 parent 9b4fb3e commit 73e24c9

File tree

2 files changed

+20
-23
lines changed

2 files changed

+20
-23
lines changed

README.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -93,12 +93,12 @@ Please see _'Development Status'_ for a listing of all crates and their capabili
9393
* We handle timeouts by shifting all IO into the transport layer, and for the transport itself, there could be
9494
some sort of reactor which feeds the client/server respectively with deserialized lines. This enables us to
9595
start out with a sync implementation, and later add an async one that reuses all the protocol code.
96-
* [ ] [PKT-Line](https://github.com/git/git/blob/master/Documentation/technical/protocol-common.txt#L52:L52)
96+
* [x] [PKT-Line](https://github.com/git/git/blob/master/Documentation/technical/protocol-common.txt#L52:L52)
9797
* [x] encode
9898
* [x] decode (zero-copy)
9999
* [x] [error line](https://github.com/git/git/blob/master/Documentation/technical/pack-protocol.txt#L28:L28)
100100
* [x] [V2 additions](https://github.com/git/git/blob/master/Documentation/technical/protocol-v2.txt#L35:L36)
101-
* [ ] [side-band mode](https://github.com/git/git/blob/master/Documentation/technical/pack-protocol.txt#L467:L467)
101+
* [x] [side-band mode](https://github.com/git/git/blob/master/Documentation/technical/pack-protocol.txt#L467:L467)
102102
* [ ] `Iterator` for multi-plexed pack lines from `Read`
103103
* [ ] parse and serialize [capabilities](https://github.com/git/git/blob/master/Documentation/technical/protocol-capabilities.txt#L1:L1)
104104
* [ ] **Version 1**

git-protocol/src/packet_line/decode.rs

+18-21
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
1-
use crate::packet_line::{
2-
self, DELIMITER_LINE, ERR_PREFIX, FLUSH_LINE, MAX_DATA_LEN, MAX_LINE_LEN, RESPONSE_END_LINE, U16_HEX_BYTES,
1+
use crate::{
2+
packet_line::{
3+
DELIMITER_LINE, ERR_PREFIX, FLUSH_LINE, MAX_DATA_LEN, MAX_LINE_LEN, RESPONSE_END_LINE, U16_HEX_BYTES,
4+
},
5+
PacketLine,
36
};
47
use bstr::BString;
58
use quick_error::quick_error;
@@ -27,7 +30,7 @@ quick_error! {
2730
#[derive(Debug, Clone)]
2831
pub enum Stream<'a> {
2932
Complete {
30-
line: packet_line::Borrowed<'a>,
33+
line: PacketLine<'a>,
3134
bytes_consumed: usize,
3235
},
3336
Incomplete {
@@ -44,23 +47,17 @@ pub fn streaming(data: &[u8]) -> Result<Stream, Error> {
4447
});
4548
}
4649
let hex_bytes = &data[..U16_HEX_BYTES];
47-
if hex_bytes == FLUSH_LINE {
48-
return Ok(Stream::Complete {
49-
line: packet_line::Borrowed::Flush,
50-
bytes_consumed: 4,
51-
});
52-
}
53-
if hex_bytes == DELIMITER_LINE {
54-
return Ok(Stream::Complete {
55-
line: packet_line::Borrowed::Delimiter,
56-
bytes_consumed: 4,
57-
});
58-
}
59-
if hex_bytes == RESPONSE_END_LINE {
60-
return Ok(Stream::Complete {
61-
line: packet_line::Borrowed::ResponseEnd,
62-
bytes_consumed: 4,
63-
});
50+
for (line_bytes, line_type) in &[
51+
(FLUSH_LINE, PacketLine::Flush),
52+
(DELIMITER_LINE, PacketLine::Delimiter),
53+
(RESPONSE_END_LINE, PacketLine::ResponseEnd),
54+
] {
55+
if hex_bytes == *line_bytes {
56+
return Ok(Stream::Complete {
57+
line: *line_type,
58+
bytes_consumed: 4,
59+
});
60+
}
6461
}
6562

6663
let mut buf = [0u8; U16_HEX_BYTES / 2];
@@ -89,7 +86,7 @@ pub fn streaming(data: &[u8]) -> Result<Stream, Error> {
8986
}
9087

9188
Ok(Stream::Complete {
92-
line: packet_line::Borrowed::Data(data),
89+
line: PacketLine::Data(data),
9390
bytes_consumed: wanted_bytes,
9491
})
9592
}

0 commit comments

Comments
 (0)