All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
ndn::Block Class Reference

Class representing wire element of the NDN packet. More...

#include <block.hpp>

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

Data Structures

class  Error
 Error that can be thrown from Block. More...
 

Public Types

typedef std::vector< Blockelement_container
 
typedef element_container::iterator element_iterator
 
typedef
element_container::const_iterator 
element_const_iterator
 

Public Member Functions

 Block ()
 Default constructor to create an empty Block. More...
 
 Block (const EncodingBuffer &buffer)
 Create block based on EncodingBuffer object. More...
 
 Block (const ConstBufferPtr &buffer)
 A helper version of a constructor to create Block from the raw buffer (type and value-length parsing) More...
 
 Block (const ConstBufferPtr &buffer, const Buffer::const_iterator &begin, const Buffer::const_iterator &end, bool verifyLength=true)
 Another helper to create block from a buffer, directly specifying boundaries of the block within the buffer. More...
 
 Block (const uint8_t *buffer, size_t maxlength)
 A helper version of a constructor to create Block from the raw buffer (type and value-length parsing) More...
 
 Block (const void *buffer, size_t maxlength)
 
 Block (std::istream &is)
 
 Block (const ConstBufferPtr &wire, uint32_t type, const Buffer::const_iterator &begin, const Buffer::const_iterator &end, const Buffer::const_iterator &valueBegin, const Buffer::const_iterator &valueEnd)
 Create Block from the wire buffer (no parsing) More...
 
 Block (uint32_t type)
 Create Block of a specific type with empty wire buffer. More...
 
 Block (uint32_t type, const ConstBufferPtr &value)
 Create Block of a specific type with the specified value. More...
 
 Block (uint32_t type, const Block &value)
 Create nested Block of a specific type with the specified value. More...
 
bool empty () const
 Check if the Block is empty. More...
 
bool hasWire () const
 Check if the Block has fully encoded wire. More...
 
bool hasValue () const
 Check if the Block has value block (no type and length are encoded) More...
 
void reset ()
 Reset wire buffer of the element. More...
 
void resetWire ()
 Reset wire buffer but keep sub elements (if any) More...
 
void parse () const
 Parse wire buffer into subblocks. More...
 
void encode ()
 Encode subblocks into wire buffer. More...
 
uint32_t type () const
 
const Blockget (uint32_t type) const
 Get the first subelement of the requested type. More...
 
element_const_iterator find (uint32_t type) const
 
void remove (uint32_t type)
 
element_iterator erase (element_iterator position)
 
element_iterator erase (element_iterator first, element_iterator last)
 
void push_back (const Block &element)
 
Buffer::const_iterator begin () const
 
Buffer::const_iterator end () const
 
const uint8_t * wire () const
 
size_t size () const
 
Buffer::const_iterator value_begin () const
 
Buffer::const_iterator value_end () const
 
const uint8_t * value () const
 
size_t value_size () const
 
const element_containerelements () const
 Get all subelements. More...
 
element_const_iterator elements_begin () const
 
element_const_iterator elements_end () const
 
size_t elements_size () const
 
Block blockFromValue () const
 
bool operator== (const Block &other) const
 
bool operator!= (const Block &other) const
 

Static Public Member Functions

static bool fromBuffer (const ConstBufferPtr &wire, size_t offset, Block &block)
 Try to construct block from Buffer, referencing data block pointed by wire. More...
 
static bool fromBuffer (const uint8_t *buffer, size_t maxSize, Block &block)
 Try to construct block from Buffer, referencing data block pointed by wire. More...
 

Protected Attributes

ConstBufferPtr m_buffer
 
uint32_t m_type
 
Buffer::const_iterator m_begin
 
Buffer::const_iterator m_end
 
uint32_t m_size
 
Buffer::const_iterator m_value_begin
 
Buffer::const_iterator m_value_end
 
element_container m_subBlocks
 

Friends

class EncodingImpl< true >
 

Detailed Description

Class representing wire element of the NDN packet.

Definition at line 26 of file block.hpp.

Member Typedef Documentation

typedef element_container::const_iterator ndn::Block::element_const_iterator

Definition at line 31 of file block.hpp.

typedef std::vector<Block> ndn::Block::element_container

Definition at line 29 of file block.hpp.

typedef element_container::iterator ndn::Block::element_iterator

Definition at line 30 of file block.hpp.

Constructor & Destructor Documentation

ndn::Block::Block ( )

Default constructor to create an empty Block.

Definition at line 18 of file block.cpp.

ndn::Block::Block ( const EncodingBuffer buffer)
explicit

Create block based on EncodingBuffer object.

Definition at line 23 of file block.cpp.

ndn::Block::Block ( const ConstBufferPtr buffer)

A helper version of a constructor to create Block from the raw buffer (type and value-length parsing)

This constructor provides ability of implicit conversion from ConstBufferPtr to Block

Definition at line 54 of file block.cpp.

ndn::Block::Block ( const ConstBufferPtr buffer,
const Buffer::const_iterator &  begin,
const Buffer::const_iterator &  end,
bool  verifyLength = true 
)

Another helper to create block from a buffer, directly specifying boundaries of the block within the buffer.

This version will automatically detect type and position of the value within the block

Definition at line 72 of file block.cpp.

ndn::Block::Block ( const uint8_t *  buffer,
size_t  maxlength 
)

A helper version of a constructor to create Block from the raw buffer (type and value-length parsing)

Definition at line 133 of file block.cpp.

ndn::Block::Block ( const void *  buffer,
size_t  maxlength 
)

Definition at line 156 of file block.cpp.

ndn::Block::Block ( std::istream &  is)
explicit

Definition at line 94 of file block.cpp.

ndn::Block::Block ( const ConstBufferPtr wire,
uint32_t  type,
const Buffer::const_iterator &  begin,
const Buffer::const_iterator &  end,
const Buffer::const_iterator &  valueBegin,
const Buffer::const_iterator &  valueEnd 
)

Create Block from the wire buffer (no parsing)

This version of the constructor does not do any parsing

Definition at line 40 of file block.cpp.

ndn::Block::Block ( uint32_t  type)
explicit

Create Block of a specific type with empty wire buffer.

Definition at line 181 of file block.cpp.

ndn::Block::Block ( uint32_t  type,
const ConstBufferPtr value 
)

Create Block of a specific type with the specified value.

The underlying buffer hold only value, additional operations are needed to construct wire encoding, one need to prepend the wire buffer with type and value-length VAR-NUMBERs

Definition at line 186 of file block.cpp.

ndn::Block::Block ( uint32_t  type,
const Block value 
)
explicit

Create nested Block of a specific type with the specified value.

The underlying buffer hold only value, additional operations are needed to construct wire encoding, one need to prepend the wire buffer with type and value-length VAR-NUMBERs

Definition at line 197 of file block.cpp.

Member Function Documentation

Buffer::const_iterator ndn::Block::begin ( ) const
inline

Definition at line 397 of file block.hpp.

Block ndn::Block::blockFromValue ( ) const

Definition at line 352 of file block.cpp.

const Block::element_container & ndn::Block::elements ( ) const
inline

Get all subelements.

Definition at line 464 of file block.hpp.

Block::element_const_iterator ndn::Block::elements_begin ( ) const
inline

Definition at line 470 of file block.hpp.

Block::element_const_iterator ndn::Block::elements_end ( ) const
inline

Definition at line 476 of file block.hpp.

size_t ndn::Block::elements_size ( ) const
inline

Definition at line 482 of file block.hpp.

bool ndn::Block::empty ( ) const
inline

Check if the Block is empty.

Definition at line 281 of file block.hpp.

void ndn::Block::encode ( )

Encode subblocks into wire buffer.

Definition at line 298 of file block.cpp.

Buffer::const_iterator ndn::Block::end ( ) const
inline

Definition at line 406 of file block.hpp.

Block::element_iterator ndn::Block::erase ( Block::element_iterator  position)
inline

Definition at line 375 of file block.hpp.

Block::element_iterator ndn::Block::erase ( Block::element_iterator  first,
Block::element_iterator  last 
)
inline

Definition at line 382 of file block.hpp.

Block::element_const_iterator ndn::Block::find ( uint32_t  type) const
inline

Definition at line 343 of file block.hpp.

bool ndn::Block::fromBuffer ( const ConstBufferPtr wire,
size_t  offset,
Block block 
)
static

Try to construct block from Buffer, referencing data block pointed by wire.

Exceptions
Thismethod never throws an exception
Returns
true if Block successfully created, false if block cannot be created

Definition at line 209 of file block.cpp.

bool ndn::Block::fromBuffer ( const uint8_t *  buffer,
size_t  maxSize,
Block block 
)
static

Try to construct block from Buffer, referencing data block pointed by wire.

Exceptions
Thismethod never throws an exception
Returns
true if Block successfully created, false if block cannot be created

Definition at line 236 of file block.cpp.

const Block & ndn::Block::get ( uint32_t  type) const
inline

Get the first subelement of the requested type.

Definition at line 326 of file block.hpp.

bool ndn::Block::hasValue ( ) const
inline

Check if the Block has value block (no type and length are encoded)

Definition at line 294 of file block.hpp.

bool ndn::Block::hasWire ( ) const
inline

Check if the Block has fully encoded wire.

Definition at line 288 of file block.hpp.

bool ndn::Block::operator!= ( const Block other) const
inline

Definition at line 495 of file block.hpp.

bool ndn::Block::operator== ( const Block other) const
inline

Definition at line 488 of file block.hpp.

void ndn::Block::parse ( ) const

Parse wire buffer into subblocks.

This method is not really const, but it does not modify any data. It simply parses contents of the buffer into subblocks

Definition at line 265 of file block.cpp.

void ndn::Block::push_back ( const Block element)
inline

Definition at line 390 of file block.hpp.

void ndn::Block::remove ( uint32_t  type)
inline

Definition at line 358 of file block.hpp.

void ndn::Block::reset ( )
inline

Reset wire buffer of the element.

Definition at line 300 of file block.hpp.

void ndn::Block::resetWire ( )
inline

Reset wire buffer but keep sub elements (if any)

Definition at line 310 of file block.hpp.

size_t ndn::Block::size ( ) const
inline

Definition at line 415 of file block.hpp.

uint32_t ndn::Block::type ( ) const
inline

Definition at line 320 of file block.hpp.

const uint8_t * ndn::Block::value ( ) const
inline

Definition at line 446 of file block.hpp.

Buffer::const_iterator ndn::Block::value_begin ( ) const
inline

Definition at line 425 of file block.hpp.

Buffer::const_iterator ndn::Block::value_end ( ) const
inline

Definition at line 431 of file block.hpp.

size_t ndn::Block::value_size ( ) const
inline

Definition at line 455 of file block.hpp.

const uint8_t * ndn::Block::wire ( ) const
inline

Definition at line 437 of file block.hpp.

Friends And Related Function Documentation

friend class EncodingImpl< true >
friend

Definition at line 273 of file block.hpp.

Field Documentation

Buffer::const_iterator ndn::Block::m_begin
protected

Definition at line 265 of file block.hpp.

ConstBufferPtr ndn::Block::m_buffer
protected

Definition at line 261 of file block.hpp.

Buffer::const_iterator ndn::Block::m_end
protected

Definition at line 266 of file block.hpp.

uint32_t ndn::Block::m_size
protected

Definition at line 267 of file block.hpp.

element_container ndn::Block::m_subBlocks
mutableprotected

Definition at line 272 of file block.hpp.

uint32_t ndn::Block::m_type
protected

Definition at line 263 of file block.hpp.

Buffer::const_iterator ndn::Block::m_value_begin
protected

Definition at line 269 of file block.hpp.

Buffer::const_iterator ndn::Block::m_value_end
protected

Definition at line 270 of file block.hpp.