26 #include <boost/hana/functional/overload.hpp>
30 BOOST_CONCEPT_ASSERT((boost::EqualityComparable<KeyLocator>));
31 BOOST_CONCEPT_ASSERT((WireEncodable<KeyLocator>));
32 BOOST_CONCEPT_ASSERT((WireEncodableWithEncodingBuffer<KeyLocator>));
33 BOOST_CONCEPT_ASSERT((WireDecodable<KeyLocator>));
34 static_assert(std::is_base_of<tlv::Error, KeyLocator::Error>::value,
35 "KeyLocator::Error must inherit from tlv::Error");
51 template<encoding::Tag TAG>
58 size_t totalLength = 0;
60 auto visitor = boost::hana::overload(
62 [&] (
const Name& name) { totalLength += name.wireEncode(encoder); },
65 visit(visitor, m_locator);
67 totalLength += encoder.prependVarNumber(totalLength);
86 m_wire = buffer.block();
101 if (element == m_wire.
elements().end()) {
105 switch (element->type()) {
107 m_locator.emplace<
Name>(*element);
110 m_locator.emplace<
Block>(*element);
113 m_locator = element->type();
121 switch (m_locator.index()) {
129 return get<uint32_t>(m_locator);
138 m_locator = monostate{};
147 return get<Name>(m_locator);
149 catch (
const bad_variant_access&) {
166 return get<Block>(m_locator);
168 catch (
const bad_variant_access&) {
179 m_locator = keyDigest;
187 BOOST_ASSERT(keyDigest !=
nullptr);
196 auto visitor = boost::hana::overload(
200 [&] (
const Name& name) {
201 os <<
"Name=" << name;
203 [&] (
const Block& digest) {
210 [&] (uint32_t type) {
211 os <<
"Unknown(" << type <<
")";
213 visit(visitor, keyLocator.m_locator);
#define NDN_CXX_UNREACHABLE
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.
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.
const Block & getKeyDigest() const
Get nested KeyDigest element.
const Name & getName() const
Get nested Name element.
KeyLocator()
Construct an empty KeyLocator.
const Block & wireEncode() const
void wireDecode(const Block &wire)
Decode from wire encoding.
KeyLocator & setKeyDigest(const Block &keyDigest)
Set nested KeyDigest element (whole TLV).
KeyLocator & clear()
Reset KeyLocator to its default-constructed state.
KeyLocator & setName(const Name &name)
Set nested Name element.
Represents an absolute name.
#define NDN_CXX_DEFINE_WIRE_ENCODE_INSTANTIATIONS(ClassName)
EncodingImpl< EstimatorTag > EncodingEstimator
Block makeBinaryBlock(uint32_t type, span< const uint8_t > value)
Create a TLV block copying the TLV-VALUE from a byte range.
EncodingImpl< EncoderTag > EncodingBuffer
size_t prependBlock(EncodingImpl< TAG > &encoder, const Block &block)
Prepend a TLV element.
std::string to_string(const errinfo_stacktrace &x)
void printHex(std::ostream &os, uint64_t num, bool wantUpperCase)
Output the hex representation of num to the output stream os.
shared_ptr< const Buffer > ConstBufferPtr
const size_t MAX_KEY_DIGEST_OCTETS_TO_SHOW
std::ostream & operator<<(std::ostream &os, const Data &data)