This commit is contained in:
Boog900 2024-11-01 22:50:16 +00:00
parent 789cd4d9c3
commit 2a91373691
No known key found for this signature in database
GPG key ID: 42AB1287CB0041C2

View file

@ -12,12 +12,12 @@ const FITS_IN_FOUR_BYTES: u64 = 2_u64.pow(32 - SIZE_OF_SIZE_MARKER) - 1;
/// ```rust /// ```rust
/// use cuprate_epee_encoding::read_varint; /// use cuprate_epee_encoding::read_varint;
/// ///
/// assert_eq!(read_varint(&mut [252].as_slice()).unwrap(), 63); /// assert_eq!(read_varint::<_, u64>(&mut [252].as_slice()).unwrap(), 63);
/// assert_eq!(read_varint(&mut [1, 1].as_slice()).unwrap(), 64); /// assert_eq!(read_varint::<_, u64>(&mut [1, 1].as_slice()).unwrap(), 64);
/// assert_eq!(read_varint(&mut [253, 255].as_slice()).unwrap(), 16_383); /// assert_eq!(read_varint::<_, u64>(&mut [253, 255].as_slice()).unwrap(), 16_383);
/// assert_eq!(read_varint(&mut [2, 0, 1, 0].as_slice()).unwrap(), 16_384); /// assert_eq!(read_varint::<_, u64>(&mut [2, 0, 1, 0].as_slice()).unwrap(), 16_384);
/// assert_eq!(read_varint(&mut [254, 255, 255, 255].as_slice()).unwrap(), 1_073_741_823); /// assert_eq!(read_varint::<_, u64>(&mut [254, 255, 255, 255].as_slice()).unwrap(), 1_073_741_823);
/// assert_eq!(read_varint(&mut [3, 0, 0, 0, 1, 0, 0, 0].as_slice()).unwrap(), 1_073_741_824); /// assert_eq!(read_varint::<_, u64>(&mut [3, 0, 0, 0, 1, 0, 0, 0].as_slice()).unwrap(), 1_073_741_824);
/// ``` /// ```
pub fn read_varint<B: Buf, T: TryFrom<u64>>(r: &mut B) -> Result<T> { pub fn read_varint<B: Buf, T: TryFrom<u64>>(r: &mut B) -> Result<T> {
if !r.has_remaining() { if !r.has_remaining() {