25#include <boost/mp11/algorithm.hpp>
33getLocationSortOrder() noexcept
35 if constexpr (std::is_same_v<Tag, field_location_tags::Header>)
37 if constexpr (std::is_same_v<Tag, field_location_tags::Fragment>)
44 FieldInfo() noexcept = default;
47 FieldInfo(uint32_t type) noexcept;
50 bool isRecognized = false;
51 bool canIgnore = false;
52 bool isRepeatable = false;
53 int8_t locationSortOrder = getLocationSortOrder<field_location_tags::Header>();
56FieldInfo::FieldInfo(uint32_t type) noexcept
59 boost::mp11::mp_for_each<FieldSet>([
this] (
auto fieldDecl) {
60 if (
tlvType ==
decltype(fieldDecl)::TlvType::value) {
63 locationSortOrder = getLocationSortOrder<typename decltype(fieldDecl)::FieldLocation>();
75compareFieldSortOrder(
const FieldInfo& first,
const FieldInfo& second)
noexcept
77 return (first.locationSortOrder < second.locationSortOrder) ||
78 (first.locationSortOrder == second.locationSortOrder && first.tlvType < second.tlvType);
95 if (elements.size() == 1 && elements.front().type() == FragmentField::TlvType::value) {
96 elements.front().parse();
97 return elements.front().elements().front();
109 add<FragmentField>({wire.
begin(), wire.
end()});
122 FieldInfo
info(element.type());
124 if (!
info.isRecognized && !
info.canIgnore) {
125 NDN_THROW(
Error(
"unrecognized field " + to_string(element.type()) +
" cannot be ignored"));
129 if (
info.tlvType == prev.tlvType && !
info.isRepeatable) {
130 NDN_THROW(
Error(
"non-repeatable field " + to_string(element.type()) +
" cannot be repeated"));
133 else if (
info.tlvType != prev.tlvType && !compareFieldSortOrder(prev,
info)) {
146Packet::comparePos(uint32_t first,
const Block& second)
noexcept
148 return compareFieldSortOrder(FieldInfo(first), FieldInfo(second.type()));
Represents a TLV element of the NDN packet format.
const element_container & elements() const noexcept
Get container of sub-elements.
const_iterator begin() const
Returns an iterator to the beginning of the encoded wire.
void encode()
Encode sub-elements into TLV-VALUE.
const_iterator end() const
Returns an iterator past-the-end of the encoded wire.
uint32_t type() const noexcept
Return the TLV-TYPE of the Block.
void parse() const
Parse TLV-VALUE into sub-elements.
Block wireEncode() const
Encode packet into wire format.
void wireDecode(const Block &wire)
Decode packet from wire format.
@ HEADER3_MAX
Upper bound of 3-octet header field.
@ HEADER3_MIN
Lower bound of 3-octet header field.
Contains classes and functions related to NDNLPv2.
bool isRecognized
is this field known
uint32_t tlvType
TLV-TYPE of the field; 0 if field does not exist.
bool canIgnore
can this unknown field be ignored
int8_t locationSortOrder
sort order of field_location_tag
bool isRepeatable
is the field repeatable