]> git.ipfire.org Git - thirdparty/pdns.git/commitdiff
import views.hh from master
authorPeter van Dijk <peter.van.dijk@powerdns.com>
Tue, 2 Jul 2024 10:48:38 +0000 (12:48 +0200)
committerPeter van Dijk <peter.van.dijk@powerdns.com>
Tue, 2 Jul 2024 12:22:17 +0000 (14:22 +0200)
pdns/Makefile.am
pdns/dnsdistdist/views.hh [new symlink]
pdns/recursordist/views.hh [new symlink]
pdns/views.hh [new file with mode: 0644]

index 263bf3cd01867378de6ee64ece90125da43f8ff0..bee1d58ef06d9ef2bf07f4dd03bf6c1ab84a515a 100644 (file)
@@ -287,6 +287,7 @@ pdns_server_SOURCES = \
        utility.hh \
        uuid-utils.hh uuid-utils.cc \
        version.cc version.hh \
+       views.hh \
        webserver.cc webserver.hh \
        ws-api.cc ws-api.hh \
        ws-auth.cc ws-auth.hh \
diff --git a/pdns/dnsdistdist/views.hh b/pdns/dnsdistdist/views.hh
new file mode 120000 (symlink)
index 0000000..2213b7d
--- /dev/null
@@ -0,0 +1 @@
+../views.hh
\ No newline at end of file
diff --git a/pdns/recursordist/views.hh b/pdns/recursordist/views.hh
new file mode 120000 (symlink)
index 0000000..2213b7d
--- /dev/null
@@ -0,0 +1 @@
+../views.hh
\ No newline at end of file
diff --git a/pdns/views.hh b/pdns/views.hh
new file mode 100644 (file)
index 0000000..b6be930
--- /dev/null
@@ -0,0 +1,73 @@
+/*
+ * This file is part of PowerDNS or dnsdist.
+ * Copyright -- PowerDNS.COM B.V. and its contributors
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of version 2 of the GNU General Public License as
+ * published by the Free Software Foundation.
+ *
+ * In addition, for the avoidance of any doubt, permission is granted to
+ * link this program with OpenSSL and to (re)distribute the binaries
+ * produced as the result of such linking.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ */
+#pragma once
+
+#include <string_view>
+
+namespace pdns::views
+{
+
+class UnsignedCharView
+{
+public:
+  UnsignedCharView(const char* data_, size_t size_) :
+    view(data_, size_)
+  {
+  }
+  // NOLINTBEGIN(cppcoreguidelines-pro-type-reinterpret-cast): No unsigned char view in C++17
+  UnsignedCharView(const unsigned char* data_, size_t size_) :
+    view(reinterpret_cast<const char*>(data_), size_)
+  {
+  }
+  using size_type = std::string_view::size_type;
+
+  [[nodiscard]] const unsigned char& at(size_type pos) const
+  {
+    return reinterpret_cast<const unsigned char&>(view.at(pos));
+  }
+
+  [[nodiscard]] const unsigned char& operator[](size_type pos) const
+  {
+    return reinterpret_cast<const unsigned char&>(view[pos]);
+  }
+
+  [[nodiscard]] const unsigned char* data() const
+  {
+    return reinterpret_cast<const unsigned char*>(view.data());
+  }
+  // NOLINTEND(cppcoreguidelines-pro-type-reinterpret-cast): No unsigned char view in C++17
+
+  [[nodiscard]] size_t size() const
+  {
+    return view.size();
+  }
+
+  [[nodiscard]] size_t length() const
+  {
+    return view.length();
+  }
+
+private:
+  std::string_view view;
+};
+
+}