LibQuicR
quicr::messages::KeyValuePairs Class Reference

Draft 18 flat key-value pairs: a bounded, sorted KVP sequence without a leading count. More...

#include <ctrl_message_types.h>

Public Member Functions

 KeyValuePairs ()=default
 Creates an empty sequence. More...
 
 KeyValuePairs (const std::map< std::uint64_t, Bytes > &pairs)
 
template<typename T , KeyType K>
KeyValuePairs & Add (K type, const T &value)
 
template<typename T , KeyType K>
std::optional< T > Get (K type) const
 
bool Contains (std::uint64_t type) const
 
auto begin () const noexcept
 
auto end () const noexcept
 
const std::map< std::uint64_t, Bytes > & Pairs () const noexcept
 

Static Public Member Functions

template<typename T >
static Bytes EncodeValue (std::uint64_t type, const T &value)
 

Detailed Description

Draft 18 flat key-value pairs: a bounded, sorted KVP sequence without a leading count.

Constructor & Destructor Documentation

◆ KeyValuePairs() [1/2]

quicr::messages::KeyValuePairs::KeyValuePairs ( )
default

Creates an empty sequence.

◆ KeyValuePairs() [2/2]

quicr::messages::KeyValuePairs::KeyValuePairs ( const std::map< std::uint64_t, Bytes > &  pairs)
inline
Parameters
pairsAbsolute keys and their stored value bytes.

Member Function Documentation

◆ Add()

template<typename T , KeyType K>
KeyValuePairs& quicr::messages::KeyValuePairs::Add ( K  type,
const T &  value 
)
inline

Encodes and replaces a value by key.

Template Parameters
TValue type.
Kuint64-compatible key type.
Parameters
typeKey to insert or replace.
valueValue to encode.
Returns
This collection.

◆ begin()

auto quicr::messages::KeyValuePairs::begin ( ) const
inlinenoexcept
Returns
Const iterator to the first pair.

◆ Contains()

bool quicr::messages::KeyValuePairs::Contains ( std::uint64_t  type) const
inline
Parameters
typeNumeric key to find.
Returns
Whether numeric key type exists.

◆ EncodeValue()

template<typename T >
static Bytes quicr::messages::KeyValuePairs::EncodeValue ( std::uint64_t  type,
const T &  value 
)
inlinestatic

Converts a value to the internal KVP byte representation.

Template Parameters
TValue type.
Parameters
typeAbsolute key; parity controls integer versus byte encoding.
valueValue to encode.
Returns
Owned bytes.

◆ end()

auto quicr::messages::KeyValuePairs::end ( ) const
inlinenoexcept
Returns
Const iterator past the final pair.

◆ Get()

template<typename T , KeyType K>
std::optional<T> quicr::messages::KeyValuePairs::Get ( K  type) const
inline

Decodes a value when present.

Template Parameters
TRequested result type.
KKey type.
Parameters
typeKey to retrieve.
Returns
Decoded value, or std::nullopt when absent.

◆ Pairs()

const std::map<std::uint64_t, Bytes>& quicr::messages::KeyValuePairs::Pairs ( ) const
inlinenoexcept
Returns
Read-only reference to the sorted underlying map.

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