26 BOOST_CONCEPT_ASSERT((boost::EqualityComparable<DelegationList>));
27 BOOST_CONCEPT_ASSERT((WireEncodableWithEncodingBuffer<DelegationList>));
28 BOOST_CONCEPT_ASSERT((WireDecodable<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"));
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) {
186 this->eraseImpl(
nullopt, name);
187 this->insertImpl(preference, name);
190 this->insertImpl(preference, name);
193 if (!std::any_of(m_dels.begin(), m_dels.end(),
194 [name] (
const Delegation& del) {
return del.name == name; })) {
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});
213 auto pos = std::upper_bound(m_dels.begin(), m_dels.end(), del);
214 m_dels.insert(pos, del);
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) 2013-2017 Regents of the University of California.
existing delegation(s) with the same name are replaced with the new delegation
const element_container & elements() const
Get container of sub elements.
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)
friend bool operator==(const DelegationList &, const DelegationList &)
compare whether two DelegationLists are equal
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)
void wireDecode(const Block &block, bool wantSort=true)
decode a DelegationList
const_iterator end() const noexcept
Error(const std::string &what)
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 parse() const
Parse TLV-VALUE into sub elements.
uint32_t type() const
Get TLV-TYPE.
void sort()
sort the delegation list
represents a list of Delegations
std::string to_string(const V &v)
void wireDecode(const Block &wire)
Decode name from wire encoding.
multiple delegations with the same name are kept in the DelegationList
EncodingImpl< EncoderTag > EncodingBuffer
size_t wireEncode(EncodingImpl< TAG > &encoder, uint32_t type=tlv::ForwardingHint) const
encode into wire format
represents an error in TLV encoding or decoding
EncodingImpl< EstimatorTag > EncodingEstimator
const_iterator begin() const noexcept