ndn-embeds 0.1.0
Lightweight NDN protocol stack for embedded systems
Loading...
Searching...
No Matches
ndn::Link Class Reference

NDN Link Object. More...

#include <ndn/link.hpp>

Public Member Functions

 Link ()=default
 Default constructor.
 
 Link (const Name &name)
 Create a Link with a specified Name.
 
Delegation management
Error addDelegation (const Name &delegation)
 Add a delegation (Name)
 
Error addDelegation (std::string_view uri)
 Add a delegation from a URI string.
 
size_t delegationCount () const
 Get the number of delegations.
 
const Namedelegation (size_t index) const
 Get a delegation by index.
 
void clearDelegations ()
 Clear all delegations.
 
bool hasDelegation (const Name &name) const
 Check if a given Name is in the delegation list.
 
Name access
const Namename () const
 Get the Name (const reference)
 
Namename ()
 Get the Name (reference)
 
LinksetName (const Name &name)
 Set the Name.
 
Error setName (std::string_view uri)
 Set the Name from a URI string.
 

Conversion to Data

Error toData (Data &data) const
 Convert the Link to a Data packet.
 
static Result< LinkfromData (const Data &data)
 Decode a Link from a Data packet.
 

Detailed Description

NDN Link Object.

A Link Object is a special Data packet with ContentType=LINK, containing one or more Names (delegations) in its Content field. Provides a list of Names sorted by producer priority.

// Create a Link
ndn::Link link;
link.setName("/example/link");
link.addDelegation("/ndn/jp/provider1");
link.addDelegation("/ndn/us/provider2");
// Encode to Data
ndn::Data data = link.toData();
// Decode
auto result = ndn::Link::fromData(data);
if (result.ok()) {
for (size_t i = 0; i < result.value.delegationCount(); ++i) {
auto delegation = result.value.delegation(i);
if (delegation) {
// Use delegation->toUri(...)
}
}
}
NDN Data packet.
Definition data.hpp:49
Error signWithDigestSha256()
Sign with DigestSha256.
Definition data.cpp:169

Definition at line 49 of file link.hpp.

Constructor & Destructor Documentation

◆ Link() [1/2]

ndn::Link::Link ( )
default

Default constructor.

Creates an empty Link.

◆ Link() [2/2]

ndn::Link::Link ( const Name name)
explicit

Create a Link with a specified Name.

Parameters
nameThe Link name

Definition at line 7 of file link.cpp.

Member Function Documentation

◆ addDelegation() [1/2]

Error ndn::Link::addDelegation ( const Name delegation)

Add a delegation (Name)

Add in order of producer priority. The first added has the highest priority.

Parameters
delegationName to add
Returns
Error::Success on success, Error::Full when at capacity, Error::InvalidParam on duplicate

Definition at line 23 of file link.cpp.

References delegation(), and ndn::LINK_MAX_DELEGATIONS.

Referenced by addDelegation(), and fromData().

◆ addDelegation() [2/2]

Error ndn::Link::addDelegation ( std::string_view  uri)

Add a delegation from a URI string.

Parameters
uriURI string (e.g., "/ndn/jp/provider")
Returns
Error::Success on success

Definition at line 39 of file link.cpp.

References addDelegation(), and ndn::Name::fromUri().

◆ clearDelegations()

void ndn::Link::clearDelegations ( )

Clear all delegations.

Definition at line 54 of file link.cpp.

◆ delegation()

const Name * ndn::Link::delegation ( size_t  index) const

Get a delegation by index.

Parameters
indexDelegation index (starting from 0)
Returns
Pointer to the Name at the given index, nullptr if out of range

Definition at line 47 of file link.cpp.

Referenced by addDelegation().

◆ delegationCount()

size_t ndn::Link::delegationCount ( ) const
inline

Get the number of delegations.

Returns
Number of delegations

Definition at line 91 of file link.hpp.

◆ fromData()

Result< Link > ndn::Link::fromData ( const Data data)
static

◆ hasDelegation()

bool ndn::Link::hasDelegation ( const Name name) const

Check if a given Name is in the delegation list.

Parameters
nameName to check
Returns
true if present

Definition at line 58 of file link.cpp.

References name().

◆ name() [1/2]

Name & ndn::Link::name ( )
inline

Get the Name (reference)

Returns
Reference to the Name

Definition at line 128 of file link.hpp.

◆ name() [2/2]

const Name & ndn::Link::name ( ) const
inline

Get the Name (const reference)

Returns
Const reference to the Name

Definition at line 122 of file link.hpp.

Referenced by hasDelegation(), and setName().

◆ setName() [1/2]

Link & ndn::Link::setName ( const Name name)

Set the Name.

Parameters
nameName to set
Returns
Reference to this Link

Definition at line 9 of file link.cpp.

References name().

◆ setName() [2/2]

Error ndn::Link::setName ( std::string_view  uri)

Set the Name from a URI string.

Parameters
uriURI string
Returns
Error::Success on success

Definition at line 14 of file link.cpp.

References ndn::Name::fromUri().

◆ toData()

Error ndn::Link::toData ( Data data) const

Convert the Link to a Data packet.

Generates a Data packet with ContentType=LINK. The Content contains the encoded delegations (list of Names). Signing is not performed by this method.

Parameters
dataOutput Data
Returns
Error::Success on success

Definition at line 67 of file link.cpp.

References ndn::TlvEncoder::current(), ndn::DATA_MAX_CONTENT_SIZE, ndn::TlvEncoder::position(), ndn::TlvEncoder::remaining(), ndn::Data::setContent(), ndn::Data::setContentType(), ndn::Data::setName(), ndn::TlvEncoder::setPosition(), and ndn::TlvEncoder::size().


The documentation for this class was generated from the following files: