22 #ifndef NDN_CXX_LP_PACKET_HPP 23 #define NDN_CXX_LP_PACKET_HPP 51 template<encoding::Tag TAG>
72 template<
typename FIELD>
76 return count<FIELD>() > 0;
82 template<
typename FIELD>
88 return std::count_if(m_wire.elements_begin(), m_wire.elements_end(),
89 [] (
const Block& block) {
90 return block.type() == FIELD::TlvType::value; });
97 template<
typename FIELD>
98 typename FIELD::ValueType
99 get(
size_t index = 0)
const 105 if (element.type() != FIELD::TlvType::value) {
108 if (count++ == index) {
109 return FIELD::decode(element);
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;
128 if (element.type() != FIELD::TlvType::value) {
131 output.push_back(FIELD::decode(element));
141 template<
typename FIELD>
143 set(
const typename FIELD::ValueType& value)
146 return add<FIELD>(value);
153 template<
typename FIELD>
155 add(
const typename FIELD::ValueType& value)
157 if (!FIELD::IsRepeatable::value && has<FIELD>()) {
158 BOOST_THROW_EXCEPTION(std::length_error(
"Field cannot be repeated"));
162 size_t estimatedSize = FIELD::encode(estimator, value);
164 FIELD::encode(buffer, value);
165 Block block = buffer.block();
168 m_wire.elements_end(),
169 FIELD::TlvType::value,
171 m_wire.
insert(pos, block);
180 template<
typename FIELD>
182 remove(
size_t index = 0)
189 if (it->type() == FIELD::TlvType::value) {
190 if (count == index) {
198 BOOST_THROW_EXCEPTION(std::out_of_range(
"Index out of range"));
204 template<
typename FIELD>
209 m_wire.
remove(FIELD::TlvType::value);
215 comparePos(
const Block& first,
const uint64_t second);
218 mutable Block m_wire;
224 #endif // NDN_CXX_LP_PACKET_HPP const Block & wireEncode() const
encode packet into wire format
Copyright (c) 2011-2015 Regents of the University of California.
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
const element_container & elements() const
Get all subelements.
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
std::vector< typename FIELD::ValueType > list() const
represents an error in TLV encoding or decoding