Represents a TLV element of the NDN packet format. More...
#include <ndn-cxx/encoding/block.hpp>
Classes | |
class | Error |
Public Types | |
using | const_iterator = Buffer::const_iterator |
using | element_const_iterator = element_container::const_iterator |
using | element_container = std::vector< Block > |
using | element_iterator = element_container::iterator |
using | value_type = Buffer::value_type |
Public Member Functions | |
Block () | |
Create an invalid Block. More... | |
Block (Block &&) noexcept | |
Move constructor. More... | |
Block (const Block &) | |
Copy constructor. More... | |
Block (const Block &block, Block::const_iterator begin, Block::const_iterator end, bool verifyLength=true) | |
Parse Block within boundaries of an existing Block, reusing underlying wire Buffer. More... | |
Block (const ConstBufferPtr &buffer) | |
Parse Block from a wire Buffer. More... | |
Block (const EncodingBuffer &buffer) | |
Parse Block from an EncodingBuffer. 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 (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 (span< const uint8_t > buffer) | |
Parse Block from a byte range. More... | |
Block (uint32_t type) | |
Create a zero-length Block with the specified TLV-TYPE. More... | |
Block (uint32_t type, const Block &value) | |
Create a Block with the specified TLV-TYPE and TLV-VALUE. More... | |
Block (uint32_t type, ConstBufferPtr value) | |
Create a Block with the specified TLV-TYPE and TLV-VALUE. More... | |
const_iterator | begin () const |
Returns an iterator to the beginning of the encoded wire. More... | |
Block | blockFromValue () const |
Return a new Block constructed from the TLV-VALUE of this Block. More... | |
const uint8_t * | data () const |
Returns a raw pointer to the beginning of the encoded wire, i.e., the whole TLV. More... | |
const element_container & | elements () const noexcept |
Get container of sub-elements. More... | |
element_const_iterator | elements_begin () const noexcept |
Equivalent to elements().begin() . More... | |
element_const_iterator | elements_end () const noexcept |
Equivalent to elements().end() . More... | |
size_t | elements_size () const noexcept |
Equivalent to elements().size() . More... | |
void | encode () |
Encode sub-elements into TLV-VALUE. More... | |
const_iterator | end () const |
Returns an iterator past-the-end of the encoded wire. More... | |
element_iterator | erase (element_const_iterator first, element_const_iterator last) |
Erase a range of sub-elements. More... | |
element_iterator | erase (element_const_iterator position) |
Erase a sub-element. More... | |
element_const_iterator | find (uint32_t type) const |
Find the first sub-element of the specified TLV-TYPE. More... | |
const Block & | get (uint32_t type) const |
Return the first sub-element of the specified TLV-TYPE. More... | |
ConstBufferPtr | getBuffer () const |
Returns the underlying buffer. More... | |
bool | hasValue () const noexcept |
Check if the Block has a non-empty TLV-VALUE. More... | |
bool | hasWire () const noexcept |
Check if the Block contains a fully encoded wire representation. More... | |
element_iterator | insert (element_const_iterator pos, const Block &element) |
Insert a sub-element. More... | |
bool | isValid () const noexcept |
Check if the Block is valid. More... | |
operator boost::asio::const_buffer () const | |
Implicit conversion to boost::asio::const_buffer . More... | |
Block & | operator= (Block &&) noexcept |
Move assignment operator. More... | |
Block & | operator= (const Block &) |
Copy assignment operator. More... | |
void | parse () const |
Parse TLV-VALUE into sub-elements. More... | |
void | push_back (Block &&element) |
Append a sub-element. More... | |
void | push_back (const Block &element) |
Append a sub-element. More... | |
void | remove (uint32_t type) |
Remove all sub-elements of the specified TLV-TYPE. More... | |
void | reset () noexcept |
Reset the Block to a default-constructed state. More... | |
void | resetWire () noexcept |
Reset wire buffer but keep TLV-TYPE and sub-elements (if any). More... | |
size_t | size () const |
Returns the size of the encoded wire, i.e., of the whole TLV. More... | |
uint32_t | type () const noexcept |
Return the TLV-TYPE of the Block. More... | |
const uint8_t * | value () const noexcept |
Return a raw pointer to the beginning of TLV-VALUE. More... | |
const_iterator | value_begin () const noexcept |
Get begin iterator of TLV-VALUE. More... | |
span< const uint8_t > | value_bytes () const noexcept |
Return a read-only view of TLV-VALUE as a contiguous range of bytes. More... | |
const_iterator | value_end () const noexcept |
Get end iterator of TLV-VALUE. More... | |
size_t | value_size () const noexcept |
Return the size of TLV-VALUE, i.e., the TLV-LENGTH. More... | |
Static Public Member Functions | |
static std::tuple< bool, Block > | fromBuffer (ConstBufferPtr buffer, size_t offset=0) |
Try to parse Block from a wire buffer. More... | |
static std::tuple< bool, Block > | fromBuffer (span< const uint8_t > buffer) |
Try to parse Block from a byte range. 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 |
Contains the sub-elements. More... | |
Buffer::const_iterator | m_end |
size_t | m_size = 0 |
Total size including Type-Length-Value. More... | |
uint32_t | m_type = tlv::Invalid |
TLV-TYPE. More... | |
Buffer::const_iterator | m_valueBegin |
Buffer::const_iterator | m_valueEnd |
Friends | |
std::ostream & | operator<< (std::ostream &os, const Block &block) |
Print block to os . More... | |
bool | operator== (const Block &lhs, const Block &rhs) noexcept |
Compare whether two Blocks have the same TLV-TYPE, TLV-LENGTH, and TLV-VALUE. More... | |
Represents a TLV element of the NDN packet format.
using ndn::Block::const_iterator = Buffer::const_iterator |
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 |
using ndn::Block::value_type = Buffer::value_type |
|
default |
Copy constructor.
|
inlinedefaultnoexcept |
Move constructor.
|
explicit |
Parse Block from a byte range.
buffer | sequence of bytes containing a TLV element; the element must be found at the beginning of the buffer but does not need to span the entire buffer |
tlv::Error | Type-Length parsing fails, or TLV-LENGTH exceeds the size of buffer |
|
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 a 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 is 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, |
Block::const_iterator | begin, | ||
Block::const_iterator | end, | ||
bool | verifyLength = true |
||
) |
Parse Block within boundaries of an existing Block, reusing underlying wire Buffer.
block | a Block whose buffer contains a 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 is 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 a 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 |
|
explicit |
ndn::Block::Block | ( | uint32_t | type, |
ConstBufferPtr | value | ||
) |
ndn::Block::Block | ( | uint32_t | type, |
const Block & | value | ||
) |
Block::const_iterator ndn::Block::begin | ( | ) | const |
Block ndn::Block::blockFromValue | ( | ) | const |
Return a new Block constructed from the TLV-VALUE of this Block.
value_size() > 0
const uint8_t * ndn::Block::data | ( | ) | const |
|
inlinenoexcept |
|
inlinenoexcept |
Equivalent to elements().begin()
.
|
inlinenoexcept |
Equivalent to elements().end()
.
|
inlinenoexcept |
Equivalent to elements().size()
.
void ndn::Block::encode | ( | ) |
Encode sub-elements into TLV-VALUE.
Block::const_iterator ndn::Block::end | ( | ) | const |
Block::element_iterator ndn::Block::erase | ( | Block::element_const_iterator | first, |
Block::element_const_iterator | last | ||
) |
Block::element_iterator ndn::Block::erase | ( | Block::element_const_iterator | position | ) |
Block::element_const_iterator ndn::Block::find | ( | uint32_t | type | ) | const |
Find the first sub-element of the specified TLV-TYPE.
|
static |
|
static |
Try to parse Block from a byte range.
buffer | sequence of bytes containing a TLV element; the element must be found at the beginning of the buffer but does not need to span the entire buffer |
|
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 |
Return the first sub-element of the specified TLV-TYPE.
tlv::Error | a sub-element of the specified type does not exist |
|
inline |
|
inlinenoexcept |
Check if the Block has a non-empty TLV-VALUE.
This property reflects whether the underlying buffer contains a TLV-VALUE. If this is false, TLV-VALUE has zero-length. If this is true, TLV-VALUE may be zero-length.
|
inlinenoexcept |
Block::element_iterator ndn::Block::insert | ( | Block::element_const_iterator | pos, |
const Block & | element | ||
) |
Insert a sub-element.
pos | position of the new sub-element |
element | new sub-element to insert |
|
inlinenoexcept |
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 | ( | Block && | element | ) |
void ndn::Block::push_back | ( | const Block & | element | ) |
void ndn::Block::remove | ( | uint32_t | type | ) |
Remove all sub-elements of the specified TLV-TYPE.
find(type) == elements_end()
|
noexcept |
|
noexcept |
Reset wire buffer but keep TLV-TYPE and sub-elements (if any).
hasWire() == false
hasValue() == false
size_t ndn::Block::size | ( | ) | const |
Returns the size of the encoded wire, i.e., of the whole TLV.
isValid() == true
|
inlinenoexcept |
Return the TLV-TYPE of the Block.
|
noexcept |
Return a raw pointer to the beginning of TLV-VALUE.
|
inlinenoexcept |
Get begin iterator of TLV-VALUE.
hasValue() == true
|
inlinenoexcept |
|
inlinenoexcept |
Get end iterator of TLV-VALUE.
hasValue() == true
|
inlinenoexcept |
|
friend |
Print block
to os
.
Default-constructed Block is printed as: [invalid]
. Zero-length Block is printed as: TT[empty]
, where TT is TLV-TYPE in decimal. Non-zero-length Block on which parse() has not been called is printed as: TT[LL]=VVVV
, where LL is TLV-LENGTH in decimal, and VVVV is TLV-VALUE in hexadecimal. Block on which parse() has been called is printed as: TT[LL]={SUB,SUB}
, where each SUB is a sub-element printed using this format.
|
protected |
|
protected |
Underlying buffer storing TLV-VALUE and possibly TLV-TYPE and TLV-LENGTH fields.
If m_buffer is nullptr, this is an invalid or zero-length Block with TLV-TYPE given in m_type. Otherwise,
|
mutableprotected |
|
protected |
|
protected |
|
protected |
|
protected |