void Block::parse() const { if (!m_subBlocks.empty() || value_size() == 0) return; Buffer::const_iterator begin = value_begin(); Buffer::const_iterator end = value_end(); while (begin != end) { Buffer::const_iterator element_begin = begin; uint32_t type = Tlv::readType(begin, end); uint64_t length = Tlv::readVarNumber(begin, end); if (length > static_cast<uint64_t>(end - begin)) { m_subBlocks.clear(); throw Tlv::Error("TLV length exceeds buffer length"); } Buffer::const_iterator element_end = begin + length; m_subBlocks.push_back(Block(m_buffer, type, element_begin, element_end, begin, element_end)); begin = element_end; // don't do recursive parsing, just the top level } }
bool Component::equals(const Component& other) const { return type() == other.type() && value_size() == other.value_size() && (empty() || // needed with Apple clang < 9.0.0 due to libc++ bug std::equal(value_begin(), value_end(), other.value_begin())); }
uint64_t Component::toNumberWithMarker(uint8_t marker) const { if (!isNumberWithMarker(marker)) NDN_THROW(Error("Name component does not have the requested marker " "or the value is not a nonNegativeInteger")); Buffer::const_iterator valueBegin = value_begin() + 1; return tlv::readNonNegativeInteger(value_size() - 1, valueBegin, value_end()); }
Block Block::blockFromValue() const { if (value_size() == 0) throw Error("Underlying value buffer is empty"); Buffer::const_iterator begin = value_begin(), end = value_end(); Buffer::const_iterator element_begin = begin; uint32_t type = Tlv::readType(begin, end); uint64_t length = Tlv::readVarNumber(begin, end); if (length != static_cast<uint64_t>(end - begin)) throw Tlv::Error("TLV length mismatches buffer length"); return Block(m_buffer, type, element_begin, end, begin, end); }