ndn-cxx: NDN C++ Library 0.9.0-33-g832ea91d
Loading...
Searching...
No Matches
prefix-announcement-header.cpp
Go to the documentation of this file.
1/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2/*
3 * Copyright (c) 2013-2023 Regents of the University of California.
4 *
5 * This file is part of ndn-cxx library (NDN C++ library with eXperimental eXtensions).
6 *
7 * ndn-cxx library is free software: you can redistribute it and/or modify it under the
8 * terms of the GNU Lesser General Public License as published by the Free Software
9 * Foundation, either version 3 of the License, or (at your option) any later version.
10 *
11 * ndn-cxx library is distributed in the hope that it will be useful, but WITHOUT ANY
12 * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
13 * PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
14 *
15 * You should have received copies of the GNU General Public License and GNU Lesser
16 * General Public License along with ndn-cxx, e.g., in COPYING.md file. If not, see
17 * <http://www.gnu.org/licenses/>.
18 *
19 * See AUTHORS.md for complete list of ndn-cxx authors and contributors.
20 */
21
23#include "ndn-cxx/lp/tlv.hpp"
24
25namespace ndn::lp {
26
28
33
35 : m_prefixAnn(std::move(prefixAnn))
36{
37 if (!m_prefixAnn->getData()) {
38 NDN_THROW(Error("PrefixAnnouncement does not contain Data"));
39 }
40}
41
42template<encoding::Tag TAG>
43size_t
45{
46 if (!m_prefixAnn) {
47 NDN_THROW(Error("PrefixAnnouncementHeader does not contain a PrefixAnnouncement"));
48 }
49
50 size_t length = 0;
51 length += m_prefixAnn->getData()->wireEncode(encoder);
52 length += encoder.prependVarNumber(length);
53 length += encoder.prependVarNumber(tlv::PrefixAnnouncement);
54 return length;
55}
56
58
59void
61{
62 if (wire.type() != tlv::PrefixAnnouncement) {
63 NDN_THROW(Error("PrefixAnnouncement", wire.type()));
64 }
65
66 wire.parse();
67 m_prefixAnn.emplace(Data(wire.get(ndn::tlv::Data)));
68}
69} // namespace ndn::lp
Represents a TLV element of the NDN packet format.
Definition block.hpp:45
uint32_t type() const noexcept
Return the TLV-TYPE of the Block.
Definition block.hpp:275
void parse() const
Parse TLV-VALUE into sub-elements.
Definition block.cpp:326
const Block & get(uint32_t type) const
Return the first sub-element of the specified TLV-TYPE.
Definition block.cpp:414
Represents a Data packet.
Definition data.hpp:39
A prefix announcement object that represents an application's intent of registering a prefix toward i...
Represents a PrefixAnnouncement header field in NDNLP.
size_t wireEncode(EncodingImpl< TAG > &encoder) const
Encodes the prefix announcement header to the wire format.
#define NDN_CXX_DEFINE_WIRE_ENCODE_INSTANTIATIONS(ClassName)
#define NDN_THROW(e)
Definition exception.hpp:56
@ PrefixAnnouncement
Definition tlv.hpp:53
Contains classes and functions related to NDNLPv2.
@ Data
Definition tlv.hpp:69
STL namespace.