Represents a TLV element of NDN packet format. More...
#include <block.hpp>
Classes | |
class | Error |
Public Types | |
using | element_const_iterator = element_container::const_iterator |
using | element_container = std::vector< Block > |
using | element_iterator = element_container::iterator |
Public Member Functions | |
Block () | |
Create an empty Block. More... | |
Block (const EncodingBuffer &buffer) | |
Parse Block from an EncodingBuffer. More... | |
Block (const ConstBufferPtr &buffer) | |
Parse Block from a wire Buffer. More... | |
Block (ConstBufferPtr buffer, Buffer::const_iterator begin, Buffer::const_iterator end, bool verifyLength=true) | |
Parse Block within boundaries of a wire Buffer. More... | |
Block (const Block &block, Buffer::const_iterator begin, Buffer::const_iterator end, bool verifyLength=true) | |
Parse Block within boundaries of an existing Block, reusing underlying wire Buffer. More... | |
Block (ConstBufferPtr buffer, uint32_t type, Buffer::const_iterator begin, Buffer::const_iterator end, Buffer::const_iterator valueBegin, Buffer::const_iterator valueEnd) | |
Create a Block from a wire Buffer without parsing. More... | |
Block (const uint8_t *buf, size_t bufSize) | |
Parse Block from a raw buffer. More... | |
Block (uint32_t type) | |
Create an empty Block with specified TLV-TYPE. More... | |
Block (uint32_t type, ConstBufferPtr value) | |
Create a Block with specified TLV-TYPE and TLV-VALUE. More... | |
Block (uint32_t type, const Block &value) | |
Create a Block with specified TLV-TYPE and TLV-VALUE. More... | |
Buffer::const_iterator | begin () const |
Get begin iterator of encoded wire. More... | |
Block | blockFromValue () const |
const element_container & | elements () const |
Get container of sub elements. More... | |
element_const_iterator | elements_begin () const |
Equivalent to elements().begin() More... | |
element_const_iterator | elements_end () const |
Equivalent to elements().end() More... | |
size_t | elements_size () const |
Equivalent to elements().size() More... | |
bool | empty () const |
Check if the Block is empty. More... | |
void | encode () |
Encode sub elements into TLV-VALUE. More... | |
Buffer::const_iterator | end () const |
Get end iterator of encoded wire. More... | |
element_iterator | erase (element_const_iterator position) |
Erase a sub element. More... | |
element_iterator | erase (element_const_iterator first, element_const_iterator last) |
Erase a range of sub elements. More... | |
element_const_iterator | find (uint32_t type) const |
Find the first sub element of specified TLV-TYPE. More... | |
const Block & | get (uint32_t type) const |
Get the first sub element of specified TLV-TYPE. More... | |
shared_ptr< const Buffer > | getBuffer () const |
Get underlying buffer. More... | |
bool | hasValue () const |
Get begin iterator of TLV-VALUE. More... | |
bool | hasWire () const |
Check if the Block has fully encoded wire. More... | |
element_iterator | insert (element_const_iterator pos, const Block &element) |
Insert a sub element. More... | |
operator boost::asio::const_buffer () const | |
Implicit conversion to const_buffer. More... | |
void | parse () const |
Parse TLV-VALUE into sub elements. More... | |
void | push_back (const Block &element) |
Append a sub element. More... | |
void | remove (uint32_t type) |
Remove all sub elements of specified TLV-TYPE. More... | |
void | reset () |
Reset wire buffer of the element. More... | |
void | resetWire () |
Reset wire buffer but keep TLV-TYPE and sub elements (if any) More... | |
size_t | size () const |
Get size of encoded wire, including Type-Length-Value. More... | |
uint32_t | type () const |
Get TLV-TYPE. More... | |
const uint8_t * | value () const |
Get pointer to TLV-VALUE. More... | |
Buffer::const_iterator | value_begin () const |
Get begin iterator of TLV-VALUE. More... | |
Buffer::const_iterator | value_end () const |
Get end iterator of TLV-VALUE. More... | |
size_t | value_size () const |
Get size of TLV-VALUE aka TLV-LENGTH. More... | |
const uint8_t * | wire () const |
Get pointer to encoded wire. More... | |
Static Public Member Functions | |
static std::tuple< bool, Block > | fromBuffer (ConstBufferPtr buffer, size_t offset) |
Try to parse Block from a wire buffer. More... | |
static std::tuple< bool, Block > | fromBuffer (const uint8_t *buf, size_t bufSize) |
Try to parse Block from a raw buffer. More... | |
static Block | fromStream (std::istream &is) |
Parse Block from an input stream. More... | |
Protected Attributes | |
Buffer::const_iterator | m_begin |
shared_ptr< const Buffer > | m_buffer |
underlying buffer storing TLV-VALUE and possibly TLV-TYPE and TLV-LENGTH fields More... | |
element_container | m_elements |
sub elements More... | |
Buffer::const_iterator | m_end |
uint32_t | m_size |
total size including Type-Length-Value More... | |
uint32_t | m_type |
TLV-TYPE. More... | |
Buffer::const_iterator | m_valueBegin |
Buffer::const_iterator | m_valueEnd |
Represents a TLV element of NDN packet format.
using ndn::Block::element_const_iterator = element_container::const_iterator |
using ndn::Block::element_container = std::vector<Block> |
using ndn::Block::element_iterator = element_container::iterator |
|
explicit |
Parse Block from an EncodingBuffer.
buffer | an EncodingBuffer containing one TLV element |
tlv::Error | Type-Length parsing fails, or TLV-LENGTH does not match size of TLV-VALUE |
|
explicit |
ndn::Block::Block | ( | ConstBufferPtr | buffer, |
Buffer::const_iterator | begin, | ||
Buffer::const_iterator | end, | ||
bool | verifyLength = true |
||
) |
Parse Block within boundaries of a wire Buffer.
buffer | a Buffer containing an TLV element at [begin ,end ) |
begin | begin position of the TLV element within buffer |
end | end position of the TLV element within buffer |
verifyLength | if true, check TLV-LENGTH equals size of TLV-VALUE |
std::invalid_argument | buffer is empty, or [begin ,end ) range are not within buffer |
tlv::Error | Type-Length parsing fails, or TLV-LENGTH does not match size of TLV-VALUE |
ndn::Block::Block | ( | const Block & | block, |
Buffer::const_iterator | begin, | ||
Buffer::const_iterator | end, | ||
bool | verifyLength = true |
||
) |
Parse Block within boundaries of an existing Block, reusing underlying wire Buffer.
block | a Block whose buffer contains an TLV element at [begin ,end ) |
begin | begin position of the TLV element within block |
end | end position of the TLV element within block |
verifyLength | if true, check TLV-LENGTH equals size of TLV-VALUE |
std::invalid_argument | [begin ,end ) range are not within block |
tlv::Error | Type-Length parsing fails, or TLV-LENGTH does not match size of TLV-VALUE |
ndn::Block::Block | ( | ConstBufferPtr | buffer, |
uint32_t | type, | ||
Buffer::const_iterator | begin, | ||
Buffer::const_iterator | end, | ||
Buffer::const_iterator | valueBegin, | ||
Buffer::const_iterator | valueEnd | ||
) |
Create a Block from a wire Buffer without parsing.
buffer | a Buffer containing an TLV element at [begin ,end ) |
type | TLV-TYPE |
begin | begin position of the TLV element within buffer |
end | end position of the TLV element within buffer |
valueBegin | begin position of TLV-VALUE within buffer |
valueEnd | end position of TLV-VALUE within buffer |
ndn::Block::Block | ( | const uint8_t * | buf, |
size_t | bufSize | ||
) |
Parse Block from a raw buffer.
buf | pointer to the first octet of an TLV element |
bufSize | size of the raw buffer; may be more than size of the TLV element |
tlv::Error | Type-Length parsing fails, or size of TLV-VALUE exceeds bufSize |
|
explicit |
ndn::Block::Block | ( | uint32_t | type, |
ConstBufferPtr | value | ||
) |
ndn::Block::Block | ( | uint32_t | type, |
const Block & | value | ||
) |
Buffer::const_iterator ndn::Block::begin | ( | ) | const |
|
inline |
|
inline |
Equivalent to elements().begin()
|
inline |
Equivalent to elements().end()
|
inline |
Equivalent to elements().size()
|
inline |
void ndn::Block::encode | ( | ) |
Encode sub elements into TLV-VALUE.
Buffer::const_iterator ndn::Block::end | ( | ) | const |
Block::element_iterator ndn::Block::erase | ( | Block::element_const_iterator | position | ) |
Block::element_iterator ndn::Block::erase | ( | Block::element_const_iterator | first, |
Block::element_const_iterator | last | ||
) |
Block::element_const_iterator ndn::Block::find | ( | uint32_t | type | ) | const |
Find the first sub element of specified TLV-TYPE.
|
static |
|
static |
Try to parse Block from a raw buffer.
buf | pointer to the first octet of an TLV element |
bufSize | size of the raw buffer; may be more than size of the TLV element |
|
static |
Parse Block from an input stream.
tlv::Error | TLV-LENGTH is zero or exceeds upper bound |
const Block & ndn::Block::get | ( | uint32_t | type | ) | const |
|
inline |
|
inline |
bool ndn::Block::hasWire | ( | ) | const |
Block::element_iterator ndn::Block::insert | ( | Block::element_const_iterator | pos, |
const Block & | element | ||
) |
Insert a sub element.
pos | position of new sub element |
element | new sub element |
ndn::Block::operator boost::asio::const_buffer | ( | ) | const |
void ndn::Block::parse | ( | ) | const |
Parse TLV-VALUE into sub elements.
tlv::Error | TLV-VALUE is not a sequence of TLV elements |
void ndn::Block::push_back | ( | const Block & | element | ) |
void ndn::Block::remove | ( | uint32_t | type | ) |
Remove all sub elements of specified TLV-TYPE.
void ndn::Block::reset | ( | ) |
void ndn::Block::resetWire | ( | ) |
Reset wire buffer but keep TLV-TYPE and sub elements (if any)
size_t ndn::Block::size | ( | ) | const |
const uint8_t * ndn::Block::value | ( | ) | const |
|
inline |
Get begin iterator of TLV-VALUE.
|
inline |
Get end iterator of TLV-VALUE.
size_t ndn::Block::value_size | ( | ) | const |
const uint8_t * ndn::Block::wire | ( | ) | const |
|
protected |
|
protected |
underlying buffer storing TLV-VALUE and possibly TLV-TYPE and TLV-LENGTH fields
If m_buffer is nullptr, this is an empty Block with TLV-TYPE given in m_type. Otherwise,
|
mutableprotected |
|
protected |
|
protected |
|
protected |