pub struct VarInt(/* private fields */);Expand description
A QUIC variable-length integer (RFC 9000 Section 16).
Uses 2-bit prefix encoding:
- 00: 1 byte, values 0-63
- 01: 2 bytes, values 0-16383
- 10: 4 bytes, values 0-1073741823
- 11: 8 bytes, values 0-4611686018427387903
Implementations§
Source§impl VarInt
impl VarInt
Sourcepub fn from_u64(v: u64) -> Result<Self, VarIntError>
pub fn from_u64(v: u64) -> Result<Self, VarIntError>
Create a VarInt from a u64, returning an error if it exceeds the maximum.
Sourcepub fn into_inner(self) -> u64
pub fn into_inner(self) -> u64
Get the inner u64 value.
Sourcepub fn encoded_len(&self) -> usize
pub fn encoded_len(&self) -> usize
Return the number of bytes needed to encode this varint.
Sourcepub fn decode(buf: &mut impl Buf) -> Result<Self, VarIntError>
pub fn decode(buf: &mut impl Buf) -> Result<Self, VarIntError>
Decode a varint from the given buffer.
Source§impl VarInt
impl VarInt
Sourcepub fn from_u64_moqt(v: u64) -> Self
pub fn from_u64_moqt(v: u64) -> Self
Create a VarInt from a u64 under the MoQT encoding, which reaches the full 64-bit range and so cannot fail.
Sourcepub fn encode_moqt<P: MoqtProfile>(&self, buf: &mut impl BufMut)
pub fn encode_moqt<P: MoqtProfile>(&self, buf: &mut impl BufMut)
Encode using the MoQT variable-length integer (drafts 17 and later).
Draft-17 replaced the RFC 9000 encoding with one whose length comes from the number of leading 1 bits in the first byte: one byte carries 0-127, and nine bytes carry the full 64-bit range. The shortest form that holds the value is always used.
Sourcepub fn decode_moqt<P: MoqtProfile>(
buf: &mut impl Buf,
) -> Result<Self, VarIntError>
pub fn decode_moqt<P: MoqtProfile>( buf: &mut impl Buf, ) -> Result<Self, VarIntError>
Decode a MoQT variable-length integer (drafts 17 and later).
Non-minimal encodings are accepted, as draft-19 Section 1.4.1 requires:
0 may arrive as 0x00, 0x8000, 0xC00000 or any longer form. On a
Moqt17 session a 7-byte encoding is VarIntError::InvalidCodePoint.