/// Parse a CompactInt into its data length and the number it represents
/// Useful for Parsing Vins and Vouts. Returns `BadCompactInt` if insufficient bytes.
///
/// # Arguments
///
/// * `buf` - A byte-string starting with a CompactInt
///
/// # Returns
///
/// * (length, number) - the length of the data in bytes, and the number it represents
Parse a CompactInt into its data length and the number it represents
Useful for Parsing Vins and Vouts. Returns `BadCompactInt` if insufficient bytes.
Parse a CompactInt into its data length and the number it represents Useful for Parsing Vins and Vouts . Returns ` BadCompactInt ` if insufficient bytes .
pub fn parse_compact_int<T: AsRef<[u8]> + ?Sized>(buf: &T) -> Result<CompactInt, SPVError> {
    let buf = buf.as_ref();
    let length = CompactInt::data_length(buf[0]) as usize;
    if length == 0 {
        return Ok(buf[0].into());
    }
    if buf.len() < 1 + length {
        return Err(SPVError::BadCompactInt);
    }
    let mut num_bytes = [0u8; 8];
    num_bytes[..length].copy_from_slice(&buf[1..=length]);
    Ok(u64::from_le_bytes(num_bytes).into())
}
pub fn parse_compact_int < T : AsRef < [ u8 ] > + ? Sized > ( buf : & T ) -> Result < CompactInt , SPVError > { let buf = buf . as_ref ( ) ; let length = CompactInt :: data_length ( buf [ 0 ] ) as usize ; if length == 0 { return Ok ( buf [ 0 ] . into ( ) ) ; } if buf . len ( ) < 1 + length { return Err ( SPVError :: BadCompactInt ) ; } let mut num_bytes = [ 0u8 ; 8 ] ; num_bytes [ .. length ] . copy_from_slice ( & buf [ 1 ..= length ] ) ; Ok ( u64 :: from_le_bytes ( num_bytes ) . into ( ) ) }
Parse a CompactInt into its data length and the number it represents
Useful for Parsing Vins and Vouts.
Parse a CompactInt into its data length and the number it represents Useful for Parsing Vins and Vouts .
(length, number) - the length of the data in bytes, and the number it represents
( length number ) - the length of the data in bytes and the number it represents
buf
&T