30 #include <boost/range/adaptors.hpp> 34 BOOST_CONCEPT_ASSERT((boost::EqualityComparable<Link>));
38 static_assert(std::is_base_of<Data::Error, Link::Error>::value,
39 "Link::Error should inherit from Data::Error");
54 m_delegations.insert(links);
61 this->removeDelegationNoEncode(name);
62 m_delegations.insert({preference, name});
69 bool hasRemovedDelegation = this->removeDelegationNoEncode(name);
70 if (hasRemovedDelegation) {
73 return hasRemovedDelegation;
82 template<encoding::Tag TAG>
96 size_t totalLength = 0;
97 for (
const auto& delegation : m_delegations | boost::adaptors::reversed) {
98 size_t delegationLength = 0;
99 delegationLength += std::get<1>(delegation).
wireEncode(encoder);
101 std::get<0>(delegation));
102 delegationLength += encoder.prependVarNumber(delegationLength);
104 totalLength += delegationLength;
106 totalLength += encoder.prependVarNumber(totalLength);
147 BOOST_THROW_EXCEPTION(
Error(
"Expected Content Type Link"));
153 for (
auto& delegation : content.
elements()) {
156 if (val == delegation.elements_end()) {
157 BOOST_THROW_EXCEPTION(
Error(
"Unexpected Link Encoding"));
164 BOOST_THROW_EXCEPTION(
Error(
"Missing Preference field in Link Encoding"));
167 if (val == delegation.elements_end()) {
168 BOOST_THROW_EXCEPTION(
Error(
"Missing Name field in Link Encoding"));
171 m_delegations.insert({preference, name});
182 std::tuple<uint32_t, Name>
187 contentBlock.
parse();
188 const Block& delegationBlock = contentBlock.
elements().at(index);
189 delegationBlock.
parse();
191 BOOST_THROW_EXCEPTION(
Error(
"Unexpected TLV-TYPE, expecting LinkDelegation"));
193 return std::make_tuple(
194 static_cast<uint32_t>(
204 contentBlock.
parse();
206 for (
auto&& delegationBlock : contentBlock.
elements()) {
207 delegationBlock.parse();
209 BOOST_THROW_EXCEPTION(
Error(
"Unexpected TLV-TYPE, expecting LinkDelegation"));
212 if (
name == delegationName) {
225 contentBlock.
parse();
230 Link::removeDelegationNoEncode(
const Name&
name)
232 bool hasRemoved =
false;
233 auto i = m_delegations.begin();
234 while (i != m_delegations.end()) {
235 if (i->second == name) {
237 i = m_delegations.erase(i);
const Block & wireEncode() const
Encode to a wire format.
void addDelegation(uint32_t preference, const Name &name)
Add a delegation in the format of <Name, Preference>
Data & setContentType(uint32_t type)
Copyright (c) 2011-2015 Regents of the University of California.
void wireDecode(const Block &wire)
Decode from the wire format.
size_t prependNonNegativeIntegerBlock(EncodingImpl< TAG > &encoder, uint32_t type, uint64_t value)
Helper to prepend TLV block type type containing non-negative integer value.
Link()=default
Create an empty Link object.
const Block & getContent() const
Get content Block.
static std::tuple< uint32_t, Name > getDelegationFromWire(const Block &block, size_t index)
gets the delegation at index from block
EncodingImpl< EstimatorTag > EncodingEstimator
Data & setContent(const uint8_t *buffer, size_t bufferSize)
Set the content from the buffer (buffer will be copied)
void parse() const
Parse wire buffer into subblocks.
Class representing a wire element of NDN-TLV packet format.
void wireDecode(const Block &wire)
Decode from the wire format.
uint64_t readNonNegativeInteger(const Block &block)
Helper to read a non-negative integer from a block.
void onChanged()
Clear the wire encoding.
std::set< std::pair< uint32_t, Name > > DelegationSet
a concept check for TLV abstraction with .wireEncode method
static ssize_t countDelegationsFromWire(const Block &block)
const Block & get(uint32_t type) const
Get the first subelement of the requested type.
EncodingImpl< EncoderTag > EncodingBuffer
bool removeDelegation(const Name &name)
Remove a delegation whose name is name.
element_container::const_iterator element_const_iterator
Name abstraction to represent an absolute name.
size_t elements_size() const
const element_container & elements() const
Get all subelements.
static ssize_t findDelegationFromWire(const Block &block, const Name &delegationName)
finds index of a delegation with delegationName from block
const DelegationSet & getDelegations() const
Get the pairs of <Name, Preference>
a concept check for TLV abstraction with .wireEncode method
a concept check for TLV abstraction with .wireDecode method and constructible from Block ...
uint32_t getContentType() const
indicates content is another name which identifies actual data content
represents an error in TLV encoding or decoding
const size_t INVALID_SELECTED_DELEGATION_INDEX