32 #include <boost/functional/hash.hpp>
33 #include <boost/range/adaptor/reversed.hpp>
51 if (
size_t iColon = uri.find(
':'); iColon != std::string_view::npos) {
53 size_t iFirstSlash = uri.find(
'/');
54 if (iFirstSlash == std::string_view::npos || iColon < iFirstSlash) {
56 uri.remove_prefix(iColon + 1);
61 if (uri.size() >= 1 && uri[0] ==
'/') {
62 if (uri.size() >= 2 && uri[1] ==
'/') {
64 size_t iAfterAuthority = uri.find(
'/', 2);
65 if (iAfterAuthority == std::string_view::npos) {
70 uri.remove_prefix(iAfterAuthority + 1);
79 while (!uri.empty()) {
80 auto component = uri.substr(0, uri.find(
'/'));
82 if (component.size() + 1 >= uri.size()) {
86 uri.remove_prefix(component.size() + 1);
90 template<encoding::Tag TAG>
94 size_t totalLength = 0;
95 for (
const Component& comp : *
this | boost::adaptors::reversed) {
96 totalLength += comp.wireEncode(encoder);
99 totalLength += encoder.prependVarNumber(totalLength);
100 totalLength += encoder.prependVarNumber(
tlv::Name);
118 m_wire = buffer.block();
137 Name copiedName(*
this);
148 auto ssize =
static_cast<ssize_t
>(
size());
149 if (i < -ssize || i >= ssize) {
164 if (iStartComponent < 0)
165 iStartComponent +=
static_cast<ssize_t
>(
size());
166 size_t iStart = iStartComponent < 0 ? 0 : static_cast<size_t>(iStartComponent);
168 size_t iEnd =
size();
169 if (nComponents !=
npos)
170 iEnd = std::min(
size(), iStart + nComponents);
172 for (
size_t i = iStart; i < iEnd; ++i)
184 i +=
static_cast<ssize_t
>(
size());
196 i +=
static_cast<ssize_t
>(
size());
224 for (
const auto& c : name) {
230 static constexpr uint8_t SHA256_OF_EMPTY_STRING[] = {
231 0xe3, 0xb0, 0xc4, 0x42, 0x98, 0xfc, 0x1c, 0x14,
232 0x9a, 0xfb, 0xf4, 0xc8, 0x99, 0x6f, 0xb9, 0x24,
233 0x27, 0xae, 0x41, 0xe4, 0x64, 0x9b, 0x93, 0x4c,
234 0xa4, 0x95, 0x99, 0x1b, 0x78, 0x52, 0xb8, 0x55,
241 return append(placeholder);
267 static const Name n(
"/sha256digest=0000000000000000000000000000000000000000000000000000000000000000");
278 if (size() > other.size())
282 for (
size_t i = 0; i < size(); ++i) {
283 if (get(i) != other.get(i))
293 if (size() != other.size())
296 for (
size_t i = 0; i < size(); ++i) {
297 if (get(i) != other.get(i))
307 count1 = std::min(count1, this->
size() - pos1);
308 count2 = std::min(count2, other.
size() - pos2);
309 size_t count = std::min(count1, count2);
311 for (
size_t i = 0; i < count; ++i) {
318 return count1 - count2;
331 for (
const auto& component : *
this) {
333 component.toUri(os, format);
340 std::ostringstream os;
348 std::string inputString;
350 name =
Name(inputString);
Represents a TLV element of the NDN packet format.
element_const_iterator elements_begin() const noexcept
Equivalent to elements().begin().
element_iterator erase(element_const_iterator position)
Erase a sub-element.
const element_container & elements() const noexcept
Get container of sub-elements.
element_const_iterator elements_end() const noexcept
Equivalent to elements().end().
bool hasWire() const noexcept
Check if the Block contains a fully encoded wire representation.
void resetWire() noexcept
Reset wire buffer but keep TLV-TYPE and sub-elements (if any).
uint32_t type() const noexcept
Return the TLV-TYPE of the Block.
std::vector< Block > element_container
void parse() const
Parse TLV-VALUE into sub-elements.
Represents an absolute name.
bool equals(const Name &other) const noexcept
Check if this name equals another name.
Name & set(ssize_t i, const Component &component)
Replace the component at the specified index.
Name & appendTimestamp(const std::optional< time::system_clock::time_point > ×tamp=std::nullopt)
Append a timestamp component.
Name getSuccessor() const
Get the successor of a name.
PartialName getPrefix(ssize_t nComponents) const
Returns a prefix of the name.
int compare(const Name &other) const
Compare this to the other Name using NDN canonical ordering.
Name & appendParametersSha256DigestPlaceholder()
Append a placeholder for a ParametersSha256Digest component.
Name & appendVersion(const std::optional< uint64_t > &version=std::nullopt)
Append a version component.
size_t size() const noexcept
Returns the number of components.
static constexpr size_t npos
Indicates "until the end" in getSubName() and compare().
bool empty() const noexcept
Checks if the name is empty, i.e., has no components.
void clear()
Remove all components.
Name & append(const Component &component)
Append a name component.
Name()
Create an empty name.
const Component & at(ssize_t i) const
Returns an immutable reference to the component at the specified index, with bounds checking.
size_t wireEncode(EncodingImpl< TAG > &encoder) const
Prepend wire encoding to encoder.
Name deepCopy() const
Make a deep copy of the name, reallocating the underlying memory buffer.
const Block & wireEncode() const
Perform wire encoding, or return existing (cached) wire encoding.
PartialName getSubName(ssize_t iStartComponent, size_t nComponents=npos) const
Extracts some components as a sub-name (PartialName).
void erase(ssize_t i)
Erase the component at the specified index.
void toUri(std::ostream &os, name::UriFormat format=name::UriFormat::DEFAULT) const
Write URI representation of the name to the output stream.
bool isPrefixOf(const Name &other) const noexcept
Check if this name is a prefix of another name.
void wireDecode(const Block &wire)
Decode name from wire encoding.
const Component & get(ssize_t i) const noexcept
Returns an immutable reference to the component at the specified index.
Represents a name component.
static Component fromTimestamp(const time::system_clock::time_point &timePoint)
Create a timestamp component using NDN naming conventions.
static Component fromUri(std::string_view input)
Construct a NameComponent from its string representation in NDN URI format.
static Component fromVersion(uint64_t version)
Create a version component using NDN naming conventions.
int compare(const Component &other) const
Compare this component to other using NDN canonical ordering.
static time_point now() noexcept
Represents an error in TLV encoding or decoding.
#define NDN_CXX_DEFINE_WIRE_ENCODE_INSTANTIATIONS(ClassName)
EncodingImpl< EstimatorTag > EncodingEstimator
EncodingImpl< EncoderTag > EncodingBuffer
std::string to_string(const errinfo_stacktrace &x)
UriFormat
Format used for the URI representation of a name.
constexpr Duration toUnixTimestamp(const system_clock::time_point &tp)
Convert system_clock::time_point to UNIX timestamp.
@ ParametersSha256DigestComponent
Name PartialName
Represents an arbitrary sequence of name components.
std::istream & operator>>(std::istream &is, Name &name)
Parse URI from stream as Name.
size_t operator()(const ndn::Name &name) const