25 #include <boost/bind/bind.hpp>
26 #include <boost/mpl/for_each.hpp>
27 #include <boost/range/adaptor/reversed.hpp>
34 template<
typename TAG>
36 getLocationSortOrder() noexcept;
40 getLocationSortOrder<field_location_tags::Header>() noexcept
47 getLocationSortOrder<field_location_tags::Fragment>() noexcept
56 FieldInfo() noexcept = default;
59 FieldInfo(uint64_t tlv) noexcept;
69 class ExtractFieldInfo
72 using result_type = void;
76 operator()(FieldInfo*
info,
const T&)
const noexcept
78 if (T::TlvType::value !=
info->tlvType) {
81 info->isRecognized =
true;
82 info->canIgnore =
false;
83 info->isRepeatable = T::IsRepeatable::value;
84 info->locationSortOrder = getLocationSortOrder<typename T::FieldLocation>();
88 FieldInfo::FieldInfo(uint64_t tlv) noexcept
91 boost::mpl::for_each<FieldSet>(boost::bind(ExtractFieldInfo(),
this, _1));
100 compareFieldSortOrder(
const FieldInfo& first,
const FieldInfo& second) noexcept
102 return (first.locationSortOrder < second.locationSortOrder) ||
103 (first.locationSortOrder == second.locationSortOrder && first.tlvType < second.tlvType);
123 if (elements.size() == 1 && elements.front().type() == FragmentField::TlvType::value) {
124 elements.front().parse();
125 return elements.front().elements().front();
137 add<FragmentField>({wire.
begin(), wire.
end()});
150 FieldInfo
info(element.type());
152 if (!
info.isRecognized && !
info.canIgnore) {
157 if (
info.tlvType == prev.tlvType && !
info.isRepeatable) {
161 else if (
info.tlvType != prev.tlvType && !compareFieldSortOrder(prev,
info)) {
174 Packet::comparePos(uint64_t first,
const Block& second) noexcept
176 FieldInfo firstInfo(first);
177 FieldInfo secondInfo(second.type());
178 return compareFieldSortOrder(firstInfo, secondInfo);
Represents a TLV element of the NDN packet format.
const_iterator begin() const
Get begin iterator of encoded wire.
const element_container & elements() const noexcept
Get container of sub-elements.
void encode()
Encode sub-elements into TLV-VALUE.
const_iterator end() const
Get end iterator of encoded wire.
uint32_t type() const noexcept
Return the TLV-TYPE of the Block.
std::vector< Block > element_container
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.
std::string to_string(const errinfo_stacktrace &x)
@ HEADER3_MAX
Upper bound of 3-octet header field.
@ HEADER3_MIN
Lower bound of 3-octet header field.
int locationSortOrder
sort order of field_location_tag
bool isRecognized
is this field known
bool canIgnore
can this unknown field be ignored
uint64_t tlvType
TLV-TYPE of the field; 0 if field does not exist.
bool isRepeatable
is the field repeatable