24 #ifndef NDN_CXX_ENCODING_BLOCK_HPP
25 #define NDN_CXX_ENCODING_BLOCK_HPP
90 Block(span<const uint8_t> buffer);
116 bool verifyLength = true);
127 bool verifyLength = true);
343 value() const noexcept;
462 operator boost::asio::const_buffer()
const;
538 operator==(const
Block& lhs, const
Block& rhs) noexcept;
543 return !(lhs == rhs);
560 operator ""_block(
const char* input, std::size_t len);
#define NDN_CXX_NODISCARD
Represents a TLV element of the NDN packet format.
element_const_iterator elements_begin() const noexcept
Equivalent to elements().begin().
element_container::const_iterator element_const_iterator
const uint8_t * data() const
Return a raw pointer to the beginning of the encoded wire.
Buffer::const_iterator const_iterator
const_iterator value_end() const noexcept
Get end iterator of TLV-VALUE.
element_const_iterator find(uint32_t type) const
Find the first sub-element of the specified TLV-TYPE.
Buffer::value_type value_type
const_iterator begin() const
Get begin iterator of encoded wire.
Block blockFromValue() const
Return a new Block constructed from the TLV-VALUE of this Block.
element_iterator erase(element_const_iterator position)
Erase a sub-element.
friend std::ostream & operator<<(std::ostream &os, const Block &block)
Print block to os.
size_t elements_size() const noexcept
Equivalent to elements().size().
const element_container & elements() const noexcept
Get container of sub-elements.
void remove(uint32_t type)
Remove all sub-elements of the specified TLV-TYPE.
size_t size() const
Return the size of the encoded wire, i.e., of the whole TLV.
element_const_iterator elements_end() const noexcept
Equivalent to elements().end().
bool hasWire() const noexcept
Check if the Block contains a fully encoded wire representation.
size_t m_size
Total size including Type-Length-Value.
Buffer::const_iterator m_valueEnd
void resetWire() noexcept
Reset wire buffer but keep TLV-TYPE and sub-elements (if any)
element_container m_elements
Contains the sub-elements.
static std::tuple< bool, Block > fromBuffer(ConstBufferPtr buffer, size_t offset=0)
Try to parse Block from a wire buffer.
void push_back(const Block &element)
Append a sub-element.
Block(Block &&) noexcept
Move constructor.
Block & operator=(const Block &)
Copy assignment operator.
Buffer::const_iterator m_end
Buffer::const_iterator m_valueBegin
Block(const Block &)
Copy constructor.
const uint8_t * wire() const
ConstBufferPtr getBuffer() const
Get underlying buffer.
bool hasValue() const noexcept
Check if the Block has a non-empty TLV-VALUE.
bool isValid() const noexcept
Check if the Block is valid.
element_container::iterator element_iterator
void encode()
Encode sub-elements into TLV-VALUE.
span< const uint8_t > value_bytes() const noexcept
Return a read-only view of TLV-VALUE as a contiguous range of bytes.
const_iterator end() const
Get end iterator of encoded wire.
uint32_t type() const noexcept
Return the TLV-TYPE of the Block.
static Block fromStream(std::istream &is)
Parse Block from an input stream.
void reset() noexcept
Reset the Block to a default-constructed state.
Buffer::const_iterator m_begin
shared_ptr< const Buffer > m_buffer
Underlying buffer storing TLV-VALUE and possibly TLV-TYPE and TLV-LENGTH fields.
std::vector< Block > element_container
void parse() const
Parse TLV-VALUE into sub-elements.
const_iterator value_begin() const noexcept
Get begin iterator of TLV-VALUE.
const Block & get(uint32_t type) const
Return the first sub-element of the specified TLV-TYPE.
size_t value_size() const noexcept
Return the size of TLV-VALUE, i.e., the TLV-LENGTH.
Block()
Create an invalid Block.
element_iterator insert(element_const_iterator pos, const Block &element)
Insert a sub-element.
const uint8_t * value() const noexcept
Return a raw pointer to the beginning of TLV-VALUE.
General-purpose automatically managed/resized buffer.
Represents an error in TLV encoding or decoding.
Error(const char *expectedType, uint32_t actualType)
EncodingImpl< EstimatorTag > EncodingEstimator
EncodingImpl< EncoderTag > EncodingBuffer
shared_ptr< const Buffer > ConstBufferPtr