22 #ifndef NDN_IMPL_NAME_COMPONENT_TYPES_HPP 23 #define NDN_IMPL_NAME_COMPONENT_TYPES_HPP 30 #include <unordered_map> 58 virtual std::pair<bool, Component>
66 virtual const std::vector<uint8_t>&
69 static std::vector<uint8_t> value;
108 os << comp.
type() <<
'=';
116 std::pair<bool, Block>
122 bool isOverflow =
true;
124 for (; isOverflow && i > 0; i--) {
125 uint8_t newValue = static_cast<uint8_t>((comp.
value()[i - 1] + 1) & 0xFF);
126 encoder.prependByte(newValue);
127 isOverflow = (newValue == 0);
129 encoder.prependByteArray(comp.
value(), i);
133 encoder.appendByte(0);
136 encoder.prependVarNumber(encoder.size());
137 encoder.prependVarNumber(comp.
type());
138 return {isOverflow, encoder.block()};
147 [] (uint8_t x) {
return x ==
'.'; });
177 , m_typeName(typeName)
178 , m_uriPrefix(uriPrefix)
192 BOOST_THROW_EXCEPTION(
Error(m_typeName +
" TLV-LENGTH must be " +
204 create(
const uint8_t* value,
size_t valueSize)
const 209 std::pair<bool, Component>
212 bool isExtended =
false;
221 const std::vector<uint8_t>&
231 return m_uriPrefix.data();
237 shared_ptr<Buffer> value;
242 BOOST_THROW_EXCEPTION(
Error(
"Cannot convert to " + m_typeName +
" (invalid hex encoding)"));
244 return Component(m_type, std::move(value));
250 os << m_uriPrefix <<
'=';
251 printHex(os, comp.value(), comp.value_size(),
false);
256 std::string m_typeName;
257 std::string m_uriPrefix;
260 inline const Sha256ComponentType&
264 "ImplicitSha256DigestComponent",
"sha256digest");
268 inline const Sha256ComponentType&
272 "ParametersSha256DigestComponent",
"params-sha256");
288 if (type >= m_table.size() || m_table[type] ==
nullptr) {
291 return *m_table[type];
299 auto it = m_uriPrefixes.find(prefix);
300 if (it == m_uriPrefixes.end()) {
310 m_table.at(type) = &ct;
317 ComponentType m_baseType;
318 std::array<const ComponentType*, 32> m_table;
319 std::unordered_map<std::string, const ComponentType*> m_uriPrefixes;
325 m_table.fill(
nullptr);
347 #endif // NDN_IMPL_NAME_COMPONENT_TYPES_HPP
Rules regarding GenericNameComponent.
Copyright (c) 2011-2015 Regents of the University of California.
const ComponentTypeTable & getComponentTypeTable()
Get the global ComponentTypeTable.
const ComponentType & get(uint32_t type) const
Retrieve ComponentType by TLV-TYPE.
static const size_t DIGEST_SIZE
Length in bytes of a SHA-256 digest.
Sha256ComponentType(uint32_t type, const std::string &typeName, const std::string &uriPrefix)
size_t value_size() const
Get size of TLV-VALUE aka TLV-LENGTH.
Rules regarding NameComponent types.
bool match(const Component &comp) const
Declare rules regarding a NameComponent type.
Represents a TLV element of NDN packet format.
const uint8_t * value() const
Get pointer to TLV-VALUE.
virtual void writeUri(std::ostream &os, const Component &comp) const
Write URI representation of comp to os.
const Sha256ComponentType & getComponentType1()
const Sha256ComponentType & getComponentType2()
void writeUri(std::ostream &os, const Component &comp) const final
Write URI representation of comp to os.
Rules regarding a component type holding a SHA256 digest value.
virtual Component parseAltUriValue(const std::string &input) const
Parse component from alternate URI representation.
Buffer::const_iterator value_begin() const
Get begin iterator of TLV-VALUE.
size_t size() const
Get size of encoded wire, including Type-Length-Value.
shared_ptr< Buffer > fromHex(const std::string &hexString)
Convert the hex string to buffer.
virtual std::pair< bool, Component > getSuccessor(const Component &comp) const
Calculate the successor of comp.
Component create(ConstBufferPtr value) const
Block makeBinaryBlock(uint32_t type, const uint8_t *value, size_t length)
Create a TLV block copying TLV-VALUE from raw buffer.
virtual ~ComponentType()=default
Buffer::const_iterator value_end() const
Get end iterator of TLV-VALUE.
virtual const char * getAltUriPrefix() const
Return the prefix of the alternate URI representation.
const std::vector< uint8_t > & getMinValue() const final
Return the minimum allowable TLV-VALUE of this component type.
virtual const std::vector< uint8_t > & getMinValue() const
Return the minimum allowable TLV-VALUE of this component type.
void writeUriEscapedValue(std::ostream &os, const Component &comp) const
Write TLV-VALUE as <escaped-value> of NDN URI syntax.
std::string escape(const std::string &str)
Percent-encode a string.
const ComponentType * findByUriPrefix(const std::string &prefix) const
Retrieve ComponentType by alternate URI prefix.
std::pair< bool, Component > getSuccessor(const Component &comp) const final
Calculate the successor of comp.
Represents a name component.
void check(const Component &comp) const final
Throw Component::Error if comp is invalid.
Component parseAltUriValue(const std::string &input) const final
Parse component from alternate URI representation.
void printHex(std::ostream &os, uint64_t num, bool wantUpperCase)
Output the hex representation of num to the output stream os.
void writeUri(std::ostream &os, const Component &comp) const final
Write URI representation of comp to os.
std::string to_string(const V &v)
const char * getAltUriPrefix() const final
Return the prefix of the alternate URI representation.
virtual void check(const Component &comp) const
Throw Component::Error if comp is invalid.
Component create(const uint8_t *value, size_t valueSize) const
std::pair< bool, Block > getSuccessorImpl(const Component &comp) const
Calculate the successor of comp, extending TLV-LENGTH if value overflows.
EncodingImpl< EncoderTag > EncodingBuffer
uint32_t type() const
Get TLV-TYPE.
shared_ptr< const Buffer > ConstBufferPtr