LibQuicR
quicr::UintVar Class Reference

#include <uintvar.h>

Public Member Functions

constexpr UintVar (uint64_t value) noexcept
 
constexpr UintVar (std::span< const std::uint8_t > bytes, const std::source_location caller=std::source_location::current())
 
constexpr UintVar (const UintVar &other) noexcept=default
 
constexpr UintVar (UintVar &&other) noexcept=default
 
constexpr UintVar & operator= (const UintVar &other) noexcept=default
 
constexpr UintVar & operator= (UintVar &&other) noexcept=default
 
constexpr UintVar & operator= (std::uint64_t value)
 
constexpr std::uint64_t Get () const noexcept
 
constexpr std::size_t Size () const noexcept
 
constexpr const std::uint8_t * data () const noexcept
 
constexpr std::size_t size () const noexcept
 
constexpr auto begin () const noexcept
 
constexpr auto end () const noexcept
 
constexpr operator uint64_t () const noexcept
 
constexpr auto operator<=> (const UintVar &other) const noexcept=default
 

Static Public Member Functions

static constexpr std::size_t Size (uint8_t msb_bytes) noexcept
 

Detailed Description

MoQ variable-length encoding of an unsigned 64-bit integer.

The encoded width is one through nine bytes. Leading one bits in the first byte identify the width; 0xFF introduces the nine-byte form. Construction from an integer produces the shortest encoding, while construction from bytes preserves the encoded width supplied by the caller (including valid non-minimal encodings).

Constructor & Destructor Documentation

◆ UintVar() [1/4]

constexpr quicr::UintVar::UintVar ( uint64_t  value)
inlineconstexprnoexcept

Encodes a value using its shortest representation.

Parameters
valueUnsigned value to encode.

◆ UintVar() [2/4]

constexpr quicr::UintVar::UintVar ( std::span< const std::uint8_t >  bytes,
const std::source_location  caller = std::source_location::current() 
)
inlineconstexpr

Copies one encoded value from the beginning of a byte span. Trailing bytes are ignored.

Parameters
bytesSpan beginning with an encoded value.
callerSource location used when reporting malformed input.
Exceptions
UintVarInvalidArgExceptionif the span is empty or shorter than the width indicated by its first byte.

◆ UintVar() [3/4]

constexpr quicr::UintVar::UintVar ( const UintVar &  other)
constexprdefaultnoexcept

Copies an encoded value.

Parameters
otherValue to copy.

◆ UintVar() [4/4]

constexpr quicr::UintVar::UintVar ( UintVar &&  other)
constexprdefaultnoexcept

Moves an encoded value.

Parameters
otherValue to move.

Member Function Documentation

◆ begin()

constexpr auto quicr::UintVar::begin ( ) const
inlineconstexprnoexcept
Returns
Iterator to the first encoded byte.

◆ data()

constexpr const std::uint8_t* quicr::UintVar::data ( ) const
inlineconstexprnoexcept
Returns
Pointer to the first encoded byte; ownership remains with this object.

◆ end()

constexpr auto quicr::UintVar::end ( ) const
inlineconstexprnoexcept
Returns
Iterator one past the last encoded byte.

◆ Get()

constexpr std::uint64_t quicr::UintVar::Get ( ) const
inlineconstexprnoexcept
Returns
The decoded unsigned value.

◆ operator uint64_t()

constexpr quicr::UintVar::operator uint64_t ( ) const
inlineexplicitconstexprnoexcept
Returns
The decoded unsigned value.

◆ operator<=>()

constexpr auto quicr::UintVar::operator<=> ( const UintVar &  other) const
constexprdefaultnoexcept

Compares the complete stored encoding, including encoded width.

Parameters
otherEncoding to compare.
Returns
Lexicographic comparison of the stored bytes.

◆ operator=() [1/3]

constexpr UintVar& quicr::UintVar::operator= ( const UintVar &  other)
constexprdefaultnoexcept

Copy-assigns an encoded value.

Parameters
otherValue to copy.
Returns
This object.

◆ operator=() [2/3]

constexpr UintVar& quicr::UintVar::operator= ( std::uint64_t  value)
inlineconstexpr

Replaces this encoding with the shortest encoding of a value.

Parameters
valueUnsigned value to encode.
Returns
This object.

◆ operator=() [3/3]

constexpr UintVar& quicr::UintVar::operator= ( UintVar &&  other)
constexprdefaultnoexcept

Move-assigns an encoded value.

Parameters
otherValue to move.
Returns
This object.

◆ Size() [1/2]

constexpr std::size_t quicr::UintVar::Size ( ) const
inlineconstexprnoexcept
Returns
Number of significant encoded bytes stored by this object.

◆ size()

constexpr std::size_t quicr::UintVar::size ( ) const
inlineconstexprnoexcept
Returns
Number of bytes in the encoded range.

◆ Size() [2/2]

static constexpr std::size_t quicr::UintVar::Size ( uint8_t  msb_bytes)
inlinestaticconstexprnoexcept

Determines an encoded width from its first byte.

Parameters
msb_bytesFirst byte of an encoding.
Returns
Required width in bytes, from one through nine.

The documentation for this class was generated from the following file: