ndn::MetaInfo Class Reference

A MetaInfo holds the meta info which is signed inside the Data packet. More...

#include <ndn-cxx/meta-info.hpp>

Classes

class  Error
 

Public Member Functions

 MetaInfo ()
 
 MetaInfo (const Block &block)
 Create from wire encoding. More...
 
MetaInfoaddAppMetaInfo (const Block &block)
 Add an app-defined MetaInfo item. More...
 
const BlockfindAppMetaInfo (uint32_t tlvType) const
 Find a first app-defined MetaInfo item of type tlvType. More...
 
const std::list< Block > & getAppMetaInfo () const
 Get all app-defined MetaInfo items. More...
 
const std::optional< name::Component > & getFinalBlock () const noexcept
 Return the value of FinalBlockId. More...
 
time::milliseconds getFreshnessPeriod () const noexcept
 Return the value of FreshnessPeriod. More...
 
uint32_t getType () const noexcept
 Return the value of ContentType. More...
 
bool removeAppMetaInfo (uint32_t tlvType)
 Remove a first app-defined MetaInfo item with type tlvType. More...
 
MetaInfosetAppMetaInfo (const std::list< Block > &info)
 Set app-defined MetaInfo items. More...
 
MetaInfosetFinalBlock (std::optional< name::Component > finalBlockId)
 Set the FinalBlockId. More...
 
MetaInfosetFreshnessPeriod (time::milliseconds freshnessPeriod)
 Set the FreshnessPeriod. More...
 
MetaInfosetType (uint32_t type)
 Set the ContentType. More...
 
void wireDecode (const Block &wire)
 
const BlockwireEncode () const
 
template<encoding::Tag TAG>
size_t wireEncode (EncodingImpl< TAG > &encoder) const
 

Detailed Description

A MetaInfo holds the meta info which is signed inside the Data packet.

The class allows experimentation with application-defined meta-information elements. When using these application-defined elements, be aware that it may result in dropped packets (NFD and previous versions of ndn-cxx will gracefully accept such packets).

The following definition of the MetaInfo element is assumed in this implementation (compared to the NDN packet spec, the definition is extended to allow optional AppMetaInfo elements):

MetaInfo = META-INFO-TYPE TLV-LENGTH
             [ContentType]
             [FreshnessPeriod]
             [FinalBlockId]
             *AppMetaInfo

Note that AppMetaInfo elements are application-defined and must have a TLV-TYPE inside the range reserved for application use, i.e., [128, 252].

See also
https://docs.named-data.net/NDN-packet-spec/0.3/data.html#metainfo

Definition at line 61 of file meta-info.hpp.

Constructor & Destructor Documentation

◆ MetaInfo() [1/2]

ndn::MetaInfo::MetaInfo ( )
default

◆ MetaInfo() [2/2]

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

Create from wire encoding.

Definition at line 32 of file meta-info.cpp.

Member Function Documentation

◆ addAppMetaInfo()

MetaInfo & ndn::MetaInfo::addAppMetaInfo ( const Block block)

Add an app-defined MetaInfo item.

Exceptions
Errorif block has type not in the application range (https://docs.named-data.net/NDN-packet-spec/0.3/types.html)
Note
If MetaInfo is decoded from wire and setType, setFreshnessPeriod, or setFinalBlock is called before *AppMetaInfo, all app-defined blocks will be lost

Definition at line 93 of file meta-info.cpp.

◆ findAppMetaInfo()

const Block * ndn::MetaInfo::findAppMetaInfo ( uint32_t  tlvType) const

Find a first app-defined MetaInfo item of type tlvType.

Returns
NULL if an item is not found, otherwise const pointer to the item
Exceptions
Errorif tlvType is not in the application range (https://docs.named-data.net/NDN-packet-spec/0.3/types.html)
Note
If MetaInfo is decoded from wire and setType, setFreshnessPeriod, or setFinalBlock is called before *AppMetaInfo, all app-defined blocks will be lost

Definition at line 117 of file meta-info.cpp.

◆ getAppMetaInfo()

const std::list< Block > & ndn::MetaInfo::getAppMetaInfo ( ) const

Get all app-defined MetaInfo items.

Note
If MetaInfo is decoded from wire and setType, setFreshnessPeriod, or setFinalBlock is called before *AppMetaInfo, all app-defined blocks will be lost

Definition at line 74 of file meta-info.cpp.

◆ getFinalBlock()

const std::optional<name::Component>& ndn::MetaInfo::getFinalBlock ( ) const
inlinenoexcept

Return the value of FinalBlockId.

Definition at line 128 of file meta-info.hpp.

◆ getFreshnessPeriod()

time::milliseconds ndn::MetaInfo::getFreshnessPeriod ( ) const
noexcept

Return the value of FreshnessPeriod.

If the FreshnessPeriod element is not present, returns DEFAULT_FRESHNESS_PERIOD. If the FreshnessPeriod value is not representable in the return type, it's clamped to the nearest representable value.

Definition at line 46 of file meta-info.cpp.

◆ getType()

uint32_t ndn::MetaInfo::getType ( ) const
inlinenoexcept

Return the value of ContentType.

If the ContentType element is not present, returns tlv::ContentType_Blob.

Definition at line 95 of file meta-info.hpp.

◆ removeAppMetaInfo()

bool ndn::MetaInfo::removeAppMetaInfo ( uint32_t  tlvType)

Remove a first app-defined MetaInfo item with type tlvType.

Returns
true if an item was deleted
Note
If MetaInfo is decoded from wire and setType, setFreshnessPeriod, or setFinalBlock is called before *AppMetaInfo, all app-defined blocks will be lost

Definition at line 104 of file meta-info.cpp.

◆ setAppMetaInfo()

MetaInfo & ndn::MetaInfo::setAppMetaInfo ( const std::list< Block > &  info)

Set app-defined MetaInfo items.

This method will replace all existing app-defined MetaInfo items, if they existed.

Exceptions
Errorif some block in info has type not in the application range (https://docs.named-data.net/NDN-packet-spec/0.3/types.html)
Note
If MetaInfo is decoded from wire and setType, setFreshnessPeriod, or setFinalBlock is called before *AppMetaInfo, all app-defined blocks will be lost

Definition at line 80 of file meta-info.cpp.

◆ setFinalBlock()

MetaInfo & ndn::MetaInfo::setFinalBlock ( std::optional< name::Component finalBlockId)

Set the FinalBlockId.

Definition at line 66 of file meta-info.cpp.

◆ setFreshnessPeriod()

MetaInfo & ndn::MetaInfo::setFreshnessPeriod ( time::milliseconds  freshnessPeriod)

Set the FreshnessPeriod.

Exceptions
std::invalid_argumentspecified FreshnessPeriod is negative.

Definition at line 55 of file meta-info.cpp.

◆ setType()

MetaInfo & ndn::MetaInfo::setType ( uint32_t  type)

Set the ContentType.

Parameters
typeA number defined in tlv::ContentTypeValue

Definition at line 38 of file meta-info.cpp.

◆ wireDecode()

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

Definition at line 180 of file meta-info.cpp.

◆ wireEncode() [1/2]

const Block & ndn::MetaInfo::wireEncode ( ) const

Definition at line 164 of file meta-info.cpp.

◆ wireEncode() [2/2]

template<encoding::Tag TAG>
size_t ndn::MetaInfo::wireEncode ( EncodingImpl< TAG > &  encoder) const

Definition at line 126 of file meta-info.cpp.