22 #ifndef NDN_CXX_LP_PACKET_HPP 23 #define NDN_CXX_LP_PACKET_HPP 51 template<encoding::Tag TAG>
73 template<
typename FIELD>
77 return count<FIELD>() > 0;
83 template<
typename FIELD>
89 return std::count_if(m_wire.elements_begin(), m_wire.elements_end(),
90 [] (
const Block& block) {
91 return block.type() == FIELD::TlvType::value; });
98 template<
typename FIELD>
99 typename FIELD::ValueType
100 get(
size_t index = 0)
const 106 if (element.type() != FIELD::TlvType::value) {
109 if (count++ == index) {
110 return FIELD::decode(element);
114 BOOST_THROW_EXCEPTION(std::out_of_range(
"Index out of range"));
120 template<
typename FIELD>
121 std::vector<typename FIELD::ValueType>
124 std::vector<typename FIELD::ValueType> output;
129 if (element.type() != FIELD::TlvType::value) {
132 output.push_back(FIELD::decode(element));
142 template<
typename FIELD>
144 set(
const typename FIELD::ValueType& value)
147 return add<FIELD>(value);
154 template<
typename FIELD>
156 add(
const typename FIELD::ValueType& value)
158 if (!FIELD::IsRepeatable::value && has<FIELD>()) {
159 BOOST_THROW_EXCEPTION(std::length_error(
"Field cannot be repeated"));
163 size_t estimatedSize = FIELD::encode(estimator, value);
165 FIELD::encode(buffer, value);
166 Block block = buffer.block();
169 m_wire.elements_end(),
170 FIELD::TlvType::value,
172 m_wire.
insert(pos, block);
181 template<
typename FIELD>
183 remove(
size_t index = 0)
190 if (it->type() == FIELD::TlvType::value) {
191 if (count == index) {
199 BOOST_THROW_EXCEPTION(std::out_of_range(
"Index out of range"));
205 template<
typename FIELD>
210 m_wire.
remove(FIELD::TlvType::value);
216 comparePos(
const Block& first,
const uint64_t second);
219 mutable Block m_wire;
225 #endif // NDN_CXX_LP_PACKET_HPP Copyright (c) 2011-2015 Regents of the University of California.
std::vector< typename FIELD::ValueType > list() const
Packet & remove(size_t index=0)
remove the index-th occurrence of FIELD
EncodingImpl< EstimatorTag > EncodingEstimator
Packet & add(const typename FIELD::ValueType &value)
add a FIELD with value
Class representing a wire element of NDN-TLV packet format.
element_iterator insert(element_const_iterator pos, const Block &element)
insert Insert a new element in a specific position
Error(const std::string &what)
Packet & clear()
remove all occurrences of FIELD
void wireDecode(const Block &wire)
decode packet from wire format
EncodingImpl< EncoderTag > EncodingBuffer
element_container::const_iterator element_const_iterator
const element_container & elements() const
Get all subelements.
Block wireEncode() const
encode packet into wire format
represents an error in TLV encoding or decoding