27 BOOST_CONCEPT_ASSERT((boost::EqualityComparable<DelegationList>));
28 BOOST_CONCEPT_ASSERT((WireEncodableWithEncodingBuffer<DelegationList>));
29 BOOST_CONCEPT_ASSERT((WireDecodable<DelegationList>));
50 DelegationList::isValidTlvType(uint32_t type)
61 template<encoding::Tag TAG>
65 if (!isValidTlvType(type)) {
67 " while encoding DelegationList"));
70 if (this->
size() == 0) {
85 for (
auto i = m_dels.rbegin(); i != m_dels.rend(); ++i) {
87 delLen += i->name.wireEncode(encoder);
89 delLen += encoder.prependVarNumber(delLen);
93 totalLen += encoder.prependVarNumber(totalLen);
94 totalLen += encoder.prependVarNumber(type);
99 DelegationList::wireEncode<encoding::EncoderTag>(
EncodingBuffer&, uint32_t)
const;
102 DelegationList::wireEncode<encoding::EstimatorTag>(
EncodingEstimator&, uint32_t)
const;
107 if (!isValidTlvType(block.
type())) {
111 m_isSorted = wantSort;
115 for (
const auto& del : block.
elements()) {
121 auto val = del.elements_begin();
125 uint64_t preference = 0;
134 if (val == del.elements_end() || val->type() !=
tlv::Name) {
145 this->insertImpl(preference, name);
148 if (this->
size() == 0) {
160 std::vector<Delegation> dels;
165 this->insertImpl(del.preference, del.name);
173 switch (onConflict) {
175 this->eraseImpl(
nullopt, name);
176 this->insertImpl(preference, name);
179 this->insertImpl(preference, name);
182 if (!std::any_of(m_dels.begin(), m_dels.end(),
183 [name] (
const Delegation& del) {
return del.name == name; })) {
184 this->insertImpl(preference, name);
190 NDN_THROW(std::invalid_argument(
"Unknown InsertConflictResolution"));
194 DelegationList::insertImpl(uint64_t preference,
const Name& name)
197 m_dels.push_back({preference, name});
202 auto pos = std::upper_bound(m_dels.begin(), m_dels.end(), del);
203 m_dels.insert(pos, del);
207 DelegationList::eraseImpl(optional<uint64_t> preference,
const Name& name)
210 for (
auto i = m_dels.begin(); i != m_dels.end();) {
211 if ((!preference || i->preference == *preference) &&
#define NDN_THROW_NESTED(e)
existing delegation(s) with the same name are replaced with the new delegation
size_t prependNonNegativeIntegerBlock(EncodingImpl< TAG > &encoder, uint32_t type, uint64_t value)
Prepend a TLV element containing a non-negative integer.
std::string to_string(const T &val)
new delegation is not inserted if an existing delegation has the same name
DelegationList()
construct an empty DelegationList
std::ostream & operator<<(std::ostream &os, const Data &data)
void parse() const
Parse TLV-VALUE into sub-elements.
Represents a TLV element of NDN packet format.
uint64_t readNonNegativeInteger(const Block &block)
Read a non-negative integer from a TLV element.
const element_container & elements() const
Get container of sub-elements.
void wireDecode(const Block &block, bool wantSort=true)
decode a DelegationList
const_iterator end() const noexcept
Backport of ostream_joiner from the Library Fundamentals v2 TS.
ostream_joiner< std::decay_t< DelimT >, CharT, Traits > make_ostream_joiner(std::basic_ostream< CharT, Traits > &os, DelimT &&delimiter)
size_t wireEncode(EncodingImpl< TAG > &encoder, uint32_t type=tlv::ForwardingHint) const
encode into wire format
size_t size() const noexcept
Represents an absolute name.
bool insert(uint64_t preference, const Name &name, InsertConflictResolution onConflict=INS_REPLACE)
insert Delegation
InsertConflictResolution
what to do when inserting a duplicate name
void sort()
sort the delegation list
represents a list of Delegations
void wireDecode(const Block &wire)
Decode name from wire encoding.
multiple delegations with the same name are kept in the DelegationList
EncodingImpl< EncoderTag > EncodingBuffer
const nullopt_t nullopt((nullopt_t::init()))
uint32_t type() const
Return the TLV-TYPE of the Block.
represents an error in TLV encoding or decoding
EncodingImpl< EstimatorTag > EncodingEstimator
const_iterator begin() const noexcept