22 #ifndef NDN_CXX_LP_PACKET_HPP 23 #define NDN_CXX_LP_PACKET_HPP 64 return m_wire.elements_size() == 0;
72 template<
typename FIELD>
76 return count<FIELD>() > 0;
82 template<
typename FIELD>
86 return std::count_if(m_wire.elements_begin(), m_wire.elements_end(),
94 template<
typename FIELD>
95 typename FIELD::ValueType
96 get(
size_t index = 0)
const 103 if (count++ == index) {
108 NDN_THROW(std::out_of_range(
"lp::Packet::get: index out of range"));
114 template<
typename FIELD>
118 std::vector<typename FIELD::ValueType> output;
134 template<
typename FIELD>
136 set(
const typename FIELD::ValueType&
value)
139 return add<FIELD>(
value);
146 template<
typename FIELD>
151 NDN_THROW(std::invalid_argument(
"lp::Packet::add: field cannot be repeated"));
155 size_t estimatedSize = FIELD::encode(estimator, value);
157 FIELD::encode(buffer, value);
158 Block block = buffer.block();
160 auto pos = std::upper_bound(m_wire.elements_begin(), m_wire.elements_end(),
162 m_wire.
insert(pos, block);
171 template<
typename FIELD>
173 remove(
size_t index = 0)
176 for (
auto it = m_wire.elements_begin(); it != m_wire.elements_end(); ++it) {
178 if (count == index) {
186 NDN_THROW(std::out_of_range(
"lp::Packet::remove: index out of range"));
192 template<
typename FIELD>
202 comparePos(uint64_t first,
const Block& second) noexcept;
205 mutable Block m_wire;
211 #endif // NDN_CXX_LP_PACKET_HPP NDN_CXX_NODISCARD bool has() const
Copyright (c) 2011-2015 Regents of the University of California.
Packet & remove(size_t index=0)
remove the index-th occurrence of FIELD
uint32_t decode(uint32_t *state, uint32_t *codep, uint8_t byte)
Decode the next byte of a UTF8 sequence.
Packet & add(const typename FIELD::ValueType &value)
add a FIELD with value
NDN_CXX_NODISCARD bool empty() const
Represents a TLV element of the NDN packet format.
element_iterator insert(element_const_iterator pos, const Block &element)
Insert a sub-element.
const element_container & elements() const
Get container of sub-elements.
Packet & clear()
remove all occurrences of FIELD
void wireDecode(const Block &wire)
decode packet from wire format
#define NDN_CXX_NODISCARD
NDN_CXX_NODISCARD size_t count() const
Block wireEncode() const
encode packet into wire format
NDN_CXX_NODISCARD std::vector< typename FIELD::ValueType > list() const
EncodingImpl< EncoderTag > EncodingBuffer
Error(const char *expectedType, uint32_t actualType)
represents an error in TLV encoding or decoding
EncodingImpl< EstimatorTag > EncodingEstimator