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)
64 construct(uri.c_str());
67 template<encoding::Tag TAG>
71 size_t totalLength = 0;
75 totalLength += i->wireEncode(encoder);
78 totalLength += encoder.prependVarNumber(totalLength);
79 totalLength += encoder.prependVarNumber(
tlv::Name);
84 Name::wireEncode<encoding::EncoderTag>(EncodingImpl<encoding::EncoderTag>& encoder)
const;
87 Name::wireEncode<encoding::EstimatorTag>(EncodingImpl<encoding::EstimatorTag>& encoder)
const;
101 m_nameBlock = buffer.block();
111 BOOST_THROW_EXCEPTION(
tlv::Error(
"Unexpected TLV type when decoding Name"));
118 Name::construct(
const char* uriOrig)
122 std::string uri = uriOrig;
127 size_t iColon = uri.find(
':');
128 if (iColon != std::string::npos) {
130 size_t iFirstSlash = uri.find(
'/');
131 if (iFirstSlash == std::string::npos || iColon < iFirstSlash) {
133 uri.erase(0, iColon + 1);
140 if (uri.size() >= 2 && uri[1] ==
'/') {
142 size_t iAfterAuthority = uri.find(
'/', 2);
143 if (iAfterAuthority == std::string::npos)
147 uri.erase(0, iAfterAuthority + 1);
157 size_t iComponentStart = 0;
160 while (iComponentStart < uri.size()) {
161 size_t iComponentEnd = uri.find(
"/", iComponentStart);
162 if (iComponentEnd == std::string::npos)
163 iComponentEnd = uri.size();
166 iComponentStart = iComponentEnd + 1;
171 Name::set(
const char* uri)
173 *
this = std::move(
Name(uri));
177 Name::set(
const std::string& uri)
179 *
this = std::move(
Name(uri));
185 std::ostringstream os;
197 for (
size_t i = 0; i < name.
size(); ++i)
278 ssize_t iStart = iStartComponent < 0 ? this->
size() + iStartComponent : iStartComponent;
279 size_t iEnd = this->
size();
281 iStart = std::max(iStart, static_cast<ssize_t>(0));
283 if (nComponents !=
npos)
284 iEnd = std::min(this->
size(), iStart + nComponents);
286 for (
size_t i = iStart; i < iEnd; ++i)
296 static uint8_t firstValue[] = { 0 };
298 firstName.
append(firstValue, 1);
311 for (
size_t i = 0; i <
size(); ++i) {
312 if (
at(i) != name.
at(i))
327 for (
size_t i = 0; i <
size(); ++i) {
328 if (
at(i) != name.
at(i))
338 count1 = std::min(count1, this->
size() - pos1);
339 count2 = std::min(count2, other.
size() - pos2);
340 size_t count = std::min(count1, count2);
342 for (
size_t i = 0; i < count; ++i) {
343 int comp = this->
at(pos1 + i).
compare(other.
at(pos2 + i));
349 return count1 - count2;
372 std::string inputString;
374 name = std::move(
Name(inputString));
385 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.
Copyright (c) 2011-2015 Regents of the University of California.
const_iterator begin() const
Begin iterator (const).
static Component fromNumberWithMarker(uint8_t marker, uint64_t number)
Create a component encoded as NameComponentWithMarker.
int compare(const Component &other) const
Compare this to the other Component using NDN canonical ordering.
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...
Name & appendNumber(uint64_t number)
Append a component with the number encoded as nonNegativeInteger.
Name getSuccessor() const
Get the successor of a name.
EncodingImpl< EstimatorTag > EncodingEstimator
std::ostream & operator<<(std::ostream &os, const Data &data)
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
size_t wireEncode(EncodingImpl< TAG > &encoder) const
Fast encoding or block size estimation.
Class representing a wire element of NDN-TLV packet format.
static time_point now() noexcept
static Component fromSegmentOffset(uint64_t offset)
Create segment offset component using NDN naming conventions.
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.
std::string toUri() const
Encode this name as a URI.
a concept check for TLV abstraction with .wireEncode method
const Block & wireEncode() const
Name & appendSegmentOffset(uint64_t offset)
Append segment byte offset using NDN naming conventions.
EncodingImpl< EncoderTag > EncodingBuffer
const_iterator end() const
End iterator (const).
const_reverse_iterator rend() const
Reverse end iterator (const).
Name & appendSegment(uint64_t segmentNo)
Append segment number (sequential) using NDN naming conventions.
size_t size() const
Get the number of components.
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)
const_reverse_iterator rbegin() const
Reverse begin iterator (const).
void parse() const
Parse wire buffer into subblocks.
Component holds a read-only name component value.
static Component fromImplicitSha256Digest(const ConstBufferPtr &digest)
Create ImplicitSha256DigestComponent component.
int compare(const Name &other) const
Compare this to the other Name using NDN canonical ordering.
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.
bool empty() const
Check if name is emtpy.
bool hasWire() const
Check if the Block has fully encoded wire.
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...
void trim(std::string &str)
Modify str in place to erase whitespace on the left and right.
PartialName getSubName(ssize_t iStartComponent, size_t nComponents=npos) const
Extract a sub-name (PartialName) of nComponents components starting from iStartComponent.
PartialName getPrefix(ssize_t nComponents) const
Extract a prefix (PartialName) of the name, containing first nComponents components.
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.
bool equals(const Name &name) const
Check if this name has the same component count and components as the given name. ...
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
void clear()
Clear all the components.
const Component & at(ssize_t i) const
Get component at the specified index.
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.