ndn-cxx: NDN C++ Library 0.9.0-33-g832ea91d
Loading...
Searching...
No Matches
face-event-notification.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
27
28namespace ndn::nfd {
29
31
33{
34 this->wireDecode(block);
35}
36
37template<encoding::Tag TAG>
38size_t
40{
41 size_t totalLength = 0;
42
43 totalLength += prependNonNegativeIntegerBlock(encoder, tlv::nfd::Flags, m_flags);
44 totalLength += prependNonNegativeIntegerBlock(encoder, tlv::nfd::LinkType, m_linkType);
45 totalLength += prependNonNegativeIntegerBlock(encoder, tlv::nfd::FacePersistency, m_facePersistency);
46 totalLength += prependNonNegativeIntegerBlock(encoder, tlv::nfd::FaceScope, m_faceScope);
47 totalLength += prependStringBlock(encoder, tlv::nfd::LocalUri, m_localUri);
48 totalLength += prependStringBlock(encoder, tlv::nfd::Uri, m_remoteUri);
49 totalLength += prependNonNegativeIntegerBlock(encoder, tlv::nfd::FaceId, m_faceId);
50 totalLength += prependNonNegativeIntegerBlock(encoder, tlv::nfd::FaceEventKind, m_kind);
51
52 totalLength += encoder.prependVarNumber(totalLength);
53 totalLength += encoder.prependVarNumber(tlv::nfd::FaceEventNotification);
54 return totalLength;
55}
56
58
59const Block&
61{
62 if (m_wire.hasWire())
63 return m_wire;
64
65 EncodingEstimator estimator;
66 size_t estimatedSize = wireEncode(estimator);
67
68 EncodingBuffer buffer(estimatedSize, 0);
69 wireEncode(buffer);
70
71 m_wire = buffer.block();
72 return m_wire;
73}
74
75void
77{
79 NDN_THROW(Error("FaceEventNotification", block.type()));
80 }
81
82 m_wire = block;
83 m_wire.parse();
84 auto val = m_wire.elements_begin();
85
86 if (val != m_wire.elements_end() && val->type() == tlv::nfd::FaceEventKind) {
87 m_kind = readNonNegativeIntegerAs<FaceEventKind>(*val);
88 ++val;
89 }
90 else {
91 NDN_THROW(Error("missing required FaceEventKind field"));
92 }
93
94 if (val != m_wire.elements_end() && val->type() == tlv::nfd::FaceId) {
95 m_faceId = readNonNegativeInteger(*val);
96 ++val;
97 }
98 else {
99 NDN_THROW(Error("missing required FaceId field"));
100 }
101
102 if (val != m_wire.elements_end() && val->type() == tlv::nfd::Uri) {
103 m_remoteUri = readString(*val);
104 ++val;
105 }
106 else {
107 NDN_THROW(Error("missing required Uri field"));
108 }
109
110 if (val != m_wire.elements_end() && val->type() == tlv::nfd::LocalUri) {
111 m_localUri = readString(*val);
112 ++val;
113 }
114 else {
115 NDN_THROW(Error("missing required LocalUri field"));
116 }
117
118 if (val != m_wire.elements_end() && val->type() == tlv::nfd::FaceScope) {
119 m_faceScope = readNonNegativeIntegerAs<FaceScope>(*val);
120 ++val;
121 }
122 else {
123 NDN_THROW(Error("missing required FaceScope field"));
124 }
125
126 if (val != m_wire.elements_end() && val->type() == tlv::nfd::FacePersistency) {
127 m_facePersistency = readNonNegativeIntegerAs<FacePersistency>(*val);
128 ++val;
129 }
130 else {
131 NDN_THROW(Error("missing required FacePersistency field"));
132 }
133
134 if (val != m_wire.elements_end() && val->type() == tlv::nfd::LinkType) {
135 m_linkType = readNonNegativeIntegerAs<LinkType>(*val);
136 ++val;
137 }
138 else {
139 NDN_THROW(Error("missing required LinkType field"));
140 }
141
142 if (val != m_wire.elements_end() && val->type() == tlv::nfd::Flags) {
143 m_flags = readNonNegativeInteger(*val);
144 ++val;
145 }
146 else {
147 NDN_THROW(Error("missing required Flags field"));
148 }
149}
150
153{
154 m_wire.reset();
155 m_kind = kind;
156 return *this;
157}
158
159bool
161{
162 return a.getFaceId() == b.getFaceId() &&
163 a.getRemoteUri() == b.getRemoteUri() &&
164 a.getLocalUri() == b.getLocalUri() &&
165 a.getFaceScope() == b.getFaceScope() &&
167 a.getLinkType() == b.getLinkType() &&
168 a.getFlags() == b.getFlags() &&
169 a.getKind() == b.getKind();
170}
171
172std::ostream&
173operator<<(std::ostream& os, const FaceEventNotification& notification)
174{
175 os << "FaceEvent(Kind: " << notification.getKind() << ",\n"
176 << " FaceId: " << notification.getFaceId() << ",\n"
177 << " RemoteUri: " << notification.getRemoteUri() << ",\n"
178 << " LocalUri: " << notification.getLocalUri() << ",\n"
179 << " FaceScope: " << notification.getFaceScope() << ",\n"
180 << " FacePersistency: " << notification.getFacePersistency() << ",\n"
181 << " LinkType: " << notification.getLinkType() << ",\n"
182 << " Flags: " << AsHex{notification.getFlags()} << "\n";
183
184 return os << " )";
185}
186
187} // namespace ndn::nfd
Helper class to convert a number to hexadecimal format, for use with stream insertion operators.
Represents a TLV element of the NDN packet format.
Definition block.hpp:45
element_const_iterator elements_begin() const noexcept
Equivalent to elements().begin().
Definition block.hpp:433
element_const_iterator elements_end() const noexcept
Equivalent to elements().end().
Definition block.hpp:442
bool hasWire() const noexcept
Check if the Block contains a fully encoded wire representation.
Definition block.hpp:205
uint32_t type() const noexcept
Return the TLV-TYPE of the Block.
Definition block.hpp:275
void reset() noexcept
Reset the Block to a default-constructed state.
Definition block.cpp:293
void parse() const
Parse TLV-VALUE into sub-elements.
Definition block.cpp:326
Represents a Face status change notification.
const Block & wireEncode() const
Encode FaceEventNotification.
FaceEventNotification & setKind(FaceEventKind kind)
void wireDecode(const Block &wire)
Decode FaceEventNotification.
uint64_t getFlags() const
FacePersistency getFacePersistency() const
const std::string & getLocalUri() const
const std::string & getRemoteUri() const
uint64_t getFaceId() const
FaceScope getFaceScope() const
LinkType getLinkType() const
#define NDN_CXX_DEFINE_WIRE_ENCODE_INSTANTIATIONS(ClassName)
#define NDN_THROW(e)
Definition exception.hpp:56
Contains classes and functions related to the NFD Management protocol.
std::ostream & operator<<(std::ostream &os, FaceScope faceScope)
bool operator==(const ChannelStatus &a, const ChannelStatus &b)
@ FaceEventNotification
Definition tlv-nfd.hpp:74