26 BOOST_CONCEPT_ASSERT((boost::EqualityComparable<DelegationList>));
31 :
Error(what +
": "s + innerException.what())
54 DelegationList::isValidTlvType(uint32_t type)
65 template<encoding::Tag TAG>
69 if (!isValidTlvType(type)) {
70 BOOST_THROW_EXCEPTION(std::invalid_argument(
"Invalid TLV-TYPE " +
to_string(type) +
71 " when encoding DelegationList"));
74 if (this->
size() == 0) {
75 BOOST_THROW_EXCEPTION(
Error(
"Empty DelegationList"));
89 for (
auto i = m_dels.rbegin(); i != m_dels.rend(); ++i) {
91 delLen += i->name.wireEncode(encoder);
93 delLen += encoder.prependVarNumber(delLen);
97 totalLen += encoder.prependVarNumber(totalLen);
98 totalLen += encoder.prependVarNumber(type);
103 DelegationList::wireEncode<encoding::EncoderTag>(
EncodingBuffer&, uint32_t)
const;
106 DelegationList::wireEncode<encoding::EstimatorTag>(
EncodingEstimator&, uint32_t)
const;
111 if (!isValidTlvType(block.
type())) {
113 " when decoding DelegationList"));
116 m_isSorted = wantSort;
120 for (
const auto& del : block.
elements()) {
122 BOOST_THROW_EXCEPTION(
Error(
"Unexpected TLV-TYPE " +
to_string(del.type()) +
123 " when decoding Delegation"));
127 auto val = del.elements_begin();
129 BOOST_THROW_EXCEPTION(
Error(
"Missing Preference field in Delegation"));
131 uint64_t preference = 0;
136 BOOST_THROW_EXCEPTION(
Error(
"Invalid Preference field in Delegation", inner));
140 if (val == del.elements_end() || val->type() !=
tlv::Name) {
141 BOOST_THROW_EXCEPTION(
Error(
"Missing Name field in Delegation"));
145 name.wireDecode(*val);
148 BOOST_THROW_EXCEPTION(
Error(
"Invalid Name field in Delegation", inner));
151 this->insertImpl(preference,
name);
154 if (this->
size() == 0) {
155 BOOST_THROW_EXCEPTION(
Error(
"Empty DelegationList"));
166 std::vector<Delegation> dels;
171 this->insertImpl(del.preference, del.name);
179 switch (onConflict) {
182 this->insertImpl(preference,
name);
185 this->insertImpl(preference,
name);
188 if (!std::any_of(m_dels.begin(), m_dels.end(),
190 this->insertImpl(preference,
name);
195 BOOST_ASSERT_MSG(
false,
"Unknown onConflict");
200 DelegationList::insertImpl(uint64_t preference,
const Name&
name)
203 m_dels.push_back({preference,
name});
207 Delegation del{preference,
name};
208 auto pos = std::upper_bound(m_dels.begin(), m_dels.end(), del);
209 m_dels.insert(pos, del);
213 DelegationList::eraseImpl(optional<uint64_t> preference,
const Name&
name)
216 for (
auto i = m_dels.begin(); i != m_dels.end();) {
217 if ((!preference || i->preference == *preference) &&
232 return lhs.m_dels == rhs.m_dels;
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.
Error(const std::string &what, const std::exception &innerException)
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.
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
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
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
const nullopt_t nullopt((nullopt_t::init()))
uint32_t type() const
Get TLV-TYPE.
represents an error in TLV encoding or decoding
EncodingImpl< EstimatorTag > EncodingEstimator
const_iterator begin() const noexcept