22 #ifndef NDN_CXX_LP_PACKET_HPP 23 #define NDN_CXX_LP_PACKET_HPP 68 return m_wire.elements_size() == 0;
76 template<
typename FIELD>
80 return count<FIELD>() > 0;
86 template<
typename FIELD>
90 return std::count_if(m_wire.elements_begin(), m_wire.elements_end(),
91 [] (
const Block& block) {
99 template<
typename FIELD>
100 typename FIELD::ValueType
101 get(
size_t index = 0)
const 108 if (count++ == index) {
113 BOOST_THROW_EXCEPTION(std::out_of_range(
"Index out of range"));
119 template<
typename FIELD>
120 std::vector<typename FIELD::ValueType>
123 std::vector<typename FIELD::ValueType> output;
139 template<
typename FIELD>
141 set(
const typename FIELD::ValueType&
value)
144 return add<FIELD>(
value);
151 template<
typename FIELD>
156 BOOST_THROW_EXCEPTION(std::length_error(
"Field cannot be repeated"));
160 size_t estimatedSize = FIELD::encode(estimator, value);
162 FIELD::encode(buffer, value);
163 Block block = buffer.block();
165 auto pos = std::upper_bound(m_wire.elements_begin(), m_wire.elements_end(),
167 m_wire.
insert(pos, block);
176 template<
typename FIELD>
178 remove(
size_t index = 0)
181 for (
auto it = m_wire.elements_begin(); it != m_wire.elements_end(); ++it) {
183 if (count == index) {
191 BOOST_THROW_EXCEPTION(std::out_of_range(
"Index out of range"));
197 template<
typename FIELD>
207 comparePos(uint64_t first,
const Block& second);
210 mutable Block m_wire;
216 #endif // NDN_CXX_LP_PACKET_HPP Copyright (c) 2011-2015 Regents of the University of California.
const element_container & elements() const
Get container of sub elements.
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
Represents a TLV element of NDN packet format.
element_iterator insert(element_const_iterator pos, const Block &element)
Insert a sub element.
Error(const std::string &what)
Packet & clear()
remove all occurrences of FIELD
void wireDecode(const Block &wire)
decode packet from wire format
Block wireEncode() const
encode packet into wire format
std::vector< typename FIELD::ValueType > list() const
EncodingImpl< EncoderTag > EncodingBuffer
represents an error in TLV encoding or decoding
EncodingImpl< EstimatorTag > EncodingEstimator