From 99bf661661e46c6ca4ee71b955fb00f5b9baa130 Mon Sep 17 00:00:00 2001 From: Peter van Dijk Date: Tue, 2 Jul 2024 12:48:38 +0200 Subject: [PATCH] import views.hh from master --- pdns/Makefile.am | 1 + pdns/dnsdistdist/views.hh | 1 + pdns/recursordist/views.hh | 1 + pdns/views.hh | 73 ++++++++++++++++++++++++++++++++++++++ 4 files changed, 76 insertions(+) create mode 120000 pdns/dnsdistdist/views.hh create mode 120000 pdns/recursordist/views.hh create mode 100644 pdns/views.hh diff --git a/pdns/Makefile.am b/pdns/Makefile.am index 263bf3cd01..bee1d58ef0 100644 --- a/pdns/Makefile.am +++ b/pdns/Makefile.am @@ -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 index 0000000000..2213b7d900 --- /dev/null +++ b/pdns/dnsdistdist/views.hh @@ -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 index 0000000000..2213b7d900 --- /dev/null +++ b/pdns/recursordist/views.hh @@ -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 index 0000000000..b6be93019c --- /dev/null +++ b/pdns/views.hh @@ -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 + +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(data_), size_) + { + } + using size_type = std::string_view::size_type; + + [[nodiscard]] const unsigned char& at(size_type pos) const + { + return reinterpret_cast(view.at(pos)); + } + + [[nodiscard]] const unsigned char& operator[](size_type pos) const + { + return reinterpret_cast(view[pos]); + } + + [[nodiscard]] const unsigned char* data() const + { + return reinterpret_cast(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; +}; + +} -- 2.47.2