Represents a name component. More...
#include <ndn-cxx/name-component.hpp>
Classes | |
class | Error |
Public Types | |
using | element_const_iterator = element_container::const_iterator |
using | element_container = std::vector< Block > |
using | element_iterator = element_container::iterator |
Public Member Functions | |
Component (uint32_t type=tlv::GenericNameComponent) | |
Construct a NameComponent of TLV-TYPE type , using empty TLV-VALUE. More... | |
Component (const Block &wire) | |
Construct a NameComponent from block . More... | |
Component (uint32_t type, ConstBufferPtr buffer) | |
Construct a NameComponent of TLV-TYPE type , using TLV-VALUE from buffer . More... | |
Component (ConstBufferPtr buffer) | |
Construct a GenericNameComponent, using TLV-VALUE from buffer . More... | |
Component (uint32_t type, const Buffer &buffer) | |
Construct a NameComponent of TLV-TYPE type , copying TLV-VALUE from buffer . More... | |
Component (const Buffer &buffer) | |
Construct a GenericNameComponent, copying TLV-VALUE from buffer . More... | |
Component (uint32_t type, const uint8_t *value, size_t count) | |
Construct a NameComponent of TLV-TYPE type , copying count bytes at value as TLV-VALUE. More... | |
Component (const uint8_t *value, size_t count) | |
Construct a GenericNameComponent, copying count bytes at value as TLV-VALUE. More... | |
template<class Iterator > | |
Component (uint32_t type, Iterator first, Iterator last) | |
Construct a NameComponent of TLV-TYPE type , copying TLV-VALUE from a range. More... | |
template<class Iterator > | |
Component (Iterator first, Iterator last) | |
Construct a GenericNameComponent, copying TLV-VALUE from a range. More... | |
Component (const char *str) | |
Construct a GenericNameComponent, copying TLV-VALUE from a null-terminated string. More... | |
Component (const std::string &str) | |
Construct a GenericNameComponent, copying TLV-VALUE from a string. More... | |
Buffer::const_iterator | begin () const |
Get begin iterator of encoded wire. More... | |
Block | blockFromValue () const |
int | compare (const Component &other) const |
Compare this to the other Component using NDN canonical ordering. More... | |
const element_container & | elements () const |
Get container of sub-elements. More... | |
element_const_iterator | elements_begin () const |
Equivalent to elements().begin() More... | |
element_const_iterator | elements_end () const |
Equivalent to elements().end() More... | |
size_t | elements_size () const |
Equivalent to elements().size() More... | |
bool | empty () const |
void | encode () |
Encode sub-elements into TLV-VALUE. More... | |
Buffer::const_iterator | end () const |
Get end iterator of encoded wire. More... | |
bool | equals (const Component &other) const |
Check if this is the same component as other. More... | |
element_iterator | erase (element_const_iterator position) |
Erase a sub-element. More... | |
element_iterator | erase (element_const_iterator first, element_const_iterator last) |
Erase a range of sub-elements. More... | |
element_const_iterator | find (uint32_t type) const |
Find the first sub-element of the specified TLV-TYPE. More... | |
const Block & | get (uint32_t type) const |
Return the first sub-element of the specified TLV-TYPE. More... | |
ConstBufferPtr | getBuffer () const |
Get underlying buffer. More... | |
Component | getSuccessor () const |
Get the successor of this name component. More... | |
bool | hasValue () const noexcept |
Check if the Block has a non-empty TLV-VALUE. More... | |
bool | hasWire () const noexcept |
Check if the Block contains a fully encoded wire representation. More... | |
element_iterator | insert (element_const_iterator pos, const Block &element) |
Insert a sub-element. More... | |
bool | isByteOffset () const |
Check if the component is a byte offset per NDN naming conventions. More... | |
bool | isGeneric () const |
Check if the component is GenericComponent. More... | |
bool | isImplicitSha256Digest () const |
Check if the component is ImplicitSha256DigestComponent. More... | |
bool | isNumber () const |
Check if the component is a nonNegativeInteger. More... | |
bool | isNumberWithMarker (uint8_t marker) const |
Check if the component is a NameComponentWithMarker per NDN naming conventions rev1. More... | |
bool | isParametersSha256Digest () const |
Check if the component is ParametersSha256DigestComponent. More... | |
bool | isSegment () const |
Check if the component is a segment number per NDN naming conventions. More... | |
bool | isSequenceNumber () const |
Check if the component is a sequence number per NDN naming conventions. More... | |
bool | isTimestamp () const |
Check if the component is a timestamp per NDN naming conventions. More... | |
bool | isValid () const noexcept |
Check if the Block is valid. More... | |
bool | isVersion () const |
Check if the component is a version per NDN naming conventions. More... | |
operator boost::asio::const_buffer () const | |
Implicit conversion to boost::asio::const_buffer More... | |
void | parse () const |
Parse TLV-VALUE into sub-elements. More... | |
void | push_back (const Block &element) |
Append a sub-element. More... | |
void | remove (uint32_t type) |
Remove all sub-elements of the specified TLV-TYPE. More... | |
void | reset () noexcept |
Reset the Block to a default-constructed state. More... | |
void | resetWire () noexcept |
Reset wire buffer but keep TLV-TYPE and sub-elements (if any) More... | |
size_t | size () const |
Return the size of the encoded wire, i.e. More... | |
uint64_t | toByteOffset () const |
Interpret as byte offset component using NDN naming conventions. More... | |
uint64_t | toNumber () const |
Interpret this name component as nonNegativeInteger. More... | |
uint64_t | toNumberWithMarker (uint8_t marker) const |
Interpret this name component as NameComponentWithMarker. More... | |
uint64_t | toSegment () const |
Interpret as segment number component using NDN naming conventions. More... | |
uint64_t | toSequenceNumber () const |
Interpret as sequence number component using NDN naming conventions. More... | |
time::system_clock::TimePoint | toTimestamp () const |
Interpret as timestamp component using NDN naming conventions. More... | |
void | toUri (std::ostream &os, UriFormat format=UriFormat::DEFAULT) const |
Write *this to the output stream, escaping characters according to the NDN URI format. More... | |
std::string | toUri (UriFormat format=UriFormat::DEFAULT) const |
Convert *this by escaping characters according to the NDN URI format. More... | |
uint64_t | toVersion () const |
Interpret as version component using NDN naming conventions. More... | |
uint32_t | type () const |
Return the TLV-TYPE of the Block. More... | |
const uint8_t * | value () const noexcept |
Return a raw pointer to the beginning of TLV-VALUE. More... | |
Buffer::const_iterator | value_begin () const |
Get begin iterator of TLV-VALUE. More... | |
Buffer::const_iterator | value_end () const |
Get end iterator of TLV-VALUE. More... | |
size_t | value_size () const noexcept |
Return the size of TLV-VALUE, aka TLV-LENGTH. More... | |
const uint8_t * | wire () const |
Return a raw pointer to the beginning of the encoded wire. More... | |
void | wireDecode (const Block &wire) |
Decode from the wire format. More... | |
template<encoding::Tag TAG> | |
size_t | wireEncode (EncodingImpl< TAG > &encoder) const |
Fast encoding or block size estimation. More... | |
const Block & | wireEncode () const |
Encode to a wire format. More... | |
Static Public Member Functions | |
static std::tuple< bool, Block > | fromBuffer (ConstBufferPtr buffer, size_t offset) |
Try to parse Block from a wire buffer. More... | |
static std::tuple< bool, Block > | fromBuffer (const uint8_t *buf, size_t bufSize) |
Try to parse Block from a raw buffer. More... | |
static Component | fromByteOffset (uint64_t offset) |
Create byte offset component using NDN naming conventions. More... | |
static Component | fromEscapedString (const char *input, size_t beginOffset, size_t endOffset) |
Decode NameComponent from a URI component. More... | |
static Component | fromEscapedString (const char *input) |
Decode NameComponent from a URI component. More... | |
static Component | fromEscapedString (const std::string &input) |
Decode NameComponent from a URI component. More... | |
static Component | fromImplicitSha256Digest (ConstBufferPtr digest) |
Create ImplicitSha256DigestComponent component. More... | |
static Component | fromImplicitSha256Digest (const uint8_t *digest, size_t digestSize) |
Create ImplicitSha256DigestComponent component. More... | |
static Component | fromNumber (uint64_t number, uint32_t type=tlv::GenericNameComponent) |
Create a component encoded as nonNegativeInteger. More... | |
static Component | fromNumberWithMarker (uint8_t marker, uint64_t number) |
Create a component encoded as NameComponentWithMarker. More... | |
static Component | fromParametersSha256Digest (ConstBufferPtr digest) |
Create ParametersSha256DigestComponent component. More... | |
static Component | fromParametersSha256Digest (const uint8_t *digest, size_t digestSize) |
Create ParametersSha256DigestComponent component. More... | |
static Component | fromSegment (uint64_t segmentNo) |
Create segment number component using NDN naming conventions. More... | |
static Component | fromSequenceNumber (uint64_t seqNo) |
Create sequence number component using NDN naming conventions. More... | |
static Block | fromStream (std::istream &is) |
Parse Block from an input stream. More... | |
static Component | fromTimestamp (const time::system_clock::TimePoint &timePoint) |
Create sequence number component using NDN naming conventions. More... | |
static Component | fromVersion (uint64_t version) |
Create version component using NDN naming conventions. More... | |
Protected Attributes | |
Buffer::const_iterator | m_begin |
shared_ptr< const Buffer > | m_buffer |
Underlying buffer storing TLV-VALUE and possibly TLV-TYPE and TLV-LENGTH fields. More... | |
element_container | m_elements |
Contains the sub-elements. More... | |
Buffer::const_iterator | m_end |
size_t | m_size = 0 |
Total size including Type-Length-Value. More... | |
uint32_t | m_type = tlv::Invalid |
TLV-TYPE. More... | |
Buffer::const_iterator | m_valueBegin |
Buffer::const_iterator | m_valueEnd |
Friends | |
bool | operator!= (const Component &lhs, const Component &rhs) |
bool | operator< (const Component &lhs, const Component &rhs) |
std::ostream & | operator<< (std::ostream &os, const Component &component) |
bool | operator<= (const Component &lhs, const Component &rhs) |
bool | operator== (const Component &lhs, const Component &rhs) |
bool | operator> (const Component &lhs, const Component &rhs) |
bool | operator>= (const Component &lhs, const Component &rhs) |
Represents a name component.
The Component
class provides a read-only view of a Block
interpreted as a name component. Although it inherits mutation methods from Block
base class, they must not be used, because the enclosing Name
would not be updated correctly.
Definition at line 102 of file name-component.hpp.
|
inherited |
|
inherited |
|
inherited |
|
explicit |
Construct a NameComponent of TLV-TYPE type
, using empty TLV-VALUE.
Error | the NameComponent is invalid (see ensureValid ). |
Definition at line 128 of file name-component.cpp.
ndn::name::Component::Component | ( | const Block & | wire | ) |
Construct a NameComponent from block
.
Error | the NameComponent is invalid (see ensureValid ). |
This contructor enables implicit conversion from Block
.
Definition at line 134 of file name-component.cpp.
ndn::name::Component::Component | ( | uint32_t | type, |
ConstBufferPtr | buffer | ||
) |
Construct a NameComponent of TLV-TYPE type
, using TLV-VALUE from buffer
.
Error | the NameComponent is invalid (see ensureValid ). |
This constructor does not copy the underlying buffer, but retains a pointer to it. Therefore, the caller must not change the underlying buffer.
Definition at line 140 of file name-component.cpp.
|
inlineexplicit |
Construct a GenericNameComponent, using TLV-VALUE from buffer
.
Error | the NameComponent is invalid (see ensureValid ). |
This constructor does not copy the underlying buffer, but retains a pointer to it. Therefore, the caller must not change the underlying buffer.
Definition at line 144 of file name-component.hpp.
|
inline |
Construct a NameComponent of TLV-TYPE type
, copying TLV-VALUE from buffer
.
Definition at line 152 of file name-component.hpp.
|
inlineexplicit |
Construct a GenericNameComponent, copying TLV-VALUE from buffer
.
Definition at line 161 of file name-component.hpp.
ndn::name::Component::Component | ( | uint32_t | type, |
const uint8_t * | value, | ||
size_t | count | ||
) |
Construct a NameComponent of TLV-TYPE type
, copying count
bytes at value
as TLV-VALUE.
Definition at line 146 of file name-component.cpp.
|
inline |
Construct a GenericNameComponent, copying count
bytes at value
as TLV-VALUE.
Definition at line 175 of file name-component.hpp.
|
inline |
Construct a NameComponent of TLV-TYPE type
, copying TLV-VALUE from a range.
Iterator | an InputIterator dereferencing to a one-octet value type. More efficient implementation is available when it is a RandomAccessIterator . |
type | the TLV-TYPE. |
first | beginning of the range. |
last | past-end of the range. |
Definition at line 189 of file name-component.hpp.
|
inline |
Construct a GenericNameComponent, copying TLV-VALUE from a range.
Definition at line 198 of file name-component.hpp.
|
explicit |
Construct a GenericNameComponent, copying TLV-VALUE from a null-terminated string.
Bytes from the string are copied as is, and not interpreted as URI component.
Definition at line 152 of file name-component.cpp.
|
explicit |
Construct a GenericNameComponent, copying TLV-VALUE from a string.
Bytes from the string are copied as is, and not interpreted as URI component.
Definition at line 157 of file name-component.cpp.
|
inherited |
int ndn::name::Component::compare | ( | const Component & | other | ) | const |
Compare this to the other Component using NDN canonical ordering.
other | The other Component to compare with. |
negative | this comes before other in canonical ordering |
zero | this equals other |
positive | this comes after other in canonical ordering |
Definition at line 481 of file name-component.cpp.
|
inlineinherited |
|
inlineinherited |
Equivalent to elements().begin()
|
inlineinherited |
Equivalent to elements().end()
|
inlineinherited |
Equivalent to elements().size()
|
inline |
Definition at line 524 of file name-component.hpp.
|
inherited |
Encode sub-elements into TLV-VALUE.
|
inherited |
bool ndn::name::Component::equals | ( | const Component & | other | ) | const |
Check if this is the same component as other.
other | The other Component to compare with |
Definition at line 473 of file name-component.cpp.
|
inherited |
|
inherited |
|
inherited |
Find the first sub-element of the specified TLV-TYPE.
|
staticinherited |
|
staticinherited |
Try to parse Block from a raw buffer.
buf | pointer to the first octet of a TLV element |
bufSize | size of the raw buffer; may be greater than the actual size of the TLV element |
|
static |
Create byte offset component using NDN naming conventions.
Definition at line 402 of file name-component.cpp.
|
inlinestatic |
Decode NameComponent from a URI component.
The URI component is read from [input+beginOffset, input+endOffset)
range.
Error | URI component does not represent a valid NameComponent. |
Definition at line 247 of file name-component.hpp.
|
inlinestatic |
Decode NameComponent from a URI component.
Error | URI component does not represent a valid NameComponent. |
Definition at line 257 of file name-component.hpp.
|
static |
Decode NameComponent from a URI component.
Error | URI component does not represent a valid NameComponent. |
Definition at line 178 of file name-component.cpp.
|
static |
Create ImplicitSha256DigestComponent component.
Definition at line 441 of file name-component.cpp.
|
static |
Create ImplicitSha256DigestComponent component.
Definition at line 447 of file name-component.cpp.
|
static |
Create a component encoded as nonNegativeInteger.
number | The non-negative number |
type | TLV-TYPE |
Definition at line 360 of file name-component.cpp.
|
static |
Create a component encoded as NameComponentWithMarker.
NameComponentWithMarker is defined as:
NameComponentWithMarker ::= NAME-COMPONENT-TYPE TLV-LENGTH Marker includedNonNegativeInteger Marker ::= BYTE includedNonNegativeInteger ::= BYTE{1,2,4,8}
marker | 1-byte marker octet |
number | The non-negative number |
Definition at line 366 of file name-component.cpp.
|
static |
Create ParametersSha256DigestComponent component.
Definition at line 459 of file name-component.cpp.
|
static |
Create ParametersSha256DigestComponent component.
Definition at line 465 of file name-component.cpp.
|
static |
Create segment number component using NDN naming conventions.
Definition at line 394 of file name-component.cpp.
|
static |
Create sequence number component using NDN naming conventions.
Definition at line 419 of file name-component.cpp.
|
staticinherited |
Parse Block from an input stream.
tlv::Error | TLV-LENGTH is zero or exceeds upper bound |
|
static |
Create sequence number component using NDN naming conventions.
Definition at line 410 of file name-component.cpp.
|
static |
Create version component using NDN naming conventions.
Definition at line 386 of file name-component.cpp.
|
inherited |
Return the first sub-element of the specified TLV-TYPE.
tlv::Error | a sub-element of the specified type does not exist |
|
inlineinherited |
Component ndn::name::Component::getSuccessor | ( | ) | const |
Get the successor of this name component.
The successor of a name component is defined as follows:
C represents the set of name components, and X,Y ∈ C. Operator < is defined by canonical order on C. Y is the successor of X, if (a) X < Y, and (b) ∄ Z ∈ C s.t. X < Z < Y.
In plain words, successor of a name component is the next possible name component.
Examples:
sha256digest=0000000000000000000000000000000000000000000000000000000000000000
is sha256digest=0000000000000000000000000000000000000000000000000000000000000001
.sha256digest=ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff
is params-sha256=0000000000000000000000000000000000000000000000000000000000000000
.params-sha256=0000000000000000000000000000000000000000000000000000000000000000
is params-sha256=0000000000000000000000000000000000000000000000000000000000000001
.params-sha256=ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff
is 3=...
....
is %00
.A
is B
.FF
is %00%00
. Definition at line 506 of file name-component.cpp.
|
inlinenoexceptinherited |
Check if the Block has a non-empty TLV-VALUE.
This property reflects whether the underlying buffer contains a TLV-VALUE. If this is false, TLV-VALUE has zero-length. If this is true, TLV-VALUE may be zero-length.
|
inlinenoexceptinherited |
|
inherited |
Insert a sub-element.
pos | position of the new sub-element |
element | new sub-element to insert |
bool ndn::name::Component::isByteOffset | ( | ) | const |
Check if the component is a byte offset per NDN naming conventions.
Definition at line 251 of file name-component.cpp.
bool ndn::name::Component::isGeneric | ( | ) | const |
Check if the component is GenericComponent.
Definition at line 429 of file name-component.cpp.
bool ndn::name::Component::isImplicitSha256Digest | ( | ) | const |
Check if the component is ImplicitSha256DigestComponent.
Definition at line 435 of file name-component.cpp.
bool ndn::name::Component::isNumber | ( | ) | const |
Check if the component is a nonNegativeInteger.
Definition at line 223 of file name-component.cpp.
bool ndn::name::Component::isNumberWithMarker | ( | uint8_t | marker | ) | const |
Check if the component is a NameComponentWithMarker per NDN naming conventions rev1.
Definition at line 230 of file name-component.cpp.
bool ndn::name::Component::isParametersSha256Digest | ( | ) | const |
Check if the component is ParametersSha256DigestComponent.
Definition at line 453 of file name-component.cpp.
bool ndn::name::Component::isSegment | ( | ) | const |
Check if the component is a segment number per NDN naming conventions.
Definition at line 244 of file name-component.cpp.
bool ndn::name::Component::isSequenceNumber | ( | ) | const |
Check if the component is a sequence number per NDN naming conventions.
Definition at line 265 of file name-component.cpp.
bool ndn::name::Component::isTimestamp | ( | ) | const |
Check if the component is a timestamp per NDN naming conventions.
Definition at line 258 of file name-component.cpp.
|
inlinenoexceptinherited |
bool ndn::name::Component::isVersion | ( | ) | const |
Check if the component is a version per NDN naming conventions.
Definition at line 237 of file name-component.cpp.
|
inherited |
|
inherited |
Parse TLV-VALUE into sub-elements.
tlv::Error | TLV-VALUE is not a sequence of TLV elements |
|
inherited |
|
inherited |
Remove all sub-elements of the specified TLV-TYPE.
find(type) == elements_end()
|
noexceptinherited |
|
noexceptinherited |
Reset wire buffer but keep TLV-TYPE and sub-elements (if any)
hasWire() == false
hasValue() == false
|
inherited |
Return the size of the encoded wire, i.e.
of the whole TLV
isValid() == true
uint64_t ndn::name::Component::toByteOffset | ( | ) | const |
Interpret as byte offset component using NDN naming conventions.
tlv::Error | not a ByteOffset component interpreted by the chosen convention(s). |
Definition at line 318 of file name-component.cpp.
uint64_t ndn::name::Component::toNumber | ( | ) | const |
Interpret this name component as nonNegativeInteger.
Definition at line 274 of file name-component.cpp.
uint64_t ndn::name::Component::toNumberWithMarker | ( | uint8_t | marker | ) | const |
Interpret this name component as NameComponentWithMarker.
marker | 1-byte octet of the marker |
Error | if name component does not have the specified marker. tlv::Error if format does not follow NameComponentWithMarker specification. |
Definition at line 283 of file name-component.cpp.
uint64_t ndn::name::Component::toSegment | ( | ) | const |
Interpret as segment number component using NDN naming conventions.
tlv::Error | not a Segment component interpreted by the chosen convention(s). |
Definition at line 306 of file name-component.cpp.
uint64_t ndn::name::Component::toSequenceNumber | ( | ) | const |
Interpret as sequence number component using NDN naming conventions.
tlv::Error | not a SequenceNumber component interpreted by the chosen convention(s). |
Definition at line 346 of file name-component.cpp.
time::system_clock::TimePoint ndn::name::Component::toTimestamp | ( | ) | const |
Interpret as timestamp component using NDN naming conventions.
tlv::Error | not a Timestamp component interpreted by the chosen convention(s). |
Definition at line 330 of file name-component.cpp.
void ndn::name::Component::toUri | ( | std::ostream & | os, |
UriFormat | format = UriFormat::DEFAULT |
||
) | const |
Write *this to the output stream, escaping characters according to the NDN URI format.
Definition at line 202 of file name-component.cpp.
std::string ndn::name::Component::toUri | ( | UriFormat | format = UriFormat::DEFAULT | ) | const |
Convert *this by escaping characters according to the NDN URI format.
Definition at line 213 of file name-component.cpp.
uint64_t ndn::name::Component::toVersion | ( | ) | const |
Interpret as version component using NDN naming conventions.
tlv::Error | not a Version component interpreted by the chosen convention(s). |
Definition at line 294 of file name-component.cpp.
|
inlineinherited |
Return the TLV-TYPE of the Block.
|
noexceptinherited |
|
inlineinherited |
Get begin iterator of TLV-VALUE.
hasValue() == true
|
inlineinherited |
Get end iterator of TLV-VALUE.
hasValue() == true
|
noexceptinherited |
|
inherited |
void ndn::name::Component::wireDecode | ( | const Block & | wire | ) |
Decode from the wire format.
Definition at line 552 of file name-component.cpp.
size_t ndn::name::Component::wireEncode | ( | EncodingImpl< TAG > & | encoder | ) | const |
Fast encoding or block size estimation.
Definition at line 523 of file name-component.cpp.
const Block & ndn::name::Component::wireEncode | ( | ) | const |
Encode to a wire format.
Definition at line 536 of file name-component.cpp.
Definition at line 601 of file name-component.hpp.
Definition at line 607 of file name-component.hpp.
|
friend |
Definition at line 631 of file name-component.hpp.
Definition at line 613 of file name-component.hpp.
Definition at line 595 of file name-component.hpp.
Definition at line 619 of file name-component.hpp.
Definition at line 625 of file name-component.hpp.
|
protectedinherited |
|
protectedinherited |
Underlying buffer storing TLV-VALUE and possibly TLV-TYPE and TLV-LENGTH fields.
If m_buffer is nullptr, this is an invalid or zero-length Block with TLV-TYPE given in m_type. Otherwise,
|
mutableprotectedinherited |
|
protectedinherited |
|
protectedinherited |
|
protectedinherited |
|
protectedinherited |