22 #ifndef NDN_CXX_LP_PACKET_HPP 23 #define NDN_CXX_LP_PACKET_HPP 36 using ndn::tlv::Error::Error;
72 template<
typename FIELD>
76 return count<FIELD>() > 0;
82 template<
typename FIELD>
87 [] (
const Block& block) {
88 return block.type() == FIELD::TlvType::value; });
95 template<
typename FIELD>
96 typename FIELD::ValueType
97 get(
size_t index = 0)
const 101 if (element.type() != FIELD::TlvType::value) {
104 if (
count++ == index) {
105 return FIELD::decode(element);
109 BOOST_THROW_EXCEPTION(std::out_of_range(
"Index out of range"));
115 template<
typename FIELD>
116 std::vector<typename FIELD::ValueType>
119 std::vector<typename FIELD::ValueType> output;
122 if (element.type() != FIELD::TlvType::value) {
125 output.push_back(FIELD::decode(element));
135 template<
typename FIELD>
137 set(
const typename FIELD::ValueType& value)
140 return add<FIELD>(value);
147 template<
typename FIELD>
149 add(
const typename FIELD::ValueType& value)
151 if (!FIELD::IsRepeatable::value && has<FIELD>()) {
152 BOOST_THROW_EXCEPTION(std::length_error(
"Field cannot be repeated"));
156 size_t estimatedSize = FIELD::encode(estimator, value);
158 FIELD::encode(buffer, value);
159 Block block = buffer.block();
162 FIELD::TlvType::value, comparePos);
163 m_wire.
insert(pos, block);
172 template<
typename FIELD>
178 if (it->type() == FIELD::TlvType::value) {
179 if (
count == index) {
187 BOOST_THROW_EXCEPTION(std::out_of_range(
"Index out of range"));
193 template<
typename FIELD>
197 m_wire.
remove(FIELD::TlvType::value);
203 comparePos(uint64_t first,
const Block& second) noexcept;
206 mutable Block m_wire;
212 #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
Packet & set(const typename FIELD::ValueType &value)
remove all occurrences of FIELD, and add a FIELD with value
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.
element_const_iterator elements_end() const
Equivalent to elements().end()
FIELD::ValueType get(size_t index=0) const
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