|
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.
36 BOOST_CONCEPT_ASSERT((boost::EqualityComparable<Component>));
40 static_assert(std::is_base_of<tlv::Error, Component::Error>::value,
41 "name::Component::Error must inherit from tlv::Error");
61 NDN_THROW(std::invalid_argument(
"Unknown naming convention"));
93 static const char* env = std::getenv(
"NDN_NAME_ALT_URI");
94 static bool defaultSetting = env ==
nullptr || env[0] !=
'0';
95 return defaultSetting;
101 Component::ensureValid()
const
146 std::ostringstream oss;
148 std::string value = oss.str();
149 if (value.find_first_not_of(
'.') == std::string::npos) {
150 if (value.size() < 3) {
153 return Component(type,
reinterpret_cast<const uint8_t*
>(value.data()), value.size() - 3);
155 return Component(type,
reinterpret_cast<const uint8_t*
>(value.data()), value.size());
161 size_t equalPos = input.
find(
'=');
162 if (equalPos == std::string::npos) {
166 auto typePrefix = input.substr(0, equalPos);
167 auto type = std::strtoul(typePrefix.data(),
nullptr, 10);
170 size_t valuePos = equalPos + 1;
172 input.data() + valuePos, input.size() - valuePos);
177 NDN_THROW(
Error(
"Unknown TLV-TYPE '" + typePrefix +
"' in NameComponent URI"));
179 return ct->parseAltUriValue(input.substr(equalPos + 1));
196 std::ostringstream os;
258 NDN_THROW(
Error(
"Name component does not have nonNegativeInteger value"));
267 NDN_THROW(
Error(
"Name component does not have the requested marker "
268 "or the value is not a nonNegativeInteger"));
270 Buffer::const_iterator valueBegin =
value_begin() + 1;
352 valueLength += estimator.prependByteArray(&marker, 1);
353 size_t totalLength = valueLength;
354 totalLength += estimator.prependVarNumber(valueLength);
358 encoder.prependNonNegativeInteger(number);
359 encoder.prependByteArray(&marker, 1);
360 encoder.prependVarNumber(valueLength);
363 return encoder.block();
473 int cmpType =
type() - other.
type();
490 bool isOverflow =
false;
492 std::tie(isOverflow, successor) =
503 template<encoding::Tag TAG>
507 size_t totalLength = 0;
510 totalLength += encoder.prependVarNumber(
value_size());
511 totalLength += encoder.prependVarNumber(
type());
529 const_cast<Component&
>(*this) = buffer.block();
bool equals(const Component &other) const
Check if this is the same component as other.
static Component fromTimestamp(const time::system_clock::TimePoint &timePoint)
Create sequence number component using NDN naming conventions.
bool isByteOffset() const
Check if the component is a byte offset per NDN naming conventions.
static Component fromNumber(uint64_t number, uint32_t type=tlv::GenericNameComponent)
Create a component encoded as nonNegativeInteger.
bool isNumber() const
Check if the component is a nonNegativeInteger.
static Component fromByteOffset(uint64_t offset)
Create byte offset component using NDN naming conventions.
Convention getConventionEncoding()
Return which Naming Conventions style to use while encoding.
@ DEFAULT
ALTERNATE, unless NDN_NAME_ALT_URI environment variable is set to '0'.
bool isSegment() const
Check if the component is a segment number per NDN naming conventions.
static bool chooseAltUri(UriFormat format)
static Component fromNumberWithMarker(uint8_t marker, uint64_t number)
Create a component encoded as NameComponentWithMarker.
bool isGeneric() const
Check if the component is GenericComponent.
static Convention g_conventionDecoding
size_t value_size() const noexcept
Return the size of TLV-VALUE, aka TLV-LENGTH.
uint64_t toNumberWithMarker(uint8_t marker) const
Interpret this name component as NameComponentWithMarker.
bool isSequenceNumber() const
Check if the component is a sequence number per NDN naming conventions.
void setConventionEncoding(Convention convention)
Set which Naming Conventions style to use while encoding.
void toUri(std::ostream &os, UriFormat format=UriFormat::DEFAULT) const
Write *this to the output stream, escaping characters according to the NDN URI format.
int compare(const Component &other) const
Compare this to the other Component using NDN canonical ordering.
uint64_t toByteOffset() const
Interpret as byte offset component using NDN naming conventions.
element_const_iterator find(uint32_t type) const
Find the first sub-element of the specified TLV-TYPE.
Buffer::const_iterator value_end() const
Get end iterator of TLV-VALUE.
static Convention g_conventionEncoding
uint64_t toVersion() const
Interpret as version component using NDN naming conventions.
const Sha256ComponentType & getComponentType2()
uint64_t toNumber() const
Interpret this name component as nonNegativeInteger.
void setConventionDecoding(Convention convention)
Set which Naming Conventions style(s) to accept while decoding.
static Component fromParametersSha256Digest(ConstBufferPtr digest)
Create ParametersSha256DigestComponent component.
virtual void writeUri(std::ostream &os, const Component &comp) const
Write URI representation of comp to os.
a concept check for TLV abstraction with .wireDecode method and constructible from Block
EncodingImpl< EstimatorTag > EncodingEstimator
uint64_t readNonNegativeInteger(const Block &block)
Read a non-negative integer from a TLV element.
void wireDecode(const Block &wire)
Decode from the wire format.
Component getSuccessor() const
Get the successor of this name component.
uint64_t toSequenceNumber() const
Interpret as sequence number component using NDN naming conventions.
static Component fromVersion(uint64_t version)
Create version component using NDN naming conventions.
uint32_t type() const
Return the TLV-TYPE of the Block.
a concept check for TLV abstraction with .wireEncode method
@ SequenceNumNameComponent
Buffer::const_iterator value_begin() const
Get begin iterator of TLV-VALUE.
bool isVersion() const
Check if the component is a version per NDN naming conventions.
bool isNumberWithMarker(uint8_t marker) const
Check if the component is a NameComponentWithMarker per NDN naming conventions rev1.
uint64_t toSegment() const
Interpret as segment number component using NDN naming conventions.
Convention
Identify a style of NDN Naming Conventions.
bool isTimestamp() const
Check if the component is a timestamp per NDN naming conventions.
static Component parseUriEscapedValue(uint32_t type, const char *input, size_t len)
Component create(ConstBufferPtr value) const
static bool canDecodeMarkerConvention()
bool isImplicitSha256Digest() const
Check if the component is ImplicitSha256DigestComponent.
static Component fromSegment(uint64_t segmentNo)
Create segment number component using NDN naming conventions.
static Component fromSequenceNumber(uint64_t seqNo)
Create sequence number component using NDN naming conventions.
const system_clock::TimePoint & getUnixEpoch()
Get system_clock::TimePoint representing UNIX time epoch (00:00:00 on Jan 1, 1970)
Block makeNonNegativeIntegerBlock(uint32_t type, uint64_t value)
Create a TLV block containing a non-negative integer.
std::string unescape(const std::string &str)
Decode a percent-encoded string.
const Sha256ComponentType & getComponentType1()
size_t prependNonNegativeInteger(uint64_t integer) const noexcept
Prepend non-negative integer integer of NDN TLV encoding.
NDN_CXX_NODISCARD bool empty() const
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.
static bool canDecodeTypedConvention()
uint64_t readNonNegativeInteger(size_t size, Iterator &begin, Iterator end)
Read nonNegativeInteger in NDN-TLV encoding.
const Block & wireEncode() const
Encode to a wire format.
Declare rules for a NameComponent type.
@ ALTERNATE
prefer alternate format when available
time::system_clock::TimePoint toTimestamp() const
Interpret as timestamp component using NDN naming conventions.
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)
@ TYPED
typed name components (revision 2)
const ComponentType & get(uint32_t type) const
Retrieve ComponentType by TLV-TYPE.
bool hasWire() const noexcept
Check if the Block contains a fully encoded wire representation.
@ MARKER
component markers (revision 1)
static Component fromImplicitSha256Digest(ConstBufferPtr digest)
Create ImplicitSha256DigestComponent component.
virtual std::pair< bool, Component > getSuccessor(const Component &comp) const
Calculate the successor of comp.
NDN_CXX_DEFINE_WIRE_ENCODE_INSTANTIATIONS(Component)
static Component fromEscapedString(const char *input, size_t beginOffset, size_t endOffset)
Decode NameComponent from a URI component.
Component(uint32_t type=tlv::GenericNameComponent)
Construct a NameComponent of TLV-TYPE type, using empty TLV-VALUE.
@ ByteOffsetNameComponent
const uint8_t * wire() const
Return a raw pointer to the beginning of the encoded wire.
bool isParametersSha256Digest() const
Check if the component is ParametersSha256DigestComponent.
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
constexpr std::underlying_type_t< T > to_underlying(T val) noexcept
a concept check for TLV abstraction with .wireEncode method
Block makeStringBlock(uint32_t type, const std::string &value)
Create a TLV block containing a string.
Copyright (c) 2011-2015 Regents of the University of California.
EncodingImpl< EncoderTag > EncodingBuffer
bool match(const Component &comp) const
virtual void check(const Component &comp) const
Throw Component::Error if comp is invalid.
UriFormat
Identify a format of URI representation.
Convention getConventionDecoding()
Return which Naming Conventions style(s) to accept while decoding.