23 #include "../util/concepts.hpp" 24 #include "../encoding/block-helpers.hpp" 29 BOOST_CONCEPT_ASSERT((boost::EqualityComparable<AdditionalDescription>));
33 static_assert(std::is_base_of<tlv::Error, AdditionalDescription::Error>::value,
34 "AdditionalDescription::Error must inherit from tlv::Error");
47 auto it = m_info.find(key);
48 if (it == m_info.end())
49 BOOST_THROW_EXCEPTION(
Error(
"Entry does not exist for key (" + key +
")"));
63 return (m_info.find(key) != m_info.end());
69 return m_info.begin();
81 return m_info.begin();
90 template<encoding::Tag TAG>
94 size_t totalLength = 0;
96 for (
auto it = m_info.rbegin(); it != m_info.rend(); it++) {
97 size_t entryLength = 0;
100 entryLength += encoder.prependVarNumber(entryLength);
103 totalLength += entryLength;
106 totalLength += encoder.prependVarNumber(totalLength);
129 m_wire = buffer.block();
139 BOOST_THROW_EXCEPTION(
Error(
"The supplied block does not contain wire format"));
146 BOOST_THROW_EXCEPTION(
Error(
"Unexpected TLV type when decoding AdditionalDescription"));
150 const Block& entry = *it;
154 BOOST_THROW_EXCEPTION(
Error(
"Unexpected TLV type when decoding DescriptionEntry"));
157 BOOST_THROW_EXCEPTION(
Error(
"DescriptionEntry does not have two sub-TLVs"));
161 BOOST_THROW_EXCEPTION(
Error(
"Invalid DescriptionKey or DescriptionValue field"));
171 return (m_info == other.m_info);
177 return !(*
this == other);
185 for (
const auto& entry : other) {
188 os <<
"(" << entry.first <<
":" << entry.second <<
")";
bool operator!=(const AdditionalDescription &other) const
element_const_iterator elements_begin() const
bool hasWire() const
Check if the Block has fully encoded wire.
Copyright (c) 2011-2015 Regents of the University of California.
EncodingImpl< EstimatorTag > EncodingEstimator
bool operator==(const AdditionalDescription &other) const
const Block & wireEncode() const
Encode ValidityPeriod into TLV block.
element_const_iterator elements_end() const
void parse() const
Parse wire buffer into subblocks.
AdditionalDescription()=default
Create an empty AdditionalDescription.
Class representing a wire element of NDN-TLV packet format.
size_t prependStringBlock(EncodingImpl< TAG > &encoder, uint32_t type, const std::string &value)
Helper to prepend TLV block type type with value from a string value.
std::string readString(const Block &block)
Helper to read a string value from a block.
std::ostream & operator<<(std::ostream &os, const AdditionalDescription &other)
bool has(const std::string &key) const
std::map< std::string, std::string >::iterator iterator
a concept check for TLV abstraction with .wireEncode method
EncodingImpl< EncoderTag > EncodingBuffer
const std::string & get(const std::string &key) const
element_container::const_iterator element_const_iterator
size_t elements_size() const
void set(const std::string &key, const std::string &value)
const element_container & elements() const
Get all subelements.
static const size_t KEY_OFFSET
void wireDecode(const Block &wire)
Decode ValidityPeriod from TLV block.
a concept check for TLV abstraction with .wireEncode method
Abstraction of AdditionalDescription.
a concept check for TLV abstraction with .wireDecode method and constructible from Block ...
static const size_t VALUE_OFFSET
std::map< std::string, std::string >::const_iterator const_iterator