Skip to main content

gix_packetline/
encode.rs

1use super::MAX_DATA_LEN;
2
3/// The error returned by most functions in the [`encode`](crate::encode) module
4#[derive(Debug, thiserror::Error)]
5#[allow(missing_docs)]
6pub enum Error {
7    #[error("Cannot encode more than {MAX_DATA_LEN} bytes, got {length_in_bytes}")]
8    DataLengthLimitExceeded { length_in_bytes: usize },
9    #[error("Empty lines are invalid")]
10    DataIsEmpty,
11}
12
13pub(crate) fn u16_to_hex(value: u16) -> [u8; 4] {
14    let mut buf = [0u8; 4];
15    faster_hex::hex_encode(&value.to_be_bytes(), &mut buf).expect("two bytes to 4 hex chars never fails");
16    buf
17}