22 #ifndef NDN_CXX_LP_PACKET_HPP 23 #define NDN_CXX_LP_PACKET_HPP 76 template<
typename FIELD>
80 return count<FIELD>() > 0;
86 template<
typename FIELD>
91 [] (
const Block& block) {
92 return block.type() == FIELD::TlvType::value; });
99 template<
typename FIELD>
100 typename FIELD::ValueType
101 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;
126 if (element.type() != FIELD::TlvType::value) {
129 output.push_back(FIELD::decode(element));
139 template<
typename FIELD>
141 set(
const typename FIELD::ValueType& value)
144 return add<FIELD>(value);
151 template<
typename FIELD>
153 add(
const typename FIELD::ValueType& value)
155 if (!FIELD::IsRepeatable::value && has<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();
166 FIELD::TlvType::value, comparePos);
167 m_wire.
insert(pos, block);
176 template<
typename FIELD>
178 remove(
size_t index = 0)
182 if (it->type() == FIELD::TlvType::value) {
183 if (
count == index) {
191 BOOST_THROW_EXCEPTION(std::out_of_range(
"Index out of range"));
197 template<
typename FIELD>
201 m_wire.
remove(FIELD::TlvType::value);
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.
std::vector< typename FIELD::ValueType > list() const
Packet & add(const typename FIELD::ValueType &value)
add a FIELD with value
Represents a TLV element of NDN packet format.
element_const_iterator elements_begin() const
Equivalent to elements().begin()
element_iterator insert(element_const_iterator pos, const Block &element)
Insert a sub element.
element_iterator erase(element_const_iterator position)
Erase a sub element.
const element_container & elements() const
Get container of sub elements.
Error(const std::string &what)
element_const_iterator elements_end() const
Equivalent to elements().end()
Packet & clear()
remove all occurrences of FIELD
void wireDecode(const Block &wire)
decode packet from wire format
void remove(uint32_t type)
Remove all sub elements of specified TLV-TYPE.
size_t elements_size() const
Equivalent to elements().size()
Block wireEncode() const
encode packet into wire format
EncodingImpl< EncoderTag > EncodingBuffer
represents an error in TLV encoding or decoding
EncodingImpl< EstimatorTag > EncodingEstimator