|
NS-3 based Named Data Networking (NDN) simulator
ndnSIM 2.5: NDN, CCN, CCNx, content centric networks
|
API Documentation
|
Go to the documentation of this file.
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;
107 os << comp.
type() <<
'=';
115 std::pair<bool, Block>
121 bool isOverflow =
true;
123 for (; isOverflow && i > 0; i--) {
124 uint8_t newValue =
static_cast<uint8_t
>((comp.
value()[i - 1] + 1) & 0xFF);
125 encoder.prependByte(newValue);
126 isOverflow = (newValue == 0);
128 encoder.prependByteArray(comp.
value(), i);
132 encoder.appendByte(0);
135 encoder.prependVarNumber(encoder.size());
136 encoder.prependVarNumber(comp.
type());
137 return {isOverflow, encoder.block()};
146 [] (uint8_t x) { return x ==
'.'; });
177 , m_typeName(typeName)
178 , m_uriPrefix(uriPrefix)
191 BOOST_ASSERT(comp.type() == m_type);
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 NDN_THROW(
Error(
"Cannot convert to " + m_typeName +
" (invalid hex encoding)"));
250 os << m_uriPrefix <<
'=';
251 printHex(os, comp.value(), comp.value_size(),
false);
255 const uint32_t m_type;
256 const std::string m_typeName;
257 const std::string m_uriPrefix;
260 inline const Sha256ComponentType&
264 "ImplicitSha256DigestComponent",
"sha256digest");
268 inline const Sha256ComponentType&
272 "ParametersSha256DigestComponent",
"params-sha256");
284 , m_typeName(typeName)
285 , m_uriPrefix(uriPrefix)
297 return m_uriPrefix.data();
305 n = std::stoull(input);
307 catch (
const std::invalid_argument&) {
308 NDN_THROW(
Error(
"Cannot convert to " + m_typeName +
" (invalid format)"));
310 catch (
const std::out_of_range&) {
311 NDN_THROW(
Error(
"Cannot convert to " + m_typeName +
" (out of range)"));
314 NDN_THROW(
Error(
"Cannot convert to " + m_typeName +
" (invalid format)"));
322 if (comp.isNumber()) {
323 os << m_uriPrefix <<
'=' << comp.toNumber();
331 const uint32_t m_type;
332 const std::string m_typeName;
333 const std::string m_uriPrefix;
348 if (type >= m_table.size() || m_table[type] ==
nullptr) {
351 return *m_table[type];
359 auto it = m_uriPrefixes.find(prefix);
360 if (it == m_uriPrefixes.end()) {
370 m_table.at(type) = &ct;
377 const ComponentType m_baseType;
378 std::array<const ComponentType*, 38> m_table;
379 std::unordered_map<std::string, const ComponentType*> m_uriPrefixes;
385 m_table.fill(
nullptr);
418 #endif // NDN_IMPL_NAME_COMPONENT_TYPES_HPP
static Component fromNumber(uint64_t number, uint32_t type=tlv::GenericNameComponent)
Create a component encoded as nonNegativeInteger.
Sha256ComponentType(uint32_t type, const std::string &typeName, const std::string &uriPrefix)
shared_ptr< Buffer > fromHex(const std::string &hexString)
Convert the hex string to buffer.
size_t value_size() const noexcept
Return the size of TLV-VALUE, aka TLV-LENGTH.
void writeUri(std::ostream &os, const Component &comp) const final
Write URI representation of comp to os.
@ ParametersSha256DigestComponent
Rules for GenericNameComponent.
const std::vector< uint8_t > & getMinValue() const final
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.
#define NDN_CXX_UNREACHABLE
Component parseAltUriValue(const std::string &input) const final
Parse component from alternate URI representation.
static const size_t DIGEST_SIZE
Length in bytes of a SHA-256 digest.
virtual ~ComponentType()=default
void writeUri(std::ostream &os, const Component &comp) const final
Write URI representation of comp to os.
Buffer::const_iterator value_end() const
Get end iterator of TLV-VALUE.
const Sha256ComponentType & getComponentType2()
std::pair< bool, Component > getSuccessor(const Component &comp) const final
Calculate the successor of comp.
DecimalComponentType(uint32_t type, const std::string &typeName, const std::string &uriPrefix)
virtual void writeUri(std::ostream &os, const Component &comp) const
Write URI representation of comp to os.
const char * getAltUriPrefix() const final
Return the prefix of the alternate URI representation.
uint32_t type() const
Return the TLV-TYPE of the Block.
@ SequenceNumNameComponent
Buffer::const_iterator value_begin() const
Get begin iterator of TLV-VALUE.
Component create(const uint8_t *value, size_t valueSize) const
void printHex(std::ostream &os, uint64_t num, bool wantUpperCase)
Output the hex representation of num to the output stream os.
Component create(ConstBufferPtr value) const
const Sha256ComponentType & getComponentType1()
const ComponentTypeTable & getComponentTypeTable()
Get the global ComponentTypeTable.
virtual const std::vector< uint8_t > & getMinValue() const
Return the minimum allowable TLV-VALUE of this component type.
const ComponentType * findByUriPrefix(const std::string &prefix) const
Retrieve ComponentType by alternate URI prefix.
Rules regarding NameComponent types.
virtual Component parseAltUriValue(const std::string &) const
Parse component from alternate URI representation.
void check(const Component &comp) const final
Throw Component::Error if comp is invalid.
Declare rules for a NameComponent type.
virtual const char * getAltUriPrefix() const
Return the prefix of the alternate URI representation.
void writeUri(std::ostream &os, const Component &comp) const final
Write URI representation of comp to os.
const char * getAltUriPrefix() const final
Return the prefix of the alternate URI representation.
Rules for a component type holding a SHA256 digest value, written as a hex string in URI representati...
const uint8_t * value() const noexcept
Return a raw pointer to the beginning of TLV-VALUE.
Represents a name component.
Represents a TLV element of NDN packet format.
size_t size() const
Return the size of the encoded wire, i.e.
std::string to_string(const T &val)
const ComponentType & get(uint32_t type) const
Retrieve ComponentType by TLV-TYPE.
std::string escape(const std::string &str)
Percent-encode a string.
virtual std::pair< bool, Component > getSuccessor(const Component &comp) const
Calculate the successor of comp.
std::pair< bool, Block > getSuccessorImpl(const Component &comp) const
Calculate the successor of comp, extending TLV-LENGTH if value overflows.
@ ByteOffsetNameComponent
Block makeBinaryBlock(uint32_t type, const uint8_t *value, size_t length)
Create a TLV block copying TLV-VALUE from raw buffer.
shared_ptr< const Buffer > ConstBufferPtr
Rules for a component type holding a nonNegativeInteger value, written as a decimal number in URI rep...
Copyright (c) 2011-2015 Regents of the University of California.
@ ImplicitSha256DigestComponent
EncodingImpl< EncoderTag > EncodingBuffer
bool match(const Component &comp) const
virtual void check(const Component &comp) const
Throw Component::Error if comp is invalid.
Component parseAltUriValue(const std::string &input) const final
Parse component from alternate URI representation.