25 #include <boost/range/adaptor/reversed.hpp>
29 BOOST_CONCEPT_ASSERT((WireEncodable<MetaInfo>));
30 BOOST_CONCEPT_ASSERT((WireEncodableWithEncodingBuffer<MetaInfo>));
31 BOOST_CONCEPT_ASSERT((WireDecodable<MetaInfo>));
32 static_assert(std::is_base_of<tlv::Error, MetaInfo::Error>::value,
33 "MetaInfo::Error must inherit from tlv::Error");
57 if (freshnessPeriod < time::milliseconds::zero()) {
58 NDN_THROW(std::invalid_argument(
"FreshnessPeriod must be >= 0"));
61 m_freshnessPeriod = freshnessPeriod;
69 m_finalBlockId = std::move(finalBlockId);
73 const std::list<Block>&
82 for (
const auto& block :
info) {
83 if (block.type() < 128 || block.type() > 252)
84 NDN_THROW(
Error(
"AppMetaInfo block has type outside the application range [128, 252]"));
95 if (!(128 <= block.
type() && block.
type() <= 252))
96 NDN_THROW(
Error(
"AppMetaInfo block has type outside the application range [128, 252]"));
99 m_appMetaInfo.push_back(block);
106 for (
auto it = m_appMetaInfo.begin(); it != m_appMetaInfo.end(); ++it) {
109 m_appMetaInfo.erase(it);
119 auto it = std::find_if(m_appMetaInfo.begin(), m_appMetaInfo.end(),
120 [=] (
const Block& b) { return b.type() == tlvType; });
121 return it != m_appMetaInfo.end() ? &*it :
nullptr;
124 template<encoding::Tag TAG>
134 size_t totalLength = 0;
137 for (
const auto& block : m_appMetaInfo | boost::adaptors::reversed) {
142 if (m_finalBlockId) {
149 static_cast<uint64_t
>(m_freshnessPeriod.count()));
157 totalLength += encoder.prependVarNumber(totalLength);
176 m_wire = buffer.block();
196 m_type = readNonNegativeIntegerAs<uint32_t>(*val);
214 m_finalBlockId.emplace(val->blockFromValue());
218 m_finalBlockId = nullopt;
222 for (; val != m_wire.
elements().end(); ++val) {
223 m_appMetaInfo.push_back(*val);
231 os <<
"ContentType: " <<
info.getType();
234 if (
info.getFreshnessPeriod() > 0_ms) {
235 os <<
", FreshnessPeriod: " <<
info.getFreshnessPeriod();
239 if (
info.getFinalBlock()) {
240 os <<
", FinalBlockId: ";
241 info.getFinalBlock()->toUri(os);
245 for (
const auto& block :
info.getAppMetaInfo()) {
246 os <<
", AppMetaInfoTlvType: " << block.type();
Represents a TLV element of the NDN packet format.
element_const_iterator elements_begin() const noexcept
Equivalent to elements().begin().
const element_container & elements() const noexcept
Get container of sub-elements.
element_const_iterator elements_end() const noexcept
Equivalent to elements().end().
bool hasWire() const noexcept
Check if the Block contains a fully encoded wire representation.
uint32_t type() const noexcept
Return the TLV-TYPE of the Block.
void reset() noexcept
Reset the Block to a default-constructed state.
void parse() const
Parse TLV-VALUE into sub-elements.
#define NDN_CXX_DEFINE_WIRE_ENCODE_INSTANTIATIONS(ClassName)
EncodingImpl< EstimatorTag > EncodingEstimator
size_t prependNestedBlock(EncodingImpl< TAG > &encoder, uint32_t type, const U &value)
Prepend a TLV element containing a nested TLV element.
uint64_t readNonNegativeInteger(const Block &block)
Read a non-negative integer from a TLV element.
size_t prependNonNegativeIntegerBlock(EncodingImpl< TAG > &encoder, uint32_t type, uint64_t value)
Prepend a TLV element containing a non-negative integer.
EncodingImpl< EncoderTag > EncodingBuffer
size_t prependBlock(EncodingImpl< TAG > &encoder, const Block &block)
Prepend a TLV element.
boost::chrono::milliseconds milliseconds
@ ContentType_Blob
payload
std::ostream & operator<<(std::ostream &os, const Data &data)
const time::milliseconds DEFAULT_FRESHNESS_PERIOD
Default value of FreshnessPeriod.
uint64_t tlvType
TLV-TYPE of the field; 0 if field does not exist.