ndn::Link Class Reference

represents a Link instance More...

#include <link.hpp>

Inheritance diagram for ndn::Link:
[legend]
Collaboration diagram for ndn::Link:
[legend]

Data Structures

class  Error
 

Public Types

typedef std::set< std::pair< uint32_t, Name > > DelegationSet
 

Public Member Functions

 Link ()=default
 Create an empty Link object. More...
 
 Link (const Block &block)
 Create a Link object from a Block. More...
 
 Link (const Name &name)
 Create a Link object with the given name. More...
 
 Link (const Name &name, std::initializer_list< std::pair< uint32_t, Name >> links)
 Create a Link object with the given name and pairs of <Preference, Name> More...
 
void addDelegation (uint32_t preference, const Name &name)
 Add a delegation in the format of <Name, Preference> More...
 
bool removeDelegation (const Name &name)
 Remove a delegation whose name is name. More...
 
const DelegationSetgetDelegations () const
 Get the pairs of <Name, Preference> More...
 
void wireDecode (const Block &wire)
 Decode from the wire format. More...
 
template<encoding::Tag TAG>
size_t wireEncode (EncodingImpl< TAG > &encoder, bool wantUnsignedPortionOnly=false) const
 Fast encoding or block size estimation. More...
 
const BlockwireEncode () const
 Encode to a wire format. More...
 
const BlockwireEncode (EncodingBuffer &encoder, const Block &signatureValue) const
 Finalize Data packet encoding with the specified SignatureValue. More...
 
bool hasWire () const
 Check if Data is already has wire encoding. More...
 
const NamegetName () const
 Get name of the Data packet. More...
 
DatasetName (const Name &name)
 Set name to a copy of the given Name. More...
 
const NamegetFullName () const
 Get full name of Data packet, including the implicit digest. More...
 
const MetaInfogetMetaInfo () const
 Get MetaInfo block from Data packet. More...
 
DatasetMetaInfo (const MetaInfo &metaInfo)
 Set metaInfo to a copy of the given MetaInfo. More...
 
uint32_t getContentType () const
 
DatasetContentType (uint32_t type)
 
const time::milliseconds & getFreshnessPeriod () const
 
DatasetFreshnessPeriod (const time::milliseconds &freshnessPeriod)
 
const name::ComponentgetFinalBlockId () const
 
DatasetFinalBlockId (const name::Component &finalBlockId)
 
const BlockgetContent () const
 Get content Block. More...
 
DatasetContent (const uint8_t *buffer, size_t bufferSize)
 Set the content from the buffer (buffer will be copied) More...
 
DatasetContent (const Block &block)
 Set the content from the block. More...
 
DatasetContent (const ConstBufferPtr &contentValue)
 Set the content from the pointer to immutable buffer. More...
 
const SignaturegetSignature () const
 
DatasetSignature (const Signature &signature)
 Set the signature to a copy of the given signature. More...
 
DatasetSignatureValue (const Block &value)
 
bool operator== (const Data &other) const
 
bool operator!= (const Data &other) const
 
template<typename T >
shared_ptr< T > getTag () const
 get a tag item More...
 
template<typename T >
void setTag (shared_ptr< T > tag) const
 set a tag item More...
 
template<typename T >
void removeTag () const
 remove tag item More...
 

Static Public Member Functions

static std::tuple< uint32_t, NamegetDelegationFromWire (const Block &block, size_t index)
 gets the delegation at index from block More...
 
static ssize_t findDelegationFromWire (const Block &block, const Name &delegationName)
 finds index of a delegation with delegationName from block More...
 
static ssize_t countDelegationsFromWire (const Block &block)
 

Protected Member Functions

template<encoding::Tag TAG>
size_t encodeContent (EncodingImpl< TAG > &encoder) const
 prepend Link object as a Content block to the encoder More...
 
void encodeContent ()
 
void decodeContent ()
 
void onChanged ()
 Clear the wire encoding. More...
 

Detailed Description

represents a Link instance

Definition at line 34 of file link.hpp.

Member Typedef Documentation

typedef std::set<std::pair<uint32_t, Name> > ndn::Link::DelegationSet

Definition at line 48 of file link.hpp.

Constructor & Destructor Documentation

ndn::Link::Link ( )
default

Create an empty Link object.

Note that in certain contexts that use Link::shared_from_this(), Link must be created using make_shared:

shared_ptr<Link> linkObject = make_shared<Link>();

Otherwise, Link::shared_from_this() will throw std::bad_weak_ptr.

ndn::Link::Link ( const Block block)
explicit

Create a Link object from a Block.

Note that in certain contexts that use Link::shared_from_this(), Link must be created using make_shared:

shared_ptr<Link> linkObject = make_shared<Link>(block);

Otherwise, Link::shared_from_this() will throw std::bad_weak_ptr.

Definition at line 41 of file link.cpp.

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

Create a Link object with the given name.

Parameters
nameA reference to the name of the redirected namespace

Note that in certain contexts that use Link::shared_from_this(), Link must be created using make_shared:

shared_ptr<Link> link = make_shared<Link>(name);

Otherwise, Link::shared_from_this() will throw std::bad_weak_ptr.

Definition at line 46 of file link.cpp.

ndn::Link::Link ( const Name name,
std::initializer_list< std::pair< uint32_t, Name >>  links 
)

Create a Link object with the given name and pairs of <Preference, Name>

Parameters
nameA reference to the name of the redirected namespace
linksA reference to the list of pairs of the redirected namespace along with its priority

Note that in certain contexts that use Link::shared_from_this(), Link must be created using make_shared:

shared_ptr<Link> link = make_shared<Link>(name, links);

Otherwise, Link::shared_from_this() will throw std::bad_weak_ptr.

Definition at line 51 of file link.cpp.

Member Function Documentation

void ndn::Link::addDelegation ( uint32_t  preference,
const Name name 
)

Add a delegation in the format of <Name, Preference>

Parameters
preferenceThe preference of the delegation to be added
nameThe name of the delegation to be added
Note
If a delegation with name exists, its preference will be updated

Definition at line 59 of file link.cpp.

ssize_t ndn::Link::countDelegationsFromWire ( const Block block)
static

Definition at line 221 of file link.cpp.

void ndn::Link::decodeContent ( )
protected

Definition at line 133 of file link.cpp.

template<encoding::Tag TAG>
size_t ndn::Link::encodeContent ( EncodingImpl< TAG > &  encoder) const
protected

prepend Link object as a Content block to the encoder

The outermost Content element is not part of Link object structure.

Definition at line 84 of file link.cpp.

void ndn::Link::encodeContent ( )
protected

Definition at line 118 of file link.cpp.

ssize_t ndn::Link::findDelegationFromWire ( const Block block,
const Name delegationName 
)
static

finds index of a delegation with delegationName from block

Parameters
blockwire format of a Link object
delegationNamedelegation name in the Link object
Returns
0-based index of the first delegation with delegationName , or -1 if no such delegation exists

Definition at line 200 of file link.cpp.

const Block & ndn::Data::getContent ( ) const
inherited

Get content Block.

To access content value, one can use value()/value_size() or value_begin()/value_end() methods of the Block class

Definition at line 230 of file data.cpp.

uint32_t ndn::Data::getContentType ( ) const
inlineinherited

Definition at line 330 of file data.hpp.

std::tuple< uint32_t, Name > ndn::Link::getDelegationFromWire ( const Block block,
size_t  index 
)
static

gets the delegation at index from block

Parameters
blockwire format of a Link object
index0-based index of a delegation in the Link object
Returns
delegation preference and name
Exceptions
std::out_of_rangeindex is out of range

Definition at line 183 of file link.cpp.

const Link::DelegationSet & ndn::Link::getDelegations ( ) const

Get the pairs of <Name, Preference>

Returns
a set of delegations

Definition at line 77 of file link.cpp.

const name::Component & ndn::Data::getFinalBlockId ( ) const
inlineinherited

Definition at line 342 of file data.hpp.

const time::milliseconds & ndn::Data::getFreshnessPeriod ( ) const
inlineinherited

Definition at line 336 of file data.hpp.

const Name & ndn::Data::getFullName ( ) const
inherited

Get full name of Data packet, including the implicit digest.

Exceptions
Errorif Data packet doesn't have a full name yet (wire encoding has not been yet created)

Definition at line 179 of file data.cpp.

const MetaInfo & ndn::Data::getMetaInfo ( ) const
inlineinherited

Get MetaInfo block from Data packet.

Definition at line 324 of file data.hpp.

const Name & ndn::Data::getName ( ) const
inlineinherited

Get name of the Data packet.

Definition at line 318 of file data.hpp.

const Signature & ndn::Data::getSignature ( ) const
inlineinherited

Definition at line 348 of file data.hpp.

template<typename T >
shared_ptr< T > ndn::TagHost::getTag ( ) const
inlineinherited

get a tag item

Template Parameters
Ttype of the tag, which must be a subclass of ndn::Tag
Return values
nullptrif no Tag of type T is stored

Definition at line 67 of file tag-host.hpp.

bool ndn::Data::hasWire ( ) const
inlineinherited

Check if Data is already has wire encoding.

Definition at line 312 of file data.hpp.

void ndn::Data::onChanged ( )
protectedinherited

Clear the wire encoding.

Definition at line 293 of file data.cpp.

bool ndn::Data::operator!= ( const Data other) const
inherited

Definition at line 314 of file data.cpp.

bool ndn::Data::operator== ( const Data other) const
inherited

Definition at line 305 of file data.cpp.

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

Remove a delegation whose name is name.

Parameters
nameThe name of the delegation to be removed
Returns
true if delegation is removed, otherwise false

Definition at line 67 of file link.cpp.

template<typename T >
void ndn::TagHost::removeTag ( ) const
inlineinherited

remove tag item

Note
Tag can be removed even on a const tag host instance

Definition at line 94 of file tag-host.hpp.

Data & ndn::Data::setContent ( const uint8_t *  buffer,
size_t  bufferSize 
)
inherited

Set the content from the buffer (buffer will be copied)

Parameters
bufferPointer to first byte of the buffer
bufferSizeSize of the buffer
Returns
This Data so that you can chain calls to update values.

Definition at line 241 of file data.cpp.

Data & ndn::Data::setContent ( const Block block)
inherited

Set the content from the block.

Depending on type of the supplied block, there are two cases:

  • if block.type() == tlv::Content, then block will be used directly as Data packet's content (no extra copying)
  • if block.type() != tlv::Content, then this method will create a new Block with type tlv::Content and put block as a nested element in the content Block.
Parameters
blockThe Block containing the content to assign
Returns
This Data so that you can chain calls to update values.

Definition at line 261 of file data.cpp.

Data & ndn::Data::setContent ( const ConstBufferPtr contentValue)
inherited

Set the content from the pointer to immutable buffer.

This method will create a Block with tlv::Content and set contentValue as a payload for this block. Note that this method is very different from setContent(const Block&), since it does not require that payload should be a valid TLV element.

Parameters
contentValueThe pointer to immutable buffer containing the content to assign
Returns
This Data so that you can chain calls to update values.

Definition at line 251 of file data.cpp.

Data & ndn::Data::setContentType ( uint32_t  type)
inherited

Definition at line 203 of file data.cpp.

Data & ndn::Data::setFinalBlockId ( const name::Component finalBlockId)
inherited

Definition at line 221 of file data.cpp.

Data & ndn::Data::setFreshnessPeriod ( const time::milliseconds &  freshnessPeriod)
inherited

Definition at line 212 of file data.cpp.

Data & ndn::Data::setMetaInfo ( const MetaInfo metaInfo)
inherited

Set metaInfo to a copy of the given MetaInfo.

Returns
This Data so that you can chain calls to update values.

Definition at line 194 of file data.cpp.

Data & ndn::Data::setName ( const Name name)
inherited

Set name to a copy of the given Name.

Returns
This Data so that you can chain calls to update values

Definition at line 170 of file data.cpp.

Data & ndn::Data::setSignature ( const Signature signature)
inherited

Set the signature to a copy of the given signature.

Parameters
signatureThe signature object which is cloned.

Definition at line 275 of file data.cpp.

Data & ndn::Data::setSignatureValue ( const Block value)
inherited

Definition at line 284 of file data.cpp.

template<typename T >
void ndn::TagHost::setTag ( shared_ptr< T >  tag) const
inlineinherited

set a tag item

Template Parameters
Ttype of the tag, which must be a subclass of ndn::Tag
Note
Tag can be set even on a const tag host instance

Definition at line 80 of file tag-host.hpp.

void ndn::Link::wireDecode ( const Block wire)

Decode from the wire format.

Warning
This method does not preserve the relative order between delegations. To get a delegation by index, use getDelegationFromWire method.

Definition at line 176 of file link.cpp.

template<encoding::Tag TAG>
size_t ndn::Data::wireEncode ( EncodingImpl< TAG > &  encoder,
bool  wantUnsignedPortionOnly = false 
) const
inherited

Fast encoding or block size estimation.

Parameters
encoderEncodingEstimator or EncodingBuffer instance
wantUnsignedPortionOnlyRequest only unsigned portion to be encoded in block. If true, only Name, MetaInfo, Content, and SignatureInfo blocks will be encoded into the block. Note that there will be no outer TLV header of the Data packet.

Definition at line 52 of file data.cpp.

const Block & ndn::Data::wireEncode ( ) const
inherited

Encode to a wire format.

Definition at line 119 of file data.cpp.

const Block & ndn::Data::wireEncode ( EncodingBuffer &  encoder,
const Block signatureValue 
) const
inherited

Finalize Data packet encoding with the specified SignatureValue.

Parameters
encoderEncodingBuffer instance, containing Name, MetaInfo, Content, and SignatureInfo (without outer TLV header of the Data packet).
signatureValueSignatureValue block to be added to Data packet to finalize the wire encoding

This method is intended to be used in concert with Data::wireEncode(EncodingBuffer&, true) method to optimize Data packet wire format creation:

Data data;
...
EncodingBuffer encoder;
data.wireEncode(encoder, true);
...
Block signatureValue = <sign_over_unsigned_portion>(encoder.buf(), encoder.size());
data.wireEncode(encoder, signatureValue)

Definition at line 106 of file data.cpp.