MCPcopy Create free account
hub / github.com/RustCrypto/formats / read_variable_length

Function read_variable_length

tls_codec/src/quic_vec.rs:23–45  ·  view source on GitHub ↗
(bytes: &mut R)

Source from the content-addressed store, hash-verified

21/// The length and number of bytes read are returned.
22#[inline]
23fn read_variable_length<R: std::io::Read>(bytes: &mut R) -> Result<(usize, usize), Error> {
24 // The length is encoded in the first two bits of the first byte.
25 let mut len_len_byte = [0u8; 1];
26 if bytes.read(&mut len_len_byte)? == 0 {
27 // Return in case there's nothing to read and this is just an
28 // empty vector.
29 return Ok((0, 0));
30 }
31
32 let mut length: usize = (len_len_byte[0] & 0x3F).into();
33 let len_len = (len_len_byte[0] >> 6).into();
34 debug_assert!(len_len <= 3);
35 if len_len > 3 {
36 return Err(Error::InvalidVectorLength);
37 }
38 for _ in 0..len_len {
39 let mut next = [0u8; 1];
40 bytes.read_exact(&mut next)?;
41 length = (length << 8) + usize::from(next[0]);
42 }
43
44 Ok((length, len_len))
45}
46
47#[inline]
48fn length_encoding_bytes(length: u64) -> usize {

Callers 1

tls_deserializeMethod · 0.85

Calls 2

readMethod · 0.45
read_exactMethod · 0.45

Tested by

no test coverage detected