Skip to content

Commit da966fc

Browse files
committed
last remaining docs prior to refactoring
1 parent 213924d commit da966fc

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

git-packetline/src/decode.rs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,9 @@ use bstr::BString;
55
use quick_error::quick_error;
66

77
quick_error! {
8+
/// The error used in the [`decode`][crate::decode] module
89
#[derive(Debug)]
10+
#[allow(missing_docs)]
911
pub enum Error {
1012
HexDecode(err: String) {
1113
display("Failed to decode the first four hex bytes indicating the line length: {}", err)
@@ -28,23 +30,32 @@ quick_error! {
2830
}
2931
}
3032

33+
/// A utility return type to support incremental parsing of packet lines.
3134
#[derive(Debug, Clone)]
3235
pub enum Stream<'a> {
36+
/// Indicate a single packet line was parsed completely
3337
Complete {
38+
/// The parsed packet line
3439
line: PacketLine<'a>,
40+
/// The amount of bytes consumed from input
3541
bytes_consumed: usize,
3642
},
43+
/// A packet line could not yet be parsed to to missing bytes
3744
Incomplete {
3845
/// The amount of additional bytes needed for the parsing to complete
3946
bytes_needed: usize,
4047
},
4148
}
4249

50+
/// The result of [`hex_prefix()`] indicating either a special packet line or the amount of wanted bytes
4351
pub enum PacketLineOrWantedSize<'a> {
52+
/// The special kind of packet line decoded from the hex prefix. It never contains actual data.
4453
Line(PacketLine<'a>),
54+
/// The amount of bytes indicated by the hex prefix of the packet line.
4555
Wanted(u16),
4656
}
4757

58+
/// Decode the `four_bytes` packet line prefix provided in hexadecimal form and check it for validity.
4859
pub fn hex_prefix(four_bytes: &[u8]) -> Result<PacketLineOrWantedSize<'_>, Error> {
4960
debug_assert_eq!(four_bytes.len(), 4, "need four hex bytes");
5061
for (line_bytes, line_type) in &[
@@ -60,6 +71,7 @@ pub fn hex_prefix(four_bytes: &[u8]) -> Result<PacketLineOrWantedSize<'_>, Error
6071
let mut buf = [0u8; U16_HEX_BYTES / 2];
6172
hex::decode_to_slice(four_bytes, &mut buf).map_err(|err| Error::HexDecode(err.to_string()))?;
6273
let wanted_bytes = u16::from_be_bytes(buf);
74+
6375
if wanted_bytes == 3 {
6476
return Err(Error::InvalidLineLength);
6577
}
@@ -73,6 +85,7 @@ pub fn hex_prefix(four_bytes: &[u8]) -> Result<PacketLineOrWantedSize<'_>, Error
7385
Ok(PacketLineOrWantedSize::Wanted(wanted_bytes - U16_HEX_BYTES as u16))
7486
}
7587

88+
/// Obtain a `PacketLine` from `data` after assuring `data` is small enough to fit.
7689
pub fn to_data_line(data: &[u8]) -> Result<PacketLine<'_>, Error> {
7790
if data.len() > MAX_LINE_LEN {
7891
return Err(Error::DataLengthLimitExceeded(data.len()));

0 commit comments

Comments
 (0)