9 #include <initializer_list>
83 throw std::invalid_argument(
"parameter type is not a valid filter type");
102 auto param = std::visit(
104 using T = std::decay_t<decltype(f)>;
106 if constexpr (std::is_same_v<std::monostate, T>) {
135 static const std::map<ParameterType, ParameterEncoding> encodings = {
152 const auto it = encodings.find(type);
153 if (it == encodings.end()) {
155 "Unknown Message Parameter type (type=" + std::to_string(
static_cast<std::uint64_t
>(type)) +
")");
166 HasByteStreamOperators<std::decay_t<T>> || ByteParameter<std::decay_t<T>> ||
167 std::is_same_v<std::decay_t<T>,
Location> || std::is_same_v<std::decay_t<T>,
Bytes> || requires(T v) {
181 template<
typename Type = ParameterType>
182 requires std::is_convertible_v<Type, std::uint64_t> ||
183 std::is_same_v<std::underlying_type_t<Type>, std::uint64_t>
217 requires HasByteStreamOperators<T> || std::is_convertible_v<T, std::uint8_t> ||
223 const std::uint64_t key =
static_cast<std::uint64_t
>(type);
226 if constexpr (ByteParameter<T>) {
227 parameters[key].push_back(
static_cast<std::uint8_t
>(value));
231 "Given parameter type must be u8 (type=" + std::to_string(key) +
")");
239 "Given parameter type must be uvarint(u64) (type=" + std::to_string(key) +
")");
242 if constexpr (std::is_same_v<T, Bytes> || std::is_same_v<T, BytesSpan>) {
244 }
else if constexpr (HasByteStreamOperators<T>) {
248 "Given parameter type must be Location or Bytes (type=" + std::to_string(key) +
")");
263 template<ParameterValueType T>
266 if (value.has_value()) {
267 Add<T>(type, value.value());
289 std::optional<BytesSpan>
Find(Type type)
const
291 const auto it =
parameters.find(
static_cast<std::uint64_t
>(type));
310 template<ParameterValueType T>
311 std::optional<T>
Get(Type type)
const
313 const auto bytes_opt =
Find(type);
314 if (!bytes_opt.has_value()) {
317 const auto bytes = *bytes_opt;
324 if constexpr (ByteParameter<T>) {
325 return static_cast<T
>(bytes[0]);
328 std::to_string(
static_cast<std::uint64_t
>(type)) +
")");
335 std::to_string(
static_cast<std::uint64_t
>(type)) +
")");
338 if constexpr (std::is_same_v<T, Bytes> || std::is_same_v<T, BytesSpan>) {
339 return Bytes{ bytes.begin(), bytes.end() };
340 }
else if constexpr (HasByteStreamOperators<T>) {
346 std::to_string(
static_cast<std::uint64_t
>(type)) +
")");
359 if constexpr (!std::is_same_v<ParameterType, Type>) {
360 return std::monostate{};
364 if (!bytes.has_value()) {
365 return std::monostate{};
388 template<
typename Type = ParameterType>
391 std::uint64_t num = 0;
392 buffer = buffer >> num;
394 std::uint64_t prev_type = 0;
395 std::uint64_t delta = 0;
396 for (std::uint64_t i = 0; i < num; ++i) {
397 buffer = buffer >> delta;
399 const std::uint64_t type = prev_type += delta;
404 std::uint8_t
byte = 0;
405 buffer = buffer >> byte;
406 value.push_back(
byte);
412 buffer = buffer.subspan(uval.
size());
417 buffer = buffer >> loc;
422 buffer = buffer >> value;
440 template<
typename Type = ParameterType>
445 std::uint64_t prev_type = 0;
446 for (
const auto& [type, value] : msg.
parameters) {
447 buffer <<
UintVar(type - prev_type);
452 buffer << value.front();
457 buffer.insert(buffer.end(), value.begin(), value.end());
481 std::vector<ParameterType> seen;
482 for (
const auto& [type_value, value] : params) {
484 if (std::ranges::find(allowed, type) == allowed.end()) {
489 if (std::ranges::find(seen, type) != seen.end()) {
492 seen.push_back(type);
506 std::vector<Token> tokens;
507 for (
const auto& [type_value, value] : params) {
514 tokens.push_back(std::move(token));
529 return default_value;
547 if (!value.has_value()) {
562 return (expires.has_value() && expires.value() != 0) ? expires : std::nullopt;
576 return std::ranges::any_of(
592 return std::monostate{};
constexpr std::uint64_t Get() const noexcept
Definition: uintvar.h:128
constexpr std::size_t size() const noexcept
Definition: uintvar.h:160
Definition: parameters.h:185
ParameterList & operator=(ParameterList &&other)=default
std::optional< BytesSpan > Find(Type type) const
Definition: parameters.h:289
ParameterList(ParameterList &&other)=default
ParameterList(const ParameterList &other)=default
ParameterList()=default
Creates an empty list.
auto operator<=>(const ParameterList &other) const =default
auto begin() const noexcept
Definition: parameters.h:274
auto end() const noexcept
Definition: parameters.h:277
Filter GetFilter(FilterType type) const
Definition: parameters.h:357
ParameterList & AddOptional(Type type, const std::optional< T > &value)
Definition: parameters.h:264
requires HasByteStreamOperators< T > std::is_convertible_v< T, std::uint8_t > std::is_same_v< T, Location > requires(T v)
Definition: parameters.h:218
bool Contains(Type type) const
Definition: parameters.h:281
std::map< std::uint64_t, Bytes > parameters
Encoded values keyed by absolute numeric parameter type.
Definition: parameters.h:375
ParameterList & operator=(const ParameterList &other)=default
ParameterList & Add(Type type, const T &value)
Definition: parameters.h:221
std::optional< T > Get(Type type) const
Definition: parameters.h:311
void Remove(Type type)
Definition: parameters.h:300
Definition: ctrl_message_types.h:38
bool ResolveForward(const Parameters ¶ms, bool default_value)
Definition: parameters.h:526
std::vector< Token > CollectAuthTokens(const Parameters ¶ms)
Definition: parameters.h:504
constexpr FilterType kFilterTypes[]
Filter kinds searched by ContainsAnyFilter() and ResolveFilter(), in precedence order.
Definition: parameters.h:567
Parameter SerializeFilter(FilterType filter_type, const Filter &filter)
Definition: parameters.h:100
ParameterEncoding
Physical value encoding selected by a parameter type.
Definition: parameters.h:120
@ kByte
Exactly one raw byte.
@ kBytes
Unsigned-varint length followed by bytes.
@ kLocation
Two unsigned variable-length integers.
@ kVarint
One unsigned variable-length integer.
constexpr FilterType ToFilterType(ParameterType type)
Definition: parameters.h:74
Bytes & operator<<(Bytes &buffer, const Bytes &bytes)
Filter DeserializeFilter(FilterType filter_type, BytesSpan bytes)
Definition: ctrl_message_types.h:732
ParameterEncoding GetParameterEncoding(ParameterType type)
Definition: parameters.h:133
bool ContainsAnyFilter(const Parameters ¶ms)
Definition: parameters.h:574
constexpr ParameterType ToParameterFilterType(FilterType type)
Definition: parameters.h:56
FilterType GetFilterType(const Filter &filter)
Definition: ctrl_message_types.h:681
concept ParameterValueType
Definition: parameters.h:165
ParameterType GetFilterParameterType(const Filter &filter)
Definition: parameters.h:89
ParameterType
Message-parameter type codes used as delta-encoded map keys on the wire.
Definition: parameters.h:16
@ kLargestObject
Group/object location encoded as two unsigned varints.
@ kNewGroupRequest
New-group request encoded as an unsigned varint.
@ kTrackNamespacePrefix
Length-prefixed opaque namespace-prefix bytes.
@ kAuthorizationToken
Sensitive opaque token bytes; never log the value.
@ kExpires
Expiry value; zero is resolved as absent.
@ kTrackFilter
Length-prefixed track filter bytes.
@ kSubscriberPriority
One-byte subscriber priority.
@ kDeliveryTimeout
Delivery timeout, encoded as an unsigned varint.
@ kFillTimeout
Fill timeout, encoded as an unsigned varint.
@ kSubscriptionFilter
Length-prefixed location-filter bytes.
@ kInvalid
Internal sentinel; not a valid wire parameter.
@ kRendezvousTimeout
Rendezvous timeout, encoded as an unsigned varint.
@ kGroupOrder
One-byte GroupOrder value.
@ kForward
One-byte Boolean forwarding flag.
@ kSubgroupDeliveryTimeout
Subgroup delivery timeout, encoded as an unsigned varint.
BytesSpan operator>>(BytesSpan buffer, Bytes &value)
std::variant< std::monostate, SubscriptionFilter, TrackFilter > Filter
Any supported filter representation; monostate means no/unsupported filter.
Definition: ctrl_message_types.h:677
std::optional< std::uint64_t > ResolveExpires(const Parameters ¶ms)
Definition: parameters.h:559
void ValidateParameters(const Parameters ¶ms, std::initializer_list< ParameterType > allowed)
Definition: parameters.h:479
FilterType
In-memory filter discriminator.
Definition: ctrl_message_types.h:546
@ kTrackFilter
Track-selection constraints.
@ kSubscriptionFilter
Location/subscription filter.
std::optional< GroupOrder > ResolveGroupOrder(const Parameters ¶ms)
Definition: parameters.h:544
GroupOrder
Requested group traversal order.
Definition: ctrl_message_types.h:532
@ kAscending
Increasing group identifiers.
@ kDescending
Decreasing group identifiers.
Filter ResolveFilter(const Parameters ¶ms)
Definition: parameters.h:585
std::vector< Byte > Bytes
Owning contiguous byte buffer.
Definition: bytes.h:18
std::span< const Byte > BytesSpan
Non-owning, read-only view of contiguous bytes.
Definition: bytes.h:21
Definition: ctrl_message_types.h:231
Absolute group/object location ordered lexicographically by group then object.
Definition: ctrl_message_types.h:171
Exception indicating that received or constructed data violates the MoQ protocol.
Definition: ctrl_message_types.h:71
Definition: ctrl_message_types.h:425