33 #include <boost/functional/hash.hpp> 37 BOOST_CONCEPT_ASSERT((boost::EqualityComparable<Name>));
41 static_assert(std::is_base_of<tlv::Error, Name::Error>::value,
42 "Name::Error must inherit from tlv::Error");
44 const size_t Name::npos = std::numeric_limits<size_t>::max();
47 : m_nameBlock(tlv::
Name)
68 size_t iColon = uri.find(
':');
69 if (iColon != std::string::npos) {
71 size_t iFirstSlash = uri.find(
'/');
72 if (iFirstSlash == std::string::npos || iColon < iFirstSlash) {
74 uri.erase(0, iColon + 1);
81 if (uri.size() >= 2 && uri[1] ==
'/') {
83 size_t iAfterAuthority = uri.find(
'/', 2);
84 if (iAfterAuthority == std::string::npos)
88 uri.erase(0, iAfterAuthority + 1);
98 size_t iComponentStart = 0;
101 while (iComponentStart < uri.size()) {
102 size_t iComponentEnd = uri.find(
"/", iComponentStart);
103 if (iComponentEnd == std::string::npos)
104 iComponentEnd = uri.size();
107 iComponentStart = iComponentEnd + 1;
114 Name copiedName(*
this);
120 template<encoding::Tag TAG>
124 size_t totalLength = 0;
128 totalLength += i->wireEncode(encoder);
131 totalLength += encoder.prependVarNumber(totalLength);
132 totalLength += encoder.prependVarNumber(
tlv::Name);
154 m_nameBlock = buffer.block();
164 BOOST_THROW_EXCEPTION(
tlv::Error(
"Unexpected TLV type when decoding Name"));
173 std::ostringstream os;
185 for (
size_t i = 0; i < name.
size(); ++i)
266 ssize_t iStart = iStartComponent < 0 ? this->
size() + iStartComponent : iStartComponent;
267 size_t iEnd = this->
size();
269 iStart = std::max(iStart, static_cast<ssize_t>(0));
271 if (nComponents !=
npos)
272 iEnd = std::min(this->
size(), iStart + nComponents);
274 for (
size_t i = iStart; i < iEnd; ++i)
284 static uint8_t firstValue[] = { 0 };
286 firstName.
append(firstValue, 1);
299 for (
size_t i = 0; i <
size(); ++i) {
300 if (
at(i) != name.
at(i))
315 for (
size_t i = 0; i <
size(); ++i) {
316 if (
at(i) != name.
at(i))
326 count1 = std::min(count1, this->
size() - pos1);
327 count2 = std::min(count2, other.
size() - pos2);
328 size_t count = std::min(count1, count2);
330 for (
size_t i = 0; i < count; ++i) {
331 int comp = this->
at(pos1 + i).
compare(other.
at(pos2 + i));
337 return count1 - count2;
360 std::string inputString;
362 name =
Name(inputString);
373 return boost::hash_range(name.
wireEncode().wire(),
static Component fromNumber(uint64_t number)
Create a component encoded as nonNegativeInteger.
static Component fromSequenceNumber(uint64_t seqNo)
Create sequence number component using NDN naming conventions.
bool equals(const Name &name) const
Check if this name has the same component count and components as the given name. ...
PartialName getPrefix(ssize_t nComponents) const
Extract a prefix (PartialName) of the name, containing first nComponents components.
bool hasWire() const
Check if the Block has fully encoded wire.
Copyright (c) 2011-2015 Regents of the University of California.
std::string toUri() const
Encode this name as a URI.
static Component fromNumberWithMarker(uint8_t marker, uint64_t number)
Create a component encoded as NameComponentWithMarker.
static Component fromEscapedString(const char *escapedString, size_t beginOffset, size_t endOffset)
Create name::Component by decoding the escapedString between beginOffset and endOffset according to t...
const Block & wireEncode() const
const Component & at(ssize_t i) const
Get component at the specified index.
Name & appendNumber(uint64_t number)
Append a component with the number encoded as nonNegativeInteger.
const_iterator end() const
End iterator (const).
EncodingImpl< EstimatorTag > EncodingEstimator
std::ostream & operator<<(std::ostream &os, const Data &data)
Name getSuccessor() const
Get the successor of a name.
const_reverse_iterator rend() const
Reverse end iterator (const).
static Component fromTimestamp(const time::system_clock::TimePoint &timePoint)
Create sequence number component using NDN naming conventions.
static const size_t npos
indicates "until the end" in getSubName and compare
void parse() const
Parse wire buffer into subblocks.
Class representing a wire element of NDN-TLV packet format.
const_reverse_iterator rbegin() const
Reverse begin iterator (const).
int compare(const Component &other) const
Compare this to the other Component using NDN canonical ordering.
static time_point now() noexcept
static Component fromSegmentOffset(uint64_t offset)
Create segment offset component using NDN naming conventions.
void resetWire()
Reset wire buffer but keep sub elements (if any)
Name & appendSequenceNumber(uint64_t seqNo)
Append sequence number using NDN naming conventions.
static Component fromSegment(uint64_t segmentNo)
Create segment number component using NDN naming conventions.
a concept check for TLV abstraction with .wireEncode method
int compare(const Name &other) const
Compare this to the other Name using NDN canonical ordering.
Name & appendSegmentOffset(uint64_t offset)
Append segment byte offset using NDN naming conventions.
EncodingImpl< EncoderTag > EncodingBuffer
Name & appendSegment(uint64_t segmentNo)
Append segment number (sequential) using NDN naming conventions.
Name & appendTimestamp(const time::system_clock::TimePoint &timePoint=time::system_clock::now())
Append timestamp using NDN naming conventions.
std::istream & operator>>(std::istream &is, Name &name)
Name abstraction to represent an absolute name.
void push_back(const Block &element)
bool isPrefixOf(const Name &name) const
Check if the N components of this name are the same as the first N components of the given name...
const_iterator begin() const
Begin iterator (const).
size_t size() const
Get the number of components.
Component holds a read-only name component value.
static Component fromImplicitSha256Digest(const ConstBufferPtr &digest)
Create ImplicitSha256DigestComponent component.
milliseconds toUnixTimestamp(const system_clock::TimePoint &point)
Convert system_clock::TimePoint to UNIX timestamp.
Name & appendNumberWithMarker(uint8_t marker, uint64_t number)
Create a component encoded as NameComponentWithMarker.
Name & append(const uint8_t *value, size_t valueLength)
Append a new component, copying from value of length valueLength.
void trim(std::string &str)
Modify str in place to erase whitespace on the left and right.
bool empty() const
Check if name is emtpy.
size_t wireEncode(EncodingImpl< TAG > &encoder) const
Fast encoding or block size estimation.
Name PartialName
Partial name abstraction to represent an arbitrary sequence of name components.
static Component fromVersion(uint64_t version)
Create version component using NDN naming conventions.
Name deepCopy() const
Make a deep copy of the name, reallocating the underlying memory buffer.
shared_ptr< const Buffer > ConstBufferPtr
void wireDecode(const Block &wire)
a concept check for TLV abstraction with .wireEncode method
a concept check for TLV abstraction with .wireDecode method and constructible from Block ...
boost::reverse_iterator< const_iterator > const_reverse_iterator
PartialName getSubName(ssize_t iStartComponent, size_t nComponents=npos) const
Extract a sub-name (PartialName) of nComponents components starting from iStartComponent.
Name & appendVersion()
Append version using NDN naming conventions based on current UNIX timestamp in milliseconds.
Name()
Create a new Name with no components.
represents an error in TLV encoding or decoding
Name & appendImplicitSha256Digest(const ConstBufferPtr &digest)
Append ImplicitSha256Digest.