26 BOOST_CONCEPT_ASSERT((boost::EqualityComparable<DelegationList>));
36 :
Error(what +
std::string(
": ") + innerException.what())
59 DelegationList::isValidTlvType(uint32_t type)
70 template<encoding::Tag TAG>
74 if (!isValidTlvType(type)) {
75 BOOST_THROW_EXCEPTION(std::invalid_argument(
"Invalid TLV-TYPE " +
to_string(type) +
76 " when encoding DelegationList"));
79 if (this->
size() == 0) {
80 BOOST_THROW_EXCEPTION(
Error(
"Empty DelegationList"));
94 for (
auto i = m_dels.rbegin(); i != m_dels.rend(); ++i) {
96 delLen += i->name.wireEncode(encoder);
98 delLen += encoder.prependVarNumber(delLen);
102 totalLen += encoder.prependVarNumber(totalLen);
103 totalLen += encoder.prependVarNumber(type);
108 DelegationList::wireEncode<encoding::EncoderTag>(
EncodingBuffer&, uint32_t)
const;
111 DelegationList::wireEncode<encoding::EstimatorTag>(
EncodingEstimator&, uint32_t)
const;
116 if (!isValidTlvType(block.
type())) {
118 " when decoding DelegationList"));
121 m_isSorted = wantSort;
125 for (
const auto& del : block.
elements()) {
127 BOOST_THROW_EXCEPTION(
Error(
"Unexpected TLV-TYPE " +
to_string(del.type()) +
128 " when decoding Delegation"));
132 auto val = del.elements_begin();
134 BOOST_THROW_EXCEPTION(
Error(
"Missing Preference field in Delegation"));
136 uint64_t preference = 0;
141 BOOST_THROW_EXCEPTION(
Error(
"Invalid Preference field in Delegation", inner));
145 if (val == del.elements_end() || val->type() !=
tlv::Name) {
146 BOOST_THROW_EXCEPTION(
Error(
"Missing Name field in Delegation"));
150 name.wireDecode(*val);
153 BOOST_THROW_EXCEPTION(
Error(
"Invalid Name field in Delegation", inner));
156 this->insertImpl(preference,
name);
159 if (this->
size() == 0) {
160 BOOST_THROW_EXCEPTION(
Error(
"Empty DelegationList"));
171 std::vector<Delegation> dels;
176 this->insertImpl(del.preference, del.name);
184 switch (onConflict) {
187 this->insertImpl(preference,
name);
190 this->insertImpl(preference,
name);
193 if (!std::any_of(m_dels.begin(), m_dels.end(),
195 this->insertImpl(preference,
name);
200 BOOST_ASSERT_MSG(
false,
"Unknown onConflict");
205 DelegationList::insertImpl(uint64_t preference,
const Name&
name)
208 m_dels.push_back({preference,
name});
212 Delegation del{preference,
name};
213 auto pos = std::upper_bound(m_dels.begin(), m_dels.end(), del);
214 m_dels.insert(pos, del);
218 DelegationList::eraseImpl(optional<uint64_t> preference,
const Name&
name)
221 for (
auto i = m_dels.begin(); i != m_dels.end();) {
222 if ((!preference || i->preference == *preference) &&
237 return lhs.m_dels == rhs.m_dels;
constexpr nullopt_t nullopt
Copyright (c) 2011-2015 Regents of the University of California.
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.
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.
ostream_joiner< typename std::decay< DelimT >::type, CharT, Traits > make_ostream_joiner(std::basic_ostream< CharT, Traits > &os, DelimT &&delimiter)
const element_container & elements() const
Get container of sub elements.
a concept check for TLV abstraction with .wireEncode method
void wireDecode(const Block &block, bool wantSort=true)
decode a DelegationList
const_iterator end() const noexcept
Error(const std::string &what)
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
bool operator==(const Data &lhs, const Data &rhs)
std::string to_string(const V &v)
a concept check for TLV abstraction with .wireDecode method and constructible from Block ...
multiple delegations with the same name are kept in the DelegationList
EncodingImpl< EncoderTag > EncodingBuffer
uint32_t type() const
Get TLV-TYPE.
represents an error in TLV encoding or decoding
EncodingImpl< EstimatorTag > EncodingEstimator
const_iterator begin() const noexcept