ndn-cxx: NDN C++ Library 0.9.0-33-g832ea91d
Loading...
Searching...
No Matches
face-query-filter.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
25
26namespace ndn::nfd {
27
29
31{
32 this->wireDecode(block);
33}
34
35template<encoding::Tag TAG>
36size_t
38{
39 size_t totalLength = 0;
40
41 if (m_linkType) {
42 totalLength += prependNonNegativeIntegerBlock(encoder,
43 tlv::nfd::LinkType, *m_linkType);
44 }
45
46 if (m_facePersistency) {
47 totalLength += prependNonNegativeIntegerBlock(encoder,
48 tlv::nfd::FacePersistency, *m_facePersistency);
49 }
50
51 if (m_faceScope) {
52 totalLength += prependNonNegativeIntegerBlock(encoder,
53 tlv::nfd::FaceScope, *m_faceScope);
54 }
55
56 if (hasLocalUri()) {
57 totalLength += prependStringBlock(encoder, tlv::nfd::LocalUri, m_localUri);
58 }
59
60 if (hasRemoteUri()) {
61 totalLength += prependStringBlock(encoder, tlv::nfd::Uri, m_remoteUri);
62 }
63
64 if (hasUriScheme()) {
65 totalLength += prependStringBlock(encoder, tlv::nfd::UriScheme, m_uriScheme);
66 }
67
68 if (m_faceId) {
69 totalLength += prependNonNegativeIntegerBlock(encoder,
70 tlv::nfd::FaceId, *m_faceId);
71 }
72
73 totalLength += encoder.prependVarNumber(totalLength);
74 totalLength += encoder.prependVarNumber(tlv::nfd::FaceQueryFilter);
75 return totalLength;
76}
77
79
80const Block&
82{
83 if (m_wire.hasWire())
84 return m_wire;
85
86 EncodingEstimator estimator;
87 size_t estimatedSize = wireEncode(estimator);
88
89 EncodingBuffer buffer(estimatedSize, 0);
90 wireEncode(buffer);
91
92 m_wire = buffer.block();
93 return m_wire;
94}
95
96void
98{
99 if (block.type() != tlv::nfd::FaceQueryFilter) {
100 NDN_THROW(Error("FaceQueryFilter", block.type()));
101 }
102
103 m_wire = block;
104 m_wire.parse();
105 auto val = m_wire.elements_begin();
106
107 // all fields are optional
108
109 if (val != m_wire.elements_end() && val->type() == tlv::nfd::FaceId) {
110 m_faceId = readNonNegativeInteger(*val);
111 ++val;
112 }
113 else {
114 m_faceId = std::nullopt;
115 }
116
117 if (val != m_wire.elements_end() && val->type() == tlv::nfd::UriScheme) {
118 m_uriScheme = readString(*val);
119 ++val;
120 }
121 else {
122 m_uriScheme.clear();
123 }
124
125 if (val != m_wire.elements_end() && val->type() == tlv::nfd::Uri) {
126 m_remoteUri = readString(*val);
127 ++val;
128 }
129 else {
130 m_remoteUri.clear();
131 }
132
133 if (val != m_wire.elements_end() && val->type() == tlv::nfd::LocalUri) {
134 m_localUri = readString(*val);
135 ++val;
136 }
137 else {
138 m_localUri.clear();
139 }
140
141 if (val != m_wire.elements_end() && val->type() == tlv::nfd::FaceScope) {
142 m_faceScope = readNonNegativeIntegerAs<FaceScope>(*val);
143 ++val;
144 }
145 else {
146 m_faceScope = std::nullopt;
147 }
148
149 if (val != m_wire.elements_end() && val->type() == tlv::nfd::FacePersistency) {
150 m_facePersistency = readNonNegativeIntegerAs<FacePersistency>(*val);
151 ++val;
152 }
153 else {
154 m_facePersistency = std::nullopt;
155 }
156
157 if (val != m_wire.elements_end() && val->type() == tlv::nfd::LinkType) {
158 m_linkType = readNonNegativeIntegerAs<LinkType>(*val);
159 ++val;
160 }
161 else {
162 m_linkType = std::nullopt;
163 }
164}
165
166bool
168{
169 return !this->hasFaceId() &&
170 !this->hasUriScheme() &&
171 !this->hasRemoteUri() &&
172 !this->hasLocalUri() &&
173 !this->hasFaceScope() &&
174 !this->hasFacePersistency() &&
175 !this->hasLinkType();
176}
177
180{
181 m_wire.reset();
182 m_faceId = faceId;
183 return *this;
184}
185
188{
189 m_wire.reset();
190 m_faceId = std::nullopt;
191 return *this;
192}
193
195FaceQueryFilter::setUriScheme(const std::string& uriScheme)
196{
197 m_wire.reset();
198 m_uriScheme = uriScheme;
199 return *this;
200}
201
204{
205 return this->setUriScheme("");
206}
207
209FaceQueryFilter::setRemoteUri(const std::string& remoteUri)
210{
211 m_wire.reset();
212 m_remoteUri = remoteUri;
213 return *this;
214}
215
218{
219 return this->setRemoteUri("");
220}
221
223FaceQueryFilter::setLocalUri(const std::string& localUri)
224{
225 m_wire.reset();
226 m_localUri = localUri;
227 return *this;
228}
229
232{
233 return this->setLocalUri("");
234}
235
238{
239 m_wire.reset();
240 m_faceScope = faceScope;
241 return *this;
242}
243
246{
247 m_wire.reset();
248 m_faceScope = std::nullopt;
249 return *this;
250}
251
254{
255 m_wire.reset();
256 m_facePersistency = facePersistency;
257 return *this;
258}
259
262{
263 m_wire.reset();
264 m_facePersistency = std::nullopt;
265 return *this;
266}
267
270{
271 m_wire.reset();
272 m_linkType = linkType;
273 return *this;
274}
275
278{
279 m_wire.reset();
280 m_linkType = std::nullopt;
281 return *this;
282}
283
284bool
286{
287 return a.hasFaceId() == b.hasFaceId() &&
288 (!a.hasFaceId() || a.getFaceId() == b.getFaceId()) &&
289 a.hasUriScheme() == b.hasUriScheme() &&
290 (!a.hasUriScheme() || a.getUriScheme() == b.getUriScheme()) &&
291 a.hasRemoteUri() == b.hasRemoteUri() &&
292 (!a.hasRemoteUri() || a.getRemoteUri() == b.getRemoteUri()) &&
293 a.hasLocalUri() == b.hasLocalUri() &&
294 (!a.hasLocalUri() || a.getLocalUri() == b.getLocalUri()) &&
295 a.hasFaceScope() == b.hasFaceScope() &&
296 (!a.hasFaceScope() || a.getFaceScope() == b.getFaceScope()) &&
299 a.hasLinkType() == b.hasLinkType() &&
300 (!a.hasLinkType() || a.getLinkType() == b.getLinkType());
301}
302
303std::ostream&
304operator<<(std::ostream& os, const FaceQueryFilter& filter)
305{
306 os << "FaceQueryFilter(";
307 if (filter.hasFaceId()) {
308 os << "FaceID: " << filter.getFaceId() << ",\n";
309 }
310
311 if (filter.hasUriScheme()) {
312 os << "UriScheme: " << filter.getUriScheme() << ",\n";
313 }
314
315 if (filter.hasRemoteUri()) {
316 os << "RemoteUri: " << filter.getRemoteUri() << ",\n";
317 }
318
319 if (filter.hasLocalUri()) {
320 os << "LocalUri: " << filter.getLocalUri() << ",\n";
321 }
322
323 if (filter.hasFaceScope()) {
324 os << "FaceScope: " << filter.getFaceScope() << ",\n";
325 }
326
327 if (filter.hasFacePersistency()) {
328 os << "FacePersistency: " << filter.getFacePersistency() << ",\n";
329 }
330
331 if (filter.hasLinkType()) {
332 os << "LinkType: " << filter.getLinkType() << ",\n";
333 }
334 os << ")";
335 return os;
336}
337
338} // namespace ndn::nfd
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 Face Query Filter.
const std::string & getLocalUri() const
const Block & wireEncode() const
Encode FaceQueryFilter.
FaceQueryFilter & unsetUriScheme()
FaceQueryFilter & unsetRemoteUri()
FaceQueryFilter & unsetFaceScope()
const std::string & getRemoteUri() const
FaceQueryFilter & setRemoteUri(const std::string &remoteUri)
FaceQueryFilter & unsetLinkType()
const std::string & getUriScheme() const
FaceQueryFilter & unsetFaceId()
FaceQueryFilter & unsetFacePersistency()
FaceQueryFilter & setFaceScope(FaceScope faceScope)
FacePersistency getFacePersistency() const
FaceQueryFilter & setFaceId(uint64_t faceId)
FaceQueryFilter & setFacePersistency(FacePersistency facePersistency)
FaceQueryFilter & setLocalUri(const std::string &localUri)
void wireDecode(const Block &wire)
Decode FaceQueryFilter.
FaceQueryFilter & setLinkType(LinkType linkType)
FaceQueryFilter & unsetLocalUri()
FaceQueryFilter & setUriScheme(const std::string &uriScheme)
#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)