|
NS-3 based Named Data Networking (NDN) simulator
ndnSIM 2.5: NDN, CCN, CCNx, content centric networks
|
API Documentation
|
Go to the documentation of this file.
22 #ifndef NDN_CXX_LP_PACKET_HPP
23 #define NDN_CXX_LP_PACKET_HPP
72 template<
typename FIELD>
76 return count<FIELD>() > 0;
82 template<
typename FIELD>
87 [] (
const Block& block) { return block.type() == FIELD::TlvType::value; });
94 template<
typename FIELD>
95 typename FIELD::ValueType
96 get(
size_t index = 0)
const
100 if (element.type() != FIELD::TlvType::value) {
103 if (
count++ == index) {
104 return FIELD::decode(element);
108 NDN_THROW(std::out_of_range(
"lp::Packet::get: index out of range"));
114 template<
typename FIELD>
118 std::vector<typename FIELD::ValueType> output;
121 if (element.type() != FIELD::TlvType::value) {
124 output.push_back(FIELD::decode(element));
134 template<
typename FIELD>
136 set(
const typename FIELD::ValueType& value)
139 return add<FIELD>(value);
146 template<
typename FIELD>
148 add(
const typename FIELD::ValueType& value)
150 if (!FIELD::IsRepeatable::value && has<FIELD>()) {
151 NDN_THROW(std::invalid_argument(
"lp::Packet::add: field cannot be repeated"));
155 size_t estimatedSize = FIELD::encode(estimator, value);
157 FIELD::encode(buffer, value);
158 Block block = buffer.block();
161 FIELD::TlvType::value, comparePos);
162 m_wire.
insert(pos, block);
171 template<
typename FIELD>
177 if (it->type() == FIELD::TlvType::value) {
178 if (
count == index) {
186 NDN_THROW(std::out_of_range(
"lp::Packet::remove: index out of range"));
192 template<
typename FIELD>
196 m_wire.
remove(FIELD::TlvType::value);
202 comparePos(uint64_t first,
const Block& second) noexcept;
205 mutable Block m_wire;
211 #endif // NDN_CXX_LP_PACKET_HPP
const element_container & elements() const
Get container of sub-elements.
element_iterator insert(element_const_iterator pos, const Block &element)
Insert a sub-element.
Packet & add(const typename FIELD::ValueType &value)
add a FIELD with value
NDN_CXX_NODISCARD bool has() const
element_const_iterator elements_begin() const
Equivalent to elements().begin()
NDN_CXX_NODISCARD size_t count() const
Packet & remove(size_t index=0)
remove the index-th occurrence of FIELD
NDN_CXX_NODISCARD std::vector< typename FIELD::ValueType > list() const
EncodingImpl< EstimatorTag > EncodingEstimator
NDN_CXX_NODISCARD bool empty() const
void remove(uint32_t type)
Remove all sub-elements of the specified TLV-TYPE.
Packet & set(const typename FIELD::ValueType &value)
remove all occurrences of FIELD, and add a FIELD with value
#define NDN_CXX_NODISCARD
element_iterator erase(element_const_iterator position)
Erase a sub-element.
void wireDecode(const Block &wire)
decode packet from wire format
Block wireEncode() const
encode packet into wire format
Packet & clear()
remove all occurrences of FIELD
Represents a TLV element of NDN packet format.
size_t elements_size() const
Equivalent to elements().size()
element_const_iterator elements_end() const
Equivalent to elements().end()
represents an error in TLV encoding or decoding
Error(const char *expectedType, uint32_t actualType)
FIELD::ValueType get(size_t index=0) const
Copyright (c) 2011-2015 Regents of the University of California.
EncodingImpl< EncoderTag > EncodingBuffer