From bea8a587c65d11b8a2a4307a05ced0d384dce86b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Henrik=20S=2E=20Ga=C3=9Fmann?= Date: Wed, 19 Apr 2023 09:10:31 +0200 Subject: [PATCH 1/4] build: Update dependencies @2023-04-15 --- .github/workflows/cpp-ci.yml | 4 ++-- vcpkg-configuration.json | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/cpp-ci.yml b/.github/workflows/cpp-ci.yml index 84c784c..4406d9e 100644 --- a/.github/workflows/cpp-ci.yml +++ b/.github/workflows/cpp-ci.yml @@ -40,7 +40,7 @@ jobs: uses: lukka/run-vcpkg@v10 with: vcpkgDirectory: ${{ github.workspace }}/build/vcpkg - vcpkgGitCommitId: 1271068e139c1fc30bae405c0bca0e379e155bd2 + vcpkgGitCommitId: 501db0f17ef6df184fcdbfbe0f87cde2313b6ab1 prependedCacheKey: compiler=${{ matrix.compiler }} #appendedCacheKey: r00 @@ -100,7 +100,7 @@ jobs: uses: lukka/run-vcpkg@v10 with: vcpkgDirectory: ${{ github.workspace }}/../vcpkg - vcpkgGitCommitId: 1271068e139c1fc30bae405c0bca0e379e155bd2 + vcpkgGitCommitId: 501db0f17ef6df184fcdbfbe0f87cde2313b6ab1 prependedCacheKey: compiler=clang-15 #appendedCacheKey: r00 diff --git a/vcpkg-configuration.json b/vcpkg-configuration.json index 1a1a782..3d1ae51 100644 --- a/vcpkg-configuration.json +++ b/vcpkg-configuration.json @@ -2,7 +2,7 @@ "$schema": "https://raw.githubusercontent.com/microsoft/vcpkg-tool/main/docs/vcpkg-configuration.schema.json", "default-registry": { "kind": "builtin", - "baseline": "1271068e139c1fc30bae405c0bca0e379e155bd2" + "baseline": "501db0f17ef6df184fcdbfbe0f87cde2313b6ab1" }, "registries": [ { From c60ee4295cee911ed9a1304b9257def4aa8cafbf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Henrik=20S=2E=20Ga=C3=9Fmann?= Date: Wed, 19 Apr 2023 09:11:04 +0200 Subject: [PATCH 2/4] feat: Add status-code `string_ref` encoder --- sources.cmake | 1 + src/dplx/dp/codecs/system_error2.cpp | 28 ++++++++++++++ src/dplx/dp/codecs/system_error2.hpp | 43 +++++++++++++++++++++ src/dplx/dp/codecs/system_error2.test.cpp | 46 +++++++++++++++++++++++ 4 files changed, 118 insertions(+) create mode 100644 src/dplx/dp/codecs/system_error2.cpp create mode 100644 src/dplx/dp/codecs/system_error2.hpp create mode 100644 src/dplx/dp/codecs/system_error2.test.cpp diff --git a/sources.cmake b/sources.cmake index 01bfc7c..8c1d8ae 100644 --- a/sources.cmake +++ b/sources.cmake @@ -12,6 +12,7 @@ dplx_target_sources(deeppack dp/codecs/std-chrono dp/codecs/std-filesystem dp/codecs/std-string + dp/codecs/system_error2 dp/items/skip_item ) diff --git a/src/dplx/dp/codecs/system_error2.cpp b/src/dplx/dp/codecs/system_error2.cpp new file mode 100644 index 0000000..048cfdb --- /dev/null +++ b/src/dplx/dp/codecs/system_error2.cpp @@ -0,0 +1,28 @@ + +// Copyright 2023 Henrik Steffen Gaßmann +// +// Distributed under the Boost Software License, Version 1.0. +// (See accompanying file LICENSE or copy at +// https://www.boost.org/LICENSE_1_0.txt) + +#include "dplx/dp/codecs/system_error2.hpp" + +#include +#include +#include + +namespace dplx::dp +{ + +auto codec::size_of( + emit_context &ctx, value_type const &value) noexcept -> std::uint64_t +{ + return dp::item_size_of_u8string(ctx, value.size()); +} +auto codec::encode( + emit_context &ctx, value_type const &value) noexcept -> result +{ + return dp::emit_u8string(ctx, value.data(), value.size()); +} + +} // namespace dplx::dp diff --git a/src/dplx/dp/codecs/system_error2.hpp b/src/dplx/dp/codecs/system_error2.hpp new file mode 100644 index 0000000..98d7b16 --- /dev/null +++ b/src/dplx/dp/codecs/system_error2.hpp @@ -0,0 +1,43 @@ + +// Copyright 2023 Henrik Steffen Gaßmann +// +// Distributed under the Boost Software License, Version 1.0. +// (See accompanying file LICENSE or copy at +// https://www.boost.org/LICENSE_1_0.txt) + +#pragma once + +#include + +#include + +#include + +namespace dplx::dp +{ + +template <> +class codec +{ + using value_type = SYSTEM_ERROR2_NAMESPACE::status_code_domain::string_ref; + +public: + static auto size_of(emit_context &ctx, value_type const &value) noexcept + -> std::uint64_t; + static auto encode(emit_context &ctx, value_type const &value) noexcept + -> result; +}; +template <> +class codec + : public codec +{ +}; +template StringRef> +class codec + : public codec +{ +}; + +} // namespace dplx::dp diff --git a/src/dplx/dp/codecs/system_error2.test.cpp b/src/dplx/dp/codecs/system_error2.test.cpp new file mode 100644 index 0000000..10c18b3 --- /dev/null +++ b/src/dplx/dp/codecs/system_error2.test.cpp @@ -0,0 +1,46 @@ + +// Copyright 2023 Henrik Steffen Gaßmann +// +// Distributed under the Boost Software License, Version 1.0. +// (See accompanying file LICENSE or copy at +// https://www.boost.org/LICENSE_1_0.txt) + +#include "dplx/dp/codecs/system_error2.hpp" + +#include + +#include + +#include "blob_matcher.hpp" +#include "item_sample_ct.hpp" +#include "test_input_stream.hpp" +#include "test_output_stream.hpp" +#include "test_utils.hpp" + +namespace dp_tests +{ + +using string_ref = dp::system_error::status_code_domain::string_ref; + +TEST_CASE("system_error2::status_code_domain::string_ref should be encodable") +{ + item_sample_ct const sample{ + "some", 5, {0x64, u8's', u8'o', u8'm', u8'e'} + }; + string_ref value(sample.value.data(), sample.value.size()); + + SECTION("to a stream") + { + simple_test_output_stream outputStream(sample.encoded_length); + + REQUIRE(dp::encode(outputStream, value)); + + CHECK_BLOB_EQ(outputStream.written(), sample.encoded_bytes()); + } + SECTION("with a size_of operator") + { + CHECK(dp::encoded_size_of(value) == sample.encoded_length); + } +} + +} // namespace dp_tests From 90b309cf633176bfba3f2c2f95d073c798e961ed Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Henrik=20S=2E=20Ga=C3=9Fmann?= Date: Wed, 19 Apr 2023 09:11:57 +0200 Subject: [PATCH 3/4] feat: Add `cncr::uuid` codec --- sources.cmake | 1 + src/dplx/dp/codecs/uuid.cpp | 45 ++++++++++++++++++++ src/dplx/dp/codecs/uuid.hpp | 29 +++++++++++++ src/dplx/dp/codecs/uuid.test.cpp | 72 ++++++++++++++++++++++++++++++++ 4 files changed, 147 insertions(+) create mode 100644 src/dplx/dp/codecs/uuid.cpp create mode 100644 src/dplx/dp/codecs/uuid.hpp create mode 100644 src/dplx/dp/codecs/uuid.test.cpp diff --git a/sources.cmake b/sources.cmake index 8c1d8ae..676740b 100644 --- a/sources.cmake +++ b/sources.cmake @@ -13,6 +13,7 @@ dplx_target_sources(deeppack dp/codecs/std-filesystem dp/codecs/std-string dp/codecs/system_error2 + dp/codecs/uuid dp/items/skip_item ) diff --git a/src/dplx/dp/codecs/uuid.cpp b/src/dplx/dp/codecs/uuid.cpp new file mode 100644 index 0000000..aaf86b5 --- /dev/null +++ b/src/dplx/dp/codecs/uuid.cpp @@ -0,0 +1,45 @@ + +// Copyright 2023 Henrik Steffen Gaßmann +// +// Distributed under the Boost Software License, Version 1.0. +// (See accompanying file LICENSE or copy at +// https://www.boost.org/LICENSE_1_0.txt) + +#include "dplx/dp/codecs/uuid.hpp" + +#include + +namespace dplx::dp +{ + +auto dplx::dp::codec::decode(parse_context &ctx, + cncr::uuid &value) noexcept + -> result +{ + constexpr auto stateSize = cncr::uuid::state_size; + DPLX_TRY(dp::expect_item_head(ctx, type_code::binary, stateSize)); + + // NOLINTNEXTLINE(cppcoreguidelines-pro-type-member-init) + cncr::blob raw; + DPLX_TRY(ctx.in.bulk_read(static_cast(raw.values), stateSize)); + + value = cncr::uuid(raw.values); + return oc::success(); +} + +auto codec::encode(emit_context &ctx, + cncr::uuid const value) noexcept -> result +{ + auto const canonical = value.canonical(); + return dp::emit_binary(ctx, + static_cast(canonical.values), + sizeof(canonical.values)); +} + +auto codec::size_of(emit_context &ctx, cncr::uuid) noexcept + -> std::uint64_t +{ + return dp::item_size_of_binary(ctx, cncr::uuid::state_size); +} + +} // namespace dplx::dp diff --git a/src/dplx/dp/codecs/uuid.hpp b/src/dplx/dp/codecs/uuid.hpp new file mode 100644 index 0000000..0e8b2d7 --- /dev/null +++ b/src/dplx/dp/codecs/uuid.hpp @@ -0,0 +1,29 @@ + +// Copyright 2023 Henrik Steffen Gaßmann +// +// Distributed under the Boost Software License, Version 1.0. +// (See accompanying file LICENSE or copy at +// https://www.boost.org/LICENSE_1_0.txt) + +#pragma once + +#include + +#include + +namespace dplx::dp +{ + +template <> +class codec +{ +public: + static auto decode(parse_context &ctx, cncr::uuid &value) noexcept + -> result; + static auto encode(emit_context &ctx, cncr::uuid value) noexcept + -> result; + static auto size_of(emit_context &ctx, cncr::uuid value) noexcept + -> std::uint64_t; +}; + +} // namespace dplx::dp diff --git a/src/dplx/dp/codecs/uuid.test.cpp b/src/dplx/dp/codecs/uuid.test.cpp new file mode 100644 index 0000000..1992e76 --- /dev/null +++ b/src/dplx/dp/codecs/uuid.test.cpp @@ -0,0 +1,72 @@ + +// Copyright 2023 Henrik Steffen Gaßmann +// +// Distributed under the Boost Software License, Version 1.0. +// (See accompanying file LICENSE or copy at +// https://www.boost.org/LICENSE_1_0.txt) + +#include "dplx/dp/codecs/uuid.hpp" + +#include +#include + +#include + +#include "blob_matcher.hpp" +#include "item_sample_ct.hpp" +#include "range_generator.hpp" +#include "test_input_stream.hpp" +#include "test_output_stream.hpp" +#include "test_utils.hpp" + +namespace dp_tests +{ + +namespace +{ + +using namespace cncr::uuid_literals; + +constexpr item_sample_ct uuid_samples[] = { + {"00000000-0000-0000-0000-000000000000"_uuid, + 17, {0x50, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}}, + {"00000000-0000-4000-bfff-ffffffffffff"_uuid, + 17, {0x50, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x40, 0x00, 0xbf, 0xff, + 0xff, 0xff, 0xff, 0xff, 0xff, 0xff}}, + {"ffffffff-ffff-ffff-ffff-ffffffffffff"_uuid, + 17, {0x50, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, + 0xff, 0xff, 0xff, 0xff, 0xff, 0xff}}, +}; + +} // namespace + +TEST_CASE("cncr::uuid has a codec") +{ + auto const sample = GENERATE(borrowed_range(uuid_samples)); + INFO(sample); + + SECTION("with encode") + { + simple_test_output_stream outputStream(sample.encoded_length); + + REQUIRE(dp::encode(outputStream, sample.value)); + + CHECK_BLOB_EQ(outputStream.written(), sample.encoded_bytes()); + } + SECTION("with size_of") + { + CHECK(dp::encoded_size_of(sample.value) == sample.encoded_length); + } + SECTION("with decode") + { + simple_test_input_stream inputStream(sample.encoded_bytes()); + + cncr::uuid value{}; + REQUIRE(dp::decode(inputStream, value)); + + CHECK(value == sample.value); + } +} + +} // namespace dp_tests From 7fdd5cf45adeddc70fd1b181df92afb822c72256 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Henrik=20S=2E=20Ga=C3=9Fmann?= Date: Wed, 19 Apr 2023 10:07:21 +0200 Subject: [PATCH 4/4] build: Prevent `_TRY` macros from inflating complexity --- .clang-tidy | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.clang-tidy b/.clang-tidy index 61c87a0..0bcd253 100644 --- a/.clang-tidy +++ b/.clang-tidy @@ -30,3 +30,5 @@ CheckOptions: value: true - key: cppcoreguidelines-macro-usage.AllowedRegexp value: "DPLX_.+_WORKAROUND(_TESTED_AT)?" + - key: readability-function-cognitive-complexity.IgnoreMacros + value: true