From 76c63dff22a4d3dcee805ecde370ce12b097f6d5 Mon Sep 17 00:00:00 2001 From: Rustam Gamidov <108531570+rustam-gamidov-here@users.noreply.github.com> Date: Tue, 10 Feb 2026 13:53:51 +0200 Subject: [PATCH 01/12] CI: Add build with OLP_SDK_NO_EXCEPTION=ON (#1661) To catch issues in this kind of build earlier Relates-To: OCMAM-442 Signed-off-by: Rustam Gamidov --- .github/workflows/psv_pipelines.yml | 15 ++++++++ scripts/linux/psv/build_psv_no_exceptions.sh | 37 ++++++++++++++++++++ 2 files changed, 52 insertions(+) create mode 100755 scripts/linux/psv/build_psv_no_exceptions.sh diff --git a/.github/workflows/psv_pipelines.yml b/.github/workflows/psv_pipelines.yml index 5b9551c7c..6950e6f77 100644 --- a/.github/workflows/psv_pipelines.yml +++ b/.github/workflows/psv_pipelines.yml @@ -108,6 +108,21 @@ jobs: run: ./scripts/linux/psv/test_psv.sh shell: bash + psv-linux-22-04-gcc11-build-no-exceptions: + name: PSV.Linux.22.04.gcc11.OLP_SDK_NO_EXCEPTION=ON + runs-on: ubuntu-22.04 + env: + BUILD_TYPE: RelWithDebInfo + steps: + - name: Check out repository + uses: actions/checkout@v4 + - name: Install Ubuntu dependencies + run: sudo apt-get update && sudo apt-get install -y ccache libssl-dev libcurl4-openssl-dev --no-install-recommends + shell: bash + - name: Compile project with cmake and ccache + run: gcc --version && ./scripts/linux/psv/build_psv_no_exceptions.sh + shell: bash + psv-linux-latest-gcc14-build-no-cache: name: PSV.Linux.latest.gcc14.OLP_SDK_ENABLE_DEFAULT_CACHE=OFF runs-on: ubuntu-latest diff --git a/scripts/linux/psv/build_psv_no_exceptions.sh b/scripts/linux/psv/build_psv_no_exceptions.sh new file mode 100755 index 000000000..5fa847409 --- /dev/null +++ b/scripts/linux/psv/build_psv_no_exceptions.sh @@ -0,0 +1,37 @@ +#!/bin/bash -ex +# +# Copyright (C) 2026 HERE Europe B.V. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +# SPDX-License-Identifier: Apache-2.0 +# License-Filename: LICENSE + +# Show initial ccache data +ccache -s + +mkdir -p build +cd build + +cmake -DCMAKE_BUILD_TYPE=$BUILD_TYPE \ + -DCMAKE_CXX_FLAGS="-Wall -Wextra -Werror $CXXFLAGS" \ + -DCMAKE_CXX_COMPILER_LAUNCHER=ccache \ + -DOLP_SDK_BUILD_EXAMPLES=ON \ + -DBUILD_SHARED_LIBS=ON \ + -DOLP_SDK_NO_EXCEPTION=ON \ + .. + +cmake --build . -- -j$(nproc) + +# Show last ccache data +ccache -s From 29f591ddd8c267e3bc405fd6dd57fcfb559390d0 Mon Sep 17 00:00:00 2001 From: Rustam Gamidov <108531570+rustam-gamidov-here@users.noreply.github.com> Date: Thu, 12 Feb 2026 12:05:52 +0200 Subject: [PATCH 02/12] Integrate Boost.Json patching 1.82 for no exception (#1662) Patch boost::json 1.82 with BOOST_NO_EXCEPTIONS Is is solved in boost::json 1.83 but we preferred to stay at 1.82 Relates-To: OCMAM-442 Signed-off-by: Rustam Gamidov --- external/boost/CMakeLists.txt | 4 +- external/boost/CMakeLists.txt.boost.in | 12 +++- .../boost/boost_182_json_noexceptions.diff | 30 +++++++++ olp-cpp-sdk-core/CMakeLists.txt | 4 ++ olp-cpp-sdk-core/src/utils/BoostJsonSrc.cpp | 20 ++++++ olp-cpp-sdk-core/tests/CMakeLists.txt | 3 +- olp-cpp-sdk-core/tests/utils/JsonTest.cpp | 67 +++++++++++++++++++ tests/common/CMakeLists.txt | 5 +- 8 files changed, 139 insertions(+), 6 deletions(-) create mode 100644 external/boost/boost_182_json_noexceptions.diff create mode 100644 olp-cpp-sdk-core/src/utils/BoostJsonSrc.cpp create mode 100644 olp-cpp-sdk-core/tests/utils/JsonTest.cpp diff --git a/external/boost/CMakeLists.txt b/external/boost/CMakeLists.txt index 618d0fe09..43f9396e9 100644 --- a/external/boost/CMakeLists.txt +++ b/external/boost/CMakeLists.txt @@ -1,4 +1,4 @@ -# Copyright (C) 2019-2020 HERE Europe B.V. +# Copyright (C) 2019-2026 HERE Europe B.V. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -32,6 +32,8 @@ else() set(B2_CMD ./b2) endif() +set(PATCH_BOOST_CMD "git apply -v ${CMAKE_CURRENT_SOURCE_DIR}/boost_182_json_noexceptions.diff") + configure_file(CMakeLists.txt.boost.in download/CMakeLists.txt @ONLY) set(CMAKE_VERBOSE_MAKEFILE ON) diff --git a/external/boost/CMakeLists.txt.boost.in b/external/boost/CMakeLists.txt.boost.in index d526f9278..cbf5a4080 100644 --- a/external/boost/CMakeLists.txt.boost.in +++ b/external/boost/CMakeLists.txt.boost.in @@ -1,4 +1,4 @@ -# Copyright (C) 2019-2020 HERE Europe B.V. +# Copyright (C) 2019-2026 HERE Europe B.V. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -25,6 +25,7 @@ ExternalProject_Add(boost-download GIT_REPOSITORY @OLP_SDK_CPP_BOOST_URL@ GIT_TAG @OLP_SDK_CPP_BOOST_TAG@ GIT_SUBMODULES libs/algorithm + libs/align libs/any libs/array libs/assert @@ -34,18 +35,20 @@ ExternalProject_Add(boost-download libs/container_hash libs/core libs/date_time - libs/detail libs/describe + libs/detail libs/format libs/function_types libs/headers libs/integer + libs/intrusive libs/io libs/iterator + libs/json libs/lexical_cast libs/move - libs/mpl libs/mp11 + libs/mpl libs/numeric/conversion libs/optional libs/predef @@ -55,6 +58,7 @@ ExternalProject_Add(boost-download libs/serialization libs/smart_ptr libs/static_assert + libs/system libs/throw_exception libs/tokenizer libs/tti @@ -62,11 +66,13 @@ ExternalProject_Add(boost-download libs/type_traits libs/utility libs/uuid + libs/variant2 libs/winapi tools/build tools/boost_install GIT_SHALLOW 1 SOURCE_DIR "@CMAKE_CURRENT_BINARY_DIR@/external_boost" + PATCH_COMMAND @PATCH_BOOST_CMD@ BUILD_IN_SOURCE 1 UPDATE_COMMAND "" CONFIGURE_COMMAND @BOOTSTRAP_CMD@ diff --git a/external/boost/boost_182_json_noexceptions.diff b/external/boost/boost_182_json_noexceptions.diff new file mode 100644 index 000000000..507e3cecf --- /dev/null +++ b/external/boost/boost_182_json_noexceptions.diff @@ -0,0 +1,30 @@ +diff --git a/libs/json/include/boost/json/impl/value.ipp b/libs/json/include/boost/json/impl/value.ipp +index 7460c02..7513b38 100644 +--- a/libs/json/include/boost/json/impl/value.ipp ++++ b/libs/json/include/boost/json/impl/value.ipp +@@ -381,7 +381,9 @@ operator>>( + char read_buf[BOOST_JSON_STACK_BUFFER_SIZE / 2]; + std::streambuf& buf = *is.rdbuf(); + std::ios::iostate err = std::ios::goodbit; ++#ifndef BOOST_NO_EXCEPTIONS + try ++#endif + { + while( true ) + { +@@ -437,6 +439,7 @@ operator>>( + break; + } + } ++#ifndef BOOST_NO_EXCEPTIONS + catch(...) + { + try +@@ -450,6 +453,7 @@ operator>>( + if( is.exceptions() & std::ios::badbit ) + throw; + } ++#endif + + is.setstate(err | std::ios::failbit); + return is; diff --git a/olp-cpp-sdk-core/CMakeLists.txt b/olp-cpp-sdk-core/CMakeLists.txt index 6190c13dc..e694436ad 100644 --- a/olp-cpp-sdk-core/CMakeLists.txt +++ b/olp-cpp-sdk-core/CMakeLists.txt @@ -359,6 +359,7 @@ endif() set(OLP_SDK_UTILS_SOURCES ./src/utils/Base64.cpp ./src/utils/BoostExceptionHandle.cpp + ./src/utils/BoostJsonSrc.cpp ./src/utils/Credentials.cpp ./src/utils/Dir.cpp ./src/utils/Thread.cpp @@ -456,6 +457,9 @@ if (OLP_SDK_USE_STD_ANY) PUBLIC OLP_SDK_USE_STD_ANY) endif() +target_compile_definitions(${PROJECT_NAME} PRIVATE BOOST_ALL_NO_LIB) +target_compile_definitions(${PROJECT_NAME} PRIVATE BOOST_JSON_NO_LIB) + target_include_directories(${PROJECT_NAME} PUBLIC $ $ diff --git a/olp-cpp-sdk-core/src/utils/BoostJsonSrc.cpp b/olp-cpp-sdk-core/src/utils/BoostJsonSrc.cpp new file mode 100644 index 000000000..017758210 --- /dev/null +++ b/olp-cpp-sdk-core/src/utils/BoostJsonSrc.cpp @@ -0,0 +1,20 @@ +/* + * Copyright (C) 2026 HERE Europe B.V. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * SPDX-License-Identifier: Apache-2.0 + * License-Filename: LICENSE + */ + +#include diff --git a/olp-cpp-sdk-core/tests/CMakeLists.txt b/olp-cpp-sdk-core/tests/CMakeLists.txt index 2b9d25f2e..fc13fc82e 100644 --- a/olp-cpp-sdk-core/tests/CMakeLists.txt +++ b/olp-cpp-sdk-core/tests/CMakeLists.txt @@ -1,4 +1,4 @@ -# Copyright (C) 2019-2025 HERE Europe B.V. +# Copyright (C) 2019-2026 HERE Europe B.V. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -73,6 +73,7 @@ set(OLP_CPP_SDK_CORE_TESTS_SOURCES ./http/NetworkSettingsTest.cpp ./http/NetworkUtils.cpp + ./utils/JsonTest.cpp ./utils/UtilsTest.cpp ./utils/UrlTest.cpp ) diff --git a/olp-cpp-sdk-core/tests/utils/JsonTest.cpp b/olp-cpp-sdk-core/tests/utils/JsonTest.cpp new file mode 100644 index 000000000..ba402a9c3 --- /dev/null +++ b/olp-cpp-sdk-core/tests/utils/JsonTest.cpp @@ -0,0 +1,67 @@ +/* + * Copyright (C) 2026 HERE Europe B.V. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * SPDX-License-Identifier: Apache-2.0 + * License-Filename: LICENSE + */ + +#include + +#include + +namespace { + +using UtilsTest = testing::Test; + +const std::string kJsonData = R"json( + { + "catalogs": [ + { + "hrn": "hrn:here:data::olp:ocm", + "version": 17, + "dependencies": [], + "metadata_type": "partitions" + } + ], + "regions": [ + { + "id": 423423, + "parent_id": 14123411, + "catalogs": [ + { + "hrn": "hrn:here:data::olp:ocm", + "status": "pending", + "size_raw_bytes": 4623545, + "layer_groups": [ + "rendering" + ], + "tiles": [ + 2354325, + 5243252 + ] + } + ] + } + ] + })json"; + +TEST(UtilsTest, BoostJsonAvailable) { + boost::system::error_code error_code; + auto parsed_json = boost::json::parse(kJsonData, error_code); + + EXPECT_FALSE(error_code.failed()); +} + +} // namespace diff --git a/tests/common/CMakeLists.txt b/tests/common/CMakeLists.txt index 90a99c77c..c3331f672 100644 --- a/tests/common/CMakeLists.txt +++ b/tests/common/CMakeLists.txt @@ -1,4 +1,4 @@ -# Copyright (C) 2019-2021 HERE Europe B.V. +# Copyright (C) 2019-2026 HERE Europe B.V. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -50,6 +50,9 @@ target_include_directories(olp-cpp-sdk-tests-common ${CMAKE_CURRENT_SOURCE_DIR}/../../olp-cpp-sdk-dataservice-read/src/ ) +target_compile_definitions(olp-cpp-sdk-tests-common PUBLIC BOOST_CONTAINER_NO_LIB) +target_compile_definitions(olp-cpp-sdk-tests-common PUBLIC BOOST_JSON_NO_LIB) + target_link_libraries(olp-cpp-sdk-tests-common PUBLIC gmock From 5c3ac41aeab59719de2053bd51dcc7664c33ded3 Mon Sep 17 00:00:00 2001 From: asopov-here Date: Tue, 3 Mar 2026 08:53:22 +0100 Subject: [PATCH 03/12] Refactor PartitionsSaxHandler to use boost::json (#1670) Previously it was based on rapidjson The tests are adjusted accordingly. Relates-To: OCMAM-448 Signed-off-by: Alexander Sopov Signed-off-by: Rustam Gamidov --- olp-cpp-sdk-dataservice-read/CMakeLists.txt | 9 + .../src/repositories/AsyncJsonStream.cpp | 44 +++-- .../src/repositories/AsyncJsonStream.h | 18 +- .../src/repositories/PartitionsRepository.cpp | 40 ++-- .../src/repositories/PartitionsSaxHandler.cpp | 73 ++++---- .../src/repositories/PartitionsSaxHandler.h | 95 ++++++++-- .../tests/AsyncJsonStreamTest.cpp | 11 +- .../tests/PartitionsSaxHandlerTest.cpp | 177 ++++++++++-------- 8 files changed, 290 insertions(+), 177 deletions(-) diff --git a/olp-cpp-sdk-dataservice-read/CMakeLists.txt b/olp-cpp-sdk-dataservice-read/CMakeLists.txt index b0e8c05c4..c8a954523 100644 --- a/olp-cpp-sdk-dataservice-read/CMakeLists.txt +++ b/olp-cpp-sdk-dataservice-read/CMakeLists.txt @@ -21,15 +21,24 @@ set(DESCRIPTION "C++ API library for reading OLP data") file(GLOB_RECURSE INC "include/*.h*") file(GLOB_RECURSE SRC "src/*.*") + +find_package(Boost REQUIRED) + add_library(${PROJECT_NAME} ${SRC} ${INC}) +target_compile_definitions(${PROJECT_NAME} + PRIVATE + BOOST_ALL_NO_LIB + BOOST_JSON_NO_LIB) + target_include_directories(${PROJECT_NAME} PUBLIC $ $ PRIVATE $ + $ PRIVATE ${olp-cpp-sdk-core_INCLUDE_DIRS}) target_link_libraries(${PROJECT_NAME} diff --git a/olp-cpp-sdk-dataservice-read/src/repositories/AsyncJsonStream.cpp b/olp-cpp-sdk-dataservice-read/src/repositories/AsyncJsonStream.cpp index a2e0f05e7..2b5540dd2 100644 --- a/olp-cpp-sdk-dataservice-read/src/repositories/AsyncJsonStream.cpp +++ b/olp-cpp-sdk-dataservice-read/src/repositories/AsyncJsonStream.cpp @@ -1,5 +1,5 @@ /* - * Copyright (C) 2023-2025 HERE Europe B.V. + * Copyright (C) 2023-2026 HERE Europe B.V. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -24,14 +24,27 @@ namespace dataservice { namespace read { namespace repository { -RapidJsonByteStream::Ch RapidJsonByteStream::Peek() { +JsonByteStream::Ch JsonByteStream::Peek() { if (ReadEmpty()) { SwapBuffers(); } return read_buffer_[count_]; } -RapidJsonByteStream::Ch RapidJsonByteStream::Take() { +boost::json::string_view JsonByteStream::ReadView() { + if (ReadEmpty()) { + SwapBuffers(); + } + auto begin = read_buffer_.begin() + count_; + auto terminator_it = std::find(begin, read_buffer_.end(), '\0'); + boost::json::string_view::size_type size = + std::distance(begin, terminator_it); + count_ += size; + full_count_ += size; + return {&*begin, size}; +} + +JsonByteStream::Ch JsonByteStream::Take() { if (ReadEmpty()) { SwapBuffers(); } @@ -39,23 +52,15 @@ RapidJsonByteStream::Ch RapidJsonByteStream::Take() { return read_buffer_[count_++]; } -size_t RapidJsonByteStream::Tell() const { return full_count_; } - -// Not implemented -char* RapidJsonByteStream::PutBegin() { return 0; } -void RapidJsonByteStream::Put(char) {} -void RapidJsonByteStream::Flush() {} -size_t RapidJsonByteStream::PutEnd(char*) { return 0; } +size_t JsonByteStream::Tell() const { return full_count_; } -bool RapidJsonByteStream::ReadEmpty() const { - return count_ == read_buffer_.size(); -} -bool RapidJsonByteStream::WriteEmpty() const { +bool JsonByteStream::ReadEmpty() const { return count_ == read_buffer_.size(); } +bool JsonByteStream::WriteEmpty() const { std::unique_lock lock(mutex_); return write_buffer_.empty(); } -void RapidJsonByteStream::AppendContent(const char* content, size_t length) { +void JsonByteStream::AppendContent(const char* content, size_t length) { std::unique_lock lock(mutex_); const auto buffer_size = write_buffer_.size(); @@ -65,7 +70,7 @@ void RapidJsonByteStream::AppendContent(const char* content, size_t length) { cv_.notify_one(); } -void RapidJsonByteStream::SwapBuffers() { +void JsonByteStream::SwapBuffers() { std::unique_lock lock(mutex_); cv_.wait(lock, [&]() { return !write_buffer_.empty(); }); std::swap(read_buffer_, write_buffer_); @@ -74,10 +79,9 @@ void RapidJsonByteStream::SwapBuffers() { } AsyncJsonStream::AsyncJsonStream() - : current_stream_(std::make_shared()), - closed_{false} {} + : current_stream_(std::make_shared()), closed_{false} {} -std::shared_ptr AsyncJsonStream::GetCurrentStream() const { +std::shared_ptr AsyncJsonStream::GetCurrentStream() const { std::unique_lock lock(mutex_); return current_stream_; } @@ -96,7 +100,7 @@ void AsyncJsonStream::ResetStream(const char* content, size_t length) { return; } current_stream_->AppendContent("\0", 1); - current_stream_ = std::make_shared(); + current_stream_ = std::make_shared(); current_stream_->AppendContent(content, length); } diff --git a/olp-cpp-sdk-dataservice-read/src/repositories/AsyncJsonStream.h b/olp-cpp-sdk-dataservice-read/src/repositories/AsyncJsonStream.h index ae1f57ba6..a2adad3f3 100644 --- a/olp-cpp-sdk-dataservice-read/src/repositories/AsyncJsonStream.h +++ b/olp-cpp-sdk-dataservice-read/src/repositories/AsyncJsonStream.h @@ -1,5 +1,5 @@ /* - * Copyright (C) 2023-2025 HERE Europe B.V. + * Copyright (C) 2023-2026 HERE Europe B.V. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -25,6 +25,7 @@ #include #include +#include namespace olp { namespace dataservice { @@ -32,7 +33,7 @@ namespace read { namespace repository { /// Json byte stream class. Implements rapidjson input stream concept. -class RapidJsonByteStream { +class JsonByteStream { public: typedef char Ch; @@ -43,15 +44,12 @@ class RapidJsonByteStream { /// character. Ch Take(); + /// Return the view of current read buffer until the end of first \0 character + boost::json::string_view ReadView(); + /// Get the current read cursor. size_t Tell() const; - /// Not needed for reading. - char* PutBegin(); - void Put(char); - void Flush(); - size_t PutEnd(char*); - bool ReadEmpty() const; bool WriteEmpty() const; @@ -72,7 +70,7 @@ class AsyncJsonStream { public: AsyncJsonStream(); - std::shared_ptr GetCurrentStream() const; + std::shared_ptr GetCurrentStream() const; void AppendContent(const char* content, size_t length); @@ -86,7 +84,7 @@ class AsyncJsonStream { private: mutable std::mutex mutex_; - std::shared_ptr current_stream_; + std::shared_ptr current_stream_; porting::optional error_; bool closed_; }; diff --git a/olp-cpp-sdk-dataservice-read/src/repositories/PartitionsRepository.cpp b/olp-cpp-sdk-dataservice-read/src/repositories/PartitionsRepository.cpp index 85e4549f3..cd03bd7fa 100644 --- a/olp-cpp-sdk-dataservice-read/src/repositories/PartitionsRepository.cpp +++ b/olp-cpp-sdk-dataservice-read/src/repositories/PartitionsRepository.cpp @@ -27,6 +27,7 @@ #include #include #include +#include #include "CatalogRepository.h" #include "generated/api/MetadataApi.h" #include "generated/api/QueryApi.h" @@ -709,28 +710,35 @@ client::ApiNoResponse PartitionsRepository::ParsePartitionsStream( const std::shared_ptr& async_stream, const PartitionsStreamCallback& partition_callback, client::CancellationContext context) { - rapidjson::ParseResult parse_result; + auto parse_result = + boost::json::make_error_code(boost::json::error::incomplete); // We must perform at least one attempt to parse. do { - rapidjson::Reader reader; - auto partitions_handler = - std::make_shared(partition_callback); - - auto reader_cancellation_token = client::CancellationToken([=]() { - partitions_handler->Abort(); - async_stream->CloseStream(client::ApiError::Cancelled()); - }); - - if (!context.ExecuteOrCancelled( - [=]() { return reader_cancellation_token; })) { + auto parser = + std::make_shared>( + boost::json::parse_options{}, partition_callback); + + auto reader_cancellation_token = + client::CancellationToken([parser, &async_stream]() { + parser->handler().Abort(); + async_stream->CloseStream(client::ApiError::Cancelled()); + }); + + if (!context.ExecuteOrCancelled([reader_cancellation_token]() { + return reader_cancellation_token; + })) { return client::ApiError::Cancelled(); } auto json_stream = async_stream->GetCurrentStream(); - parse_result = reader.Parse( - *json_stream, *partitions_handler); + while (json_stream->Peek() != '\0') { + auto view = json_stream->ReadView(); + if (parser->write_some(true, view.data(), view.size(), parse_result)) { + parse_result = {}; + } + } // Retry to parse the stream until it's closed. } while (!async_stream->IsClosed()); @@ -738,8 +746,8 @@ client::ApiNoResponse PartitionsRepository::ParsePartitionsStream( if (error) { return {*error}; - } else if (!parse_result) { - return client::ApiError(parse_result.Code(), "Parsing error"); + } else if (parse_result.failed()) { + return client::ApiError(parse_result.value(), "Parsing error"); } else { return client::ApiNoResult{}; } diff --git a/olp-cpp-sdk-dataservice-read/src/repositories/PartitionsSaxHandler.cpp b/olp-cpp-sdk-dataservice-read/src/repositories/PartitionsSaxHandler.cpp index 146c34e6c..bc67df12c 100644 --- a/olp-cpp-sdk-dataservice-read/src/repositories/PartitionsSaxHandler.cpp +++ b/olp-cpp-sdk-dataservice-read/src/repositories/PartitionsSaxHandler.cpp @@ -1,5 +1,5 @@ /* - * Copyright (C) 2023-2025 HERE Europe B.V. + * Copyright (C) 2023-2026 HERE Europe B.V. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -35,46 +35,45 @@ constexpr unsigned long long int HashStringToInt( PartitionsSaxHandler::PartitionsSaxHandler(PartitionCallback partition_callback) : partition_callback_(std::move(partition_callback)) {} -bool PartitionsSaxHandler::StartObject() { +bool PartitionsSaxHandler::on_object_begin(boost::json::error_code& ec) { if (state_ == State::kWaitForRootObject) { state_ = State::kWaitForRootPartitions; - return continue_parsing_; + return CanContinue(ec); } if (state_ != State::kWaitForNextPartition) { - return false; + return NotSupported(ec); } state_ = State::kProcessingAttribute; - return continue_parsing_; + return CanContinue(ec); } - -bool PartitionsSaxHandler::String(const char* str, unsigned int length, bool) { +bool PartitionsSaxHandler::String(const std::string& str, error_code& ec) { switch (state_) { case State::kProcessingAttribute: - state_ = ProcessNextAttribute(str, length); - return continue_parsing_; + state_ = ProcessNextAttribute(str); + return CanContinue(ec); - case State::kWaitForRootPartitions: - if (HashStringToInt("partitions") == HashStringToInt(str)) { + case State::kWaitForRootPartitions: { + if (HashStringToInt("partitions") == HashStringToInt(str.c_str())) { state_ = State::kWaitPartitionsArray; - return continue_parsing_; - } else { - return false; + return CanContinue(ec); } + return NotSupported(ec); + } case State::kParsingPartitionName: - partition_.SetPartition(std::string(str, length)); + partition_.SetPartition(str); break; case State::kParsingDataHandle: - partition_.SetDataHandle(std::string(str, length)); + partition_.SetDataHandle(str); break; case State::kParsingChecksum: - partition_.SetChecksum(std::string(str, length)); + partition_.SetChecksum(str); break; case State::kParsingCrc: - partition_.SetCrc(std::string(str, length)); + partition_.SetCrc(str); break; case State::kParsingIgnoreAttribute: break; @@ -92,10 +91,11 @@ bool PartitionsSaxHandler::String(const char* str, unsigned int length, bool) { state_ = State::kProcessingAttribute; - return continue_parsing_; + return CanContinue(ec); } -bool PartitionsSaxHandler::Uint(unsigned int value) { +bool PartitionsSaxHandler::on_int64(const int64_t value, string_view, + error_code& ec) { if (state_ == State::kParsingVersion) { partition_.SetVersion(value); } else if (state_ == State::kParsingDataSize) { @@ -103,61 +103,60 @@ bool PartitionsSaxHandler::Uint(unsigned int value) { } else if (state_ == State::kParsingCompressedDataSize) { partition_.SetCompressedDataSize(value); } else { - return false; + return NotSupported(ec); } state_ = State::kProcessingAttribute; - return continue_parsing_; + return CanContinue(ec); } -bool PartitionsSaxHandler::EndObject(unsigned int) { +bool PartitionsSaxHandler::on_object_end(std::size_t, error_code& ec) { if (state_ == State::kWaitForRootObjectEnd) { state_ = State::kParsingComplete; - return true; // complete + return CanContinue(ec); // complete } if (state_ != State::kProcessingAttribute) { - return false; + return NotSupported(ec); } if (partition_.GetDataHandle().empty() || partition_.GetPartition().empty()) { - return false; // partition is not valid + return NotSupported(ec); // partition is not valid } partition_callback_(std::move(partition_)); state_ = State::kWaitForNextPartition; - return continue_parsing_; + return CanContinue(ec); } -bool PartitionsSaxHandler::StartArray() { +bool PartitionsSaxHandler::on_array_begin(boost::json::error_code& ec) { // We expect only a single array in whol response if (state_ != State::kWaitPartitionsArray) { - return false; + return NotSupported(ec); } state_ = State::kWaitForNextPartition; - return continue_parsing_; + return CanContinue(ec); } -bool PartitionsSaxHandler::EndArray(unsigned int) { +bool PartitionsSaxHandler::on_array_end(std::size_t, + boost::json::error_code& ec) { if (state_ != State::kWaitForNextPartition) { - return false; + return NotSupported(ec); } state_ = State::kWaitForRootObjectEnd; - return continue_parsing_; + return CanContinue(ec); } -bool PartitionsSaxHandler::Default() { return false; } - void PartitionsSaxHandler::Abort() { continue_parsing_.store(false); } PartitionsSaxHandler::State PartitionsSaxHandler::ProcessNextAttribute( - const char* name, unsigned int /*length*/) { - switch (HashStringToInt(name)) { + const std::string& name) { + switch (HashStringToInt(name.c_str())) { case HashStringToInt("dataHandle"): return State::kParsingDataHandle; case HashStringToInt("partition"): diff --git a/olp-cpp-sdk-dataservice-read/src/repositories/PartitionsSaxHandler.h b/olp-cpp-sdk-dataservice-read/src/repositories/PartitionsSaxHandler.h index 1e5f1f905..f638eb631 100644 --- a/olp-cpp-sdk-dataservice-read/src/repositories/PartitionsSaxHandler.h +++ b/olp-cpp-sdk-dataservice-read/src/repositories/PartitionsSaxHandler.h @@ -1,5 +1,5 @@ /* - * Copyright (C) 2023-2025 HERE Europe B.V. + * Copyright (C) 2023-2026 HERE Europe B.V. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -22,7 +22,9 @@ #include #include -#include "rapidjson/reader.h" +#include +#include +#include #include @@ -31,31 +33,86 @@ namespace dataservice { namespace read { namespace repository { -class PartitionsSaxHandler - : public rapidjson::BaseReaderHandler, - PartitionsSaxHandler> { +class PartitionsSaxHandler { public: using PartitionCallback = std::function; + using string_view = boost::json::string_view; + using error_code = boost::json::error_code; explicit PartitionsSaxHandler(PartitionCallback partition_callback); - /// Json object events - bool StartObject(); - bool EndObject(unsigned int); + /// Abort parsing + void Abort(); - /// Json array events - bool StartArray(); - bool EndArray(unsigned int); + // boost::json::basic_parser handler object methods + static constexpr std::size_t max_array_size = -1; + static constexpr std::size_t max_object_size = -1; + static constexpr std::size_t max_string_size = -1; + static constexpr std::size_t max_key_size = -1; - /// Json attributes events - bool String(const char* str, unsigned int length, bool); - bool Uint(unsigned int value); - bool Default(); + bool on_document_begin(error_code&) { return continue_parsing_; } + bool on_document_end(error_code&) { return continue_parsing_; } - /// Abort parsing - void Abort(); + bool on_array_begin(error_code& ec); + bool on_array_end(std::size_t size, error_code& ec); + + bool on_object_begin(error_code& ec); + bool on_object_end(std::size_t size, error_code& ec); + + bool on_string_part(string_view str, std::size_t size, error_code& ec) { + str.length() == size ? value_ = str : value_ += str; + return CanContinue(ec); + } + + bool on_string(string_view str, std::size_t size, error_code& ec) { + str.length() == size ? value_ = str : value_ += str; + return String(value_, ec); + } + + bool on_key_part(string_view str, std::size_t size, error_code& ec) { + str.length() == size ? key_ = str : key_ += str; + return CanContinue(ec); + } + + bool on_key(string_view str, std::size_t size, error_code& ec) { + str.length() == size ? key_ = str : key_ += str; + return String(key_, ec); + } + + bool on_number_part(string_view, error_code& ec) const { + return CanContinue(ec); + } + + bool on_uint64(uint64_t value, string_view string, error_code& ec) { + return on_int64(static_cast(value), string, ec); + } + + bool on_int64(int64_t value, string_view, error_code& ec); + + static bool on_double(double, string_view, error_code& ec) { + return NotSupported(ec); + } + + static bool on_bool(bool, error_code& ec) { return NotSupported(ec); } + static bool on_null(error_code& ec) { return NotSupported(ec); } + + bool on_comment_part(string_view, error_code& ec) const { + return CanContinue(ec); + } + + bool on_comment(string_view, error_code& ec) const { return CanContinue(ec); } private: + bool String(const std::string& str, error_code& ec); + + bool CanContinue(error_code& ec) const { + return continue_parsing_ || NotSupported(ec); + } + + static bool NotSupported(error_code& ec) { + ec = boost::json::error::extra_data; + return false; + } enum class State { kWaitForRootObject, kWaitForRootPartitions, @@ -77,11 +134,13 @@ class PartitionsSaxHandler kParsingComplete, }; - State ProcessNextAttribute(const char* name, unsigned int length); + static State ProcessNextAttribute(const std::string& name); State state_{State::kWaitForRootObject}; model::Partition partition_; PartitionCallback partition_callback_; + std::string key_; + std::string value_; std::atomic_bool continue_parsing_{true}; }; diff --git a/olp-cpp-sdk-dataservice-read/tests/AsyncJsonStreamTest.cpp b/olp-cpp-sdk-dataservice-read/tests/AsyncJsonStreamTest.cpp index 45ad09db0..238444400 100644 --- a/olp-cpp-sdk-dataservice-read/tests/AsyncJsonStreamTest.cpp +++ b/olp-cpp-sdk-dataservice-read/tests/AsyncJsonStreamTest.cpp @@ -1,5 +1,5 @@ /* - * Copyright (C) 2023-2025 HERE Europe B.V. + * Copyright (C) 2023-2026 HERE Europe B.V. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -40,6 +40,15 @@ TEST(AsyncJsonStreamTest, NormalFlow) { EXPECT_EQ(current_stream->Tell(), 2u); EXPECT_EQ(current_stream->Take(), '3'); + stream.ResetStream("123", 4); + current_stream = stream.GetCurrentStream(); + auto view = current_stream->ReadView(); + EXPECT_EQ(view.size(), 3); + EXPECT_FALSE(current_stream->ReadEmpty()); + EXPECT_EQ(current_stream->Peek(), '\0'); + EXPECT_EQ(current_stream->Take(), '\0'); + EXPECT_TRUE(current_stream->ReadEmpty()); + stream.ResetStream("234", 3); auto new_current_stream = stream.GetCurrentStream(); diff --git a/olp-cpp-sdk-dataservice-read/tests/PartitionsSaxHandlerTest.cpp b/olp-cpp-sdk-dataservice-read/tests/PartitionsSaxHandlerTest.cpp index 94c340392..cb995dcfb 100644 --- a/olp-cpp-sdk-dataservice-read/tests/PartitionsSaxHandlerTest.cpp +++ b/olp-cpp-sdk-dataservice-read/tests/PartitionsSaxHandlerTest.cpp @@ -1,5 +1,5 @@ /* - * Copyright (C) 2023-2025 HERE Europe B.V. + * Copyright (C) 2023-2026 HERE Europe B.V. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -47,36 +47,60 @@ unsigned int len(const char* str) { TEST(PartitionsSaxHandlerTest, NormalFlow) { model::Partition parsed_partition; - auto callback = [&](model::Partition partition) { + auto callback = [&](const model::Partition& partition) { parsed_partition = partition; }; repository::PartitionsSaxHandler handler(callback); - ASSERT_TRUE(handler.StartObject()); - ASSERT_TRUE(handler.String(kPartitions, len(kPartitions), true)); - ASSERT_TRUE(handler.StartArray()); - - ASSERT_TRUE(handler.StartObject()); - ASSERT_TRUE(handler.String(kDataHandle, len(kDataHandle), true)); - ASSERT_TRUE(handler.String(kDataHandleValue, len(kDataHandleValue), true)); - ASSERT_TRUE(handler.String(kPartition, len(kPartition), true)); - ASSERT_TRUE(handler.String(kPartitionValue, len(kPartitionValue), true)); - ASSERT_TRUE(handler.String(kChecksum, len(kChecksum), true)); - ASSERT_TRUE(handler.String(kChecksumValue, len(kChecksumValue), true)); - ASSERT_TRUE(handler.String(kDataSize, len(kDataSize), true)); - ASSERT_TRUE(handler.Uint(150)); + boost::json::error_code error_code; + ASSERT_TRUE(handler.on_object_begin(error_code)); + ASSERT_TRUE(handler.on_key(kPartitions, len(kPartitions), error_code)); + ASSERT_TRUE(handler.on_array_begin(error_code)); + ASSERT_TRUE(handler.on_object_begin(error_code)); + + boost::json::string_view key_part_1{kDataHandle, 2}; + boost::json::string_view key_part_2{kDataHandle + key_part_1.size(), 3}; + boost::json::string_view key_part_last{ + kDataHandle + key_part_1.size() + key_part_2.size(), + len(kDataHandle) - key_part_1.size() - key_part_2.size()}; + ASSERT_TRUE(handler.on_key_part(key_part_1, key_part_1.size(), error_code)); + ASSERT_TRUE(handler.on_key_part( + key_part_2, key_part_1.size() + key_part_2.size(), error_code)); + ASSERT_TRUE(handler.on_key(key_part_last, len(kDataHandle), error_code)); + + boost::json::string_view value_part_1{kDataHandleValue, 2}; + boost::json::string_view value_part_2{kDataHandleValue + value_part_1.size(), + 3}; + boost::json::string_view value_part_last{ + kDataHandleValue + value_part_1.size() + value_part_2.size(), + len(kDataHandleValue) - value_part_1.size() - value_part_2.size()}; ASSERT_TRUE( - handler.String(kCompressedDataSize, len(kCompressedDataSize), true)); - ASSERT_TRUE(handler.Uint(100)); - ASSERT_TRUE(handler.String(kVersion, len(kVersion), true)); - ASSERT_TRUE(handler.Uint(6)); - ASSERT_TRUE(handler.String(kCrc, len(kCrc), true)); - ASSERT_TRUE(handler.String(kCrcValue, len(kCrcValue), true)); - ASSERT_TRUE(handler.EndObject(0)); + handler.on_string_part(value_part_1, value_part_1.size(), error_code)); + ASSERT_TRUE(handler.on_string_part( + value_part_2, value_part_1.size() + value_part_2.size(), error_code)); + ASSERT_TRUE( + handler.on_string(value_part_last, len(kDataHandleValue), error_code)); - ASSERT_TRUE(handler.EndArray(0)); - ASSERT_TRUE(handler.EndObject(0)); + ASSERT_TRUE(handler.on_key(kPartition, len(kPartition), error_code)); + ASSERT_TRUE( + handler.on_string(kPartitionValue, len(kPartitionValue), error_code)); + ASSERT_TRUE(handler.on_key(kChecksum, len(kChecksum), error_code)); + ASSERT_TRUE( + handler.on_string(kChecksumValue, len(kChecksumValue), error_code)); + ASSERT_TRUE(handler.on_key(kDataSize, len(kDataSize), error_code)); + ASSERT_TRUE(handler.on_uint64(150, "150", error_code)); + ASSERT_TRUE(handler.on_key(kCompressedDataSize, len(kCompressedDataSize), + error_code)); + ASSERT_TRUE(handler.on_uint64(100, "100", error_code)); + ASSERT_TRUE(handler.on_key(kVersion, len(kVersion), error_code)); + ASSERT_TRUE(handler.on_uint64(6, "6", error_code)); + ASSERT_TRUE(handler.on_key(kCrc, len(kCrc), error_code)); + ASSERT_TRUE(handler.on_string(kCrcValue, len(kCrcValue), error_code)); + ASSERT_TRUE(handler.on_object_end(0, error_code)); + + ASSERT_TRUE(handler.on_array_end(0, error_code)); + ASSERT_TRUE(handler.on_object_end(0, error_code)); EXPECT_EQ(parsed_partition.GetDataHandle(), std::string(kDataHandleValue)); EXPECT_EQ(parsed_partition.GetPartition(), std::string(kPartitionValue)); @@ -94,92 +118,95 @@ TEST(PartitionsSaxHandlerTest, WrongJSONStructure) { auto callback = [&](model::Partition) {}; repository::PartitionsSaxHandler handler(callback); + boost::json::error_code error_code; // Initial state expects an object - ASSERT_FALSE(handler.String(kPartitions, len(kPartitions), true)); - ASSERT_FALSE(handler.Uint(6)); - ASSERT_FALSE(handler.StartArray()); - ASSERT_FALSE(handler.EndArray(0)); - ASSERT_FALSE(handler.EndObject(0)); + ASSERT_FALSE(handler.on_key(kPartitions, len(kPartitions), error_code)); + ASSERT_FALSE(handler.on_uint64(6, "6", error_code)); + ASSERT_FALSE(handler.on_array_begin(error_code)); + ASSERT_FALSE(handler.on_array_end(0, error_code)); + ASSERT_FALSE(handler.on_object_end(0, error_code)); - ASSERT_TRUE(handler.StartObject()); + ASSERT_TRUE(handler.on_object_begin(error_code)); // next state expects a partitions string - ASSERT_FALSE(handler.String(kDataHandle, len(kDataHandle), true)); - ASSERT_FALSE(handler.Uint(6)); - ASSERT_FALSE(handler.StartArray()); - ASSERT_FALSE(handler.StartObject()); - ASSERT_FALSE(handler.EndObject(0)); - ASSERT_FALSE(handler.EndArray(0)); + ASSERT_FALSE(handler.on_key(kDataHandle, len(kDataHandle), error_code)); + ASSERT_FALSE(handler.on_uint64(6, "6", error_code)); + ASSERT_FALSE(handler.on_array_begin(error_code)); + ASSERT_FALSE(handler.on_object_begin(error_code)); + ASSERT_FALSE(handler.on_object_end(0, error_code)); + ASSERT_FALSE(handler.on_array_end(0, error_code)); - ASSERT_TRUE(handler.String(kPartitions, len(kPartitions), true)); + ASSERT_TRUE(handler.on_key(kPartitions, len(kPartitions), error_code)); // expect partitions array - ASSERT_FALSE(handler.String(kDataHandle, len(kDataHandle), true)); - ASSERT_FALSE(handler.Uint(6)); - ASSERT_FALSE(handler.StartObject()); - ASSERT_FALSE(handler.EndObject(0)); - ASSERT_FALSE(handler.EndArray(0)); + ASSERT_FALSE(handler.on_key(kDataHandle, len(kDataHandle), error_code)); + ASSERT_FALSE(handler.on_uint64(6, "6", error_code)); + ASSERT_FALSE(handler.on_object_begin(error_code)); + ASSERT_FALSE(handler.on_object_end(0, error_code)); + ASSERT_FALSE(handler.on_array_end(0, error_code)); - ASSERT_TRUE(handler.StartArray()); + ASSERT_TRUE(handler.on_array_begin(error_code)); // expect partition object - ASSERT_FALSE(handler.String(kDataHandle, len(kDataHandle), true)); - ASSERT_FALSE(handler.Uint(6)); - ASSERT_FALSE(handler.StartArray()); - ASSERT_FALSE(handler.EndObject(0)); + ASSERT_FALSE(handler.on_key(kDataHandle, len(kDataHandle), error_code)); + ASSERT_FALSE(handler.on_uint64(6, "6", error_code)); + ASSERT_FALSE(handler.on_array_begin(error_code)); + ASSERT_FALSE(handler.on_object_end(0, error_code)); - ASSERT_TRUE(handler.StartObject()); + ASSERT_TRUE(handler.on_object_begin(error_code)); // object is not valid - ASSERT_FALSE(handler.EndObject(0)); + ASSERT_FALSE(handler.on_object_end(0, error_code)); // expect partition attribute - ASSERT_FALSE(handler.Uint(6)); - ASSERT_FALSE(handler.StartArray()); + ASSERT_FALSE(handler.on_uint64(6, "6", error_code)); + ASSERT_FALSE(handler.on_array_begin(error_code)); - ASSERT_TRUE(handler.String(kDataHandle, len(kDataHandle), true)); + ASSERT_TRUE(handler.on_key(kDataHandle, len(kDataHandle), error_code)); // expect string attribute value - ASSERT_FALSE(handler.Uint(6)); - ASSERT_FALSE(handler.StartArray()); - ASSERT_FALSE(handler.EndObject(0)); + ASSERT_FALSE(handler.on_uint64(6, "6", error_code)); + ASSERT_FALSE(handler.on_array_begin(error_code)); + ASSERT_FALSE(handler.on_object_end(0, error_code)); - ASSERT_TRUE(handler.String(kDataHandleValue, len(kDataHandleValue), true)); + ASSERT_TRUE( + handler.on_string(kDataHandleValue, len(kDataHandleValue), error_code)); // object is not valid - ASSERT_FALSE(handler.EndObject(0)); + ASSERT_FALSE(handler.on_object_end(0, error_code)); // integer properties - ASSERT_TRUE(handler.String(kDataSize, len(kDataSize), true)); + ASSERT_TRUE(handler.on_key(kDataSize, len(kDataSize), error_code)); - ASSERT_FALSE(handler.String(kDataHandle, len(kDataHandle), true)); - ASSERT_FALSE(handler.StartArray()); - ASSERT_FALSE(handler.EndArray(0)); - ASSERT_FALSE(handler.StartObject()); - ASSERT_FALSE(handler.EndObject(0)); + ASSERT_FALSE(handler.on_string(kDataHandle, len(kDataHandle), error_code)); + ASSERT_FALSE(handler.on_array_begin(error_code)); + ASSERT_FALSE(handler.on_array_end(0, error_code)); + ASSERT_FALSE(handler.on_object_begin(error_code)); + ASSERT_FALSE(handler.on_object_end(0, error_code)); - ASSERT_TRUE(handler.Uint(6)); + ASSERT_TRUE(handler.on_uint64(6, "6", error_code)); - ASSERT_TRUE(handler.String(kPartition, len(kPartition), true)); - ASSERT_TRUE(handler.String(kPartitionValue, len(kPartitionValue), true)); + ASSERT_TRUE(handler.on_key(kPartition, len(kPartition), error_code)); + ASSERT_TRUE( + handler.on_string(kPartitionValue, len(kPartitionValue), error_code)); // complete partition - ASSERT_TRUE(handler.EndObject(0)); + ASSERT_TRUE(handler.on_object_end(0, error_code)); // complete partitions array - ASSERT_TRUE(handler.EndArray(0)); + ASSERT_TRUE(handler.on_array_end(0, error_code)); // complete the json - ASSERT_TRUE(handler.EndObject(0)); + ASSERT_TRUE(handler.on_object_end(0, error_code)); // nothing works anymore - ASSERT_FALSE(handler.String(kDataHandle, len(kDataHandle), true)); - ASSERT_FALSE(handler.Uint(6)); - ASSERT_FALSE(handler.StartArray()); - ASSERT_FALSE(handler.EndArray(0)); - ASSERT_FALSE(handler.StartObject()); - ASSERT_FALSE(handler.EndObject(0)); + ASSERT_FALSE(handler.on_key(kDataHandle, len(kDataHandle), error_code)); + ASSERT_FALSE(handler.on_uint64(6, "6", error_code)); + ASSERT_FALSE(handler.on_array_begin(error_code)); + ASSERT_FALSE(handler.on_array_end(0, error_code)); + ASSERT_FALSE(handler.on_object_begin(error_code)); + ASSERT_FALSE(handler.on_object_end(0, error_code)); } } // namespace From 7aad054b62963b4866bda2ee47a4c47e333053a9 Mon Sep 17 00:00:00 2001 From: Rustam Gamidov <108531570+rustam-gamidov-here@users.noreply.github.com> Date: Tue, 3 Mar 2026 14:12:33 +0200 Subject: [PATCH 04/12] CI: build with hidden symbols using Clang (#1675) Good to be able to do this. No tests as not exposed classes are accessed in tests. Examples: export functions from libs to utilize in the common binary Make boost::json header only in the read lib Otherwise there are unresolved external symbols when built with visibility=hidden Relates-To: MINOR Signed-off-by: Rustam Gamidov --- .github/workflows/psv_pipelines.yml | 19 +++++++++++++++++ examples/CMakeLists.txt | 21 ++++++++++++++++++- examples/Examples.h | 17 ++++++++++++--- examples/ProtectedCacheExample.h | 19 ++++++++++------- examples/ReadExample.h | 4 +++- examples/StreamLayerReadExample.h | 4 +++- examples/WriteExample.h | 11 +++++++--- .../src/utils/BoostJsonSrc.cpp | 20 ++++++++++++++++++ scripts/linux/psv/build_psv.sh | 3 ++- 9 files changed, 101 insertions(+), 17 deletions(-) create mode 100644 olp-cpp-sdk-dataservice-read/src/utils/BoostJsonSrc.cpp diff --git a/.github/workflows/psv_pipelines.yml b/.github/workflows/psv_pipelines.yml index 6950e6f77..be86659d2 100644 --- a/.github/workflows/psv_pipelines.yml +++ b/.github/workflows/psv_pipelines.yml @@ -196,6 +196,25 @@ jobs: run: scripts/linux/psv/test_psv.sh shell: bash + psv-linux-22-04-clang-hidden-build: + name: PSV.Linux.22.04.clang.hidden + runs-on: ubuntu-22.04 + env: + BUILD_TYPE: RelWithDebInfo + CC: clang-11 + CXX: clang++-11 + CXXFLAGS: -Wno-deprecated-copy + EXTRA_CMAKE_OPTIONS: -DCMAKE_CXX_VISIBILITY_PRESET=hidden -DOLP_SDK_ENABLE_TESTING=OFF + steps: + - name: Check out repository + uses: actions/checkout@v4 + - name: Install Ubuntu dependencies + run: sudo apt-get update -y && sudo apt-get install clang-11 ccache libcurl4-openssl-dev -y --no-install-recommends --fix-missing + shell: bash + - name: Compile project on Clang + run: scripts/linux/psv/build_psv.sh + shell: bash + psv-android-22-04-build: name: PSV.Linux.Android.22.04 runs-on: ubuntu-22.04 diff --git a/examples/CMakeLists.txt b/examples/CMakeLists.txt index dbac398a4..2a0684c91 100644 --- a/examples/CMakeLists.txt +++ b/examples/CMakeLists.txt @@ -1,4 +1,4 @@ -# Copyright (C) 2019-2020 HERE Europe B.V. +# Copyright (C) 2019-2026 HERE Europe B.V. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -81,6 +81,25 @@ else() olp-cpp-sdk-authentication olp-cpp-sdk-dataservice-read) + target_compile_definitions(${OLP_SDK_DATASERVICE_READ_EXAMPLE_TARGET} + PRIVATE EXAMPLES_LIBRARY) + target_compile_definitions(${OLP_SDK_DATASERVICE_WRITE_EXAMPLE_TARGET} + PRIVATE EXAMPLES_LIBRARY) + target_compile_definitions(${OLP_SDK_DATASERVICE_CACHE_EXAMPLE_TARGET} + PRIVATE EXAMPLES_LIBRARY) + target_compile_definitions(${OLP_SDK_DATASERVICE_READ_STREAM_LAYER_EXAMPLE_TARGET} + PRIVATE EXAMPLES_LIBRARY) + if(BUILD_SHARED_LIBS) + target_compile_definitions(${OLP_SDK_DATASERVICE_READ_EXAMPLE_TARGET} + PUBLIC EXAMPLES_SHARED_LIBRARY) + target_compile_definitions(${OLP_SDK_DATASERVICE_WRITE_EXAMPLE_TARGET} + PUBLIC EXAMPLES_SHARED_LIBRARY) + target_compile_definitions(${OLP_SDK_DATASERVICE_CACHE_EXAMPLE_TARGET} + PUBLIC EXAMPLES_SHARED_LIBRARY) + target_compile_definitions(${OLP_SDK_DATASERVICE_READ_STREAM_LAYER_EXAMPLE_TARGET} + PUBLIC EXAMPLES_SHARED_LIBRARY) + endif() + add_executable(${OLP_SDK_DATASERVICE_EXAMPLE_TARGET} ./main.cpp ./Examples.h diff --git a/examples/Examples.h b/examples/Examples.h index b0492468f..dd16f0acd 100644 --- a/examples/Examples.h +++ b/examples/Examples.h @@ -1,5 +1,5 @@ /* - * Copyright (C) 2019-2020 HERE Europe B.V. + * Copyright (C) 2019-2026 HERE Europe B.V. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -19,10 +19,21 @@ #pragma once +#include + +#ifdef EXAMPLES_SHARED_LIBRARY +#ifdef EXAMPLES_LIBRARY +#define EXAMPLES_API OLP_CPP_SDK_DECL_EXPORT +#else +#define EXAMPLES_API OLP_CPP_SDK_DECL_IMPORT +#endif // EXAMPLES_LIBRARY +#else +#define EXAMPLES_API +#endif // EXAMPLES_SHARED_LIBRARY + #include -struct AccessKey -{ +struct AccessKey { std::string id; // Your here.access.key.id std::string secret; // Your here.access.key.secret }; diff --git a/examples/ProtectedCacheExample.h b/examples/ProtectedCacheExample.h index 7656fe724..961798f42 100644 --- a/examples/ProtectedCacheExample.h +++ b/examples/ProtectedCacheExample.h @@ -1,5 +1,5 @@ /* - * Copyright (C) 2020 HERE Europe B.V. + * Copyright (C) 2020-2026 HERE Europe B.V. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -21,14 +21,19 @@ #include "Examples.h" +#include + /** - * @brief Dataservice cache example. + * @brief Dataservice cache example. * - * Gets the partition data using the HERE Open Location Platform with mutable cache. - * Makes the mutable cache path - * protected. Reads the same data from the protected cache. + * Gets the partition data using the HERE Open Location Platform with mutable + * cache. Makes the mutable cache path protected. Reads the same data from the + * protected cache. * @param access_key Your access key ID and access key secret. - * @param The HERE Resource Name (HRN) of the catalog from which you want to read data. + * @param The HERE Resource Name (HRN) of the catalog from which you want to + * read data. * @return 0 if data was published successfully. */ -int RunExampleProtectedCache(const AccessKey& access_key, const std::string& catalog); +EXAMPLES_API +int RunExampleProtectedCache(const AccessKey& access_key, + const std::string& catalog); diff --git a/examples/ReadExample.h b/examples/ReadExample.h index c4eb8c565..008de9f3e 100644 --- a/examples/ReadExample.h +++ b/examples/ReadExample.h @@ -1,5 +1,5 @@ /* - * Copyright (C) 2019-2020 HERE Europe B.V. + * Copyright (C) 2019-2026 HERE Europe B.V. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -22,6 +22,7 @@ #include "Examples.h" #include +#include /** * @brief Dataservice read example. Authenticate client using access key id and @@ -33,6 +34,7 @@ * @param catalog_version The desired version of the catalog. * @return result of publish data(0 - if succeed) */ +EXAMPLES_API int RunExampleRead(const AccessKey& access_key, const std::string& catalog, const olp::porting::optional& catalog_version = olp::porting::none); diff --git a/examples/StreamLayerReadExample.h b/examples/StreamLayerReadExample.h index 06519bb5a..1fb8f7274 100644 --- a/examples/StreamLayerReadExample.h +++ b/examples/StreamLayerReadExample.h @@ -1,5 +1,5 @@ /* - * Copyright (C) 2019-2020 HERE Europe B.V. + * Copyright (C) 2019-2026 HERE Europe B.V. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -22,6 +22,7 @@ #include "Examples.h" #include +#include /** * @brief Dataservice read from stream layer example. Authenticate client using @@ -34,6 +35,7 @@ * @param subscription_mode The type of client subscription. * @return 0 on success, -1 otherwise. */ +EXAMPLES_API int RunStreamLayerExampleRead( const AccessKey& access_key, const std::string& catalog, const std::string& layer_id, diff --git a/examples/WriteExample.h b/examples/WriteExample.h index 2dbfd1c1a..15546fa26 100644 --- a/examples/WriteExample.h +++ b/examples/WriteExample.h @@ -1,5 +1,5 @@ /* - * Copyright (C) 2019-2020 HERE Europe B.V. + * Copyright (C) 2019-2026 HERE Europe B.V. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -21,13 +21,18 @@ #include "Examples.h" +#include + /** * @brief Dataservice write example. Authenticate client using access key id and * secret. Publish data to some layer in HRN catalog. * @param access_key Your access key ID and access key secret. - * @param The HERE Resource Name (HRN) of the catalog to which you want to publish data. - * @param layer_id The layer ID of the catalog to which you want to publish data. + * @param The HERE Resource Name (HRN) of the catalog to which you want to + * publish data. + * @param layer_id The layer ID of the catalog to which you want to publish + * data. * @return result of publish data(0 - if succeed) */ +EXAMPLES_API int RunExampleWrite(const AccessKey& access_key, const std::string& catalog, const std::string& layer_id); diff --git a/olp-cpp-sdk-dataservice-read/src/utils/BoostJsonSrc.cpp b/olp-cpp-sdk-dataservice-read/src/utils/BoostJsonSrc.cpp new file mode 100644 index 000000000..017758210 --- /dev/null +++ b/olp-cpp-sdk-dataservice-read/src/utils/BoostJsonSrc.cpp @@ -0,0 +1,20 @@ +/* + * Copyright (C) 2026 HERE Europe B.V. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * SPDX-License-Identifier: Apache-2.0 + * License-Filename: LICENSE + */ + +#include diff --git a/scripts/linux/psv/build_psv.sh b/scripts/linux/psv/build_psv.sh index 7373352b2..0104f4f3d 100755 --- a/scripts/linux/psv/build_psv.sh +++ b/scripts/linux/psv/build_psv.sh @@ -1,6 +1,6 @@ #!/bin/bash -ex # -# Copyright (C) 2019-2020 HERE Europe B.V. +# Copyright (C) 2019-2026 HERE Europe B.V. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -30,6 +30,7 @@ cmake -DCMAKE_BUILD_TYPE=$BUILD_TYPE \ -DCMAKE_CXX_COMPILER_LAUNCHER=ccache \ -DOLP_SDK_BUILD_EXAMPLES=ON \ -DBUILD_SHARED_LIBS=ON \ + $EXTRA_CMAKE_OPTIONS \ .. make -j$(nproc) From 59770674391c1cbb87fc925005cbf759a5d682cc Mon Sep 17 00:00:00 2001 From: Rustam Gamidov <108531570+rustam-gamidov-here@users.noreply.github.com> Date: Tue, 3 Mar 2026 14:29:46 +0200 Subject: [PATCH 05/12] Use Boost::json in olp-cpp-sdk-authentication (#1674) Migrating from RapidJSON Relates-To: OCMAM-443 Signed-off-by: Rustam Gamidov --- olp-cpp-sdk-authentication/CMakeLists.txt | 13 +- .../src/AuthenticationClientImpl.cpp | 314 ++++++++---------- .../src/AuthenticationClientUtils.cpp | 69 ++-- .../src/AuthenticationClientUtils.h | 11 +- olp-cpp-sdk-authentication/src/BaseResult.cpp | 47 ++- olp-cpp-sdk-authentication/src/BaseResult.h | 6 +- .../src/ResponseFromJsonBuilder.h | 67 +++- .../src/SignInResultImpl.cpp | 65 ++-- .../src/SignInResultImpl.h | 8 +- .../src/SignInUserResultImpl.cpp | 33 +- .../src/SignInUserResultImpl.h | 5 +- .../src/SignOutResultImpl.cpp | 6 +- .../src/SignOutResultImpl.h | 4 +- .../src/SignUpResultImpl.cpp | 10 +- .../src/SignUpResultImpl.h | 6 +- .../src/TokenEndpointImpl.cpp | 51 ++- .../src/utils/BoostJsonSrc.cpp | 20 ++ .../tests/SignInResultImplTest.cpp | 27 +- .../AuthenticationTestUtils.cpp | 111 ++++--- .../FederatedAuthenticationTest.cpp | 33 +- 20 files changed, 472 insertions(+), 434 deletions(-) create mode 100644 olp-cpp-sdk-authentication/src/utils/BoostJsonSrc.cpp diff --git a/olp-cpp-sdk-authentication/CMakeLists.txt b/olp-cpp-sdk-authentication/CMakeLists.txt index b8d9cc787..64908df2e 100644 --- a/olp-cpp-sdk-authentication/CMakeLists.txt +++ b/olp-cpp-sdk-authentication/CMakeLists.txt @@ -18,6 +18,8 @@ project(olp-cpp-sdk-authentication VERSION 1.24.0) set(DESCRIPTION "C++ API library for accessing HERE Account authentication service") +find_package(Boost REQUIRED) + file(GLOB_RECURSE AUTHENTICATION_INC "include/*.h*") file(GLOB_RECURSE AUTHENTICATION_SRC "src/*.*") @@ -27,6 +29,7 @@ add_library(${PROJECT_NAME} target_include_directories(${PROJECT_NAME} PUBLIC $ + $ $) # Used also in the package config file @@ -37,8 +40,9 @@ target_link_libraries(${PROJECT_NAME} ${PROJECT_LIBS} ) -# On MINGW boost uses bcrypt library -if (MINGW) +# On MINGW and MSVC boost uses bcrypt library +# https://github.com/boostorg/uuid/issues/122 +if (MINGW OR MSVC) target_link_libraries(${PROJECT_NAME} PRIVATE bcrypt ) endif() @@ -49,6 +53,11 @@ if(BUILD_SHARED_LIBS) PUBLIC AUTHENTICATION_SHARED_LIBRARY) endif() +target_compile_definitions(${PROJECT_NAME} + PRIVATE + BOOST_ALL_NO_LIB + BOOST_JSON_NO_LIB) + # install component install (FILES ${AUTHENTICATION_INC} DESTINATION ${INCLUDE_DIRECTORY}/olp/authentication) diff --git a/olp-cpp-sdk-authentication/src/AuthenticationClientImpl.cpp b/olp-cpp-sdk-authentication/src/AuthenticationClientImpl.cpp index 567c1cde8..de349240c 100644 --- a/olp-cpp-sdk-authentication/src/AuthenticationClientImpl.cpp +++ b/olp-cpp-sdk-authentication/src/AuthenticationClientImpl.cpp @@ -1,5 +1,5 @@ /* - * Copyright (C) 2020-2025 HERE Europe B.V. + * Copyright (C) 2020-2026 HERE Europe B.V. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -26,10 +26,9 @@ #include #include -#include -#include -#include -#include +#include +#include +#include #include #include #include @@ -116,17 +115,13 @@ void RetryDelay(const client::RetrySettings& retry_settings, size_t retry) { client::OlpClient::RequestBodyType GenerateAppleSignInBody( const AppleSignInProperties& sign_in_properties) { - rapidjson::StringBuffer data; - rapidjson::Writer writer(data); - writer.StartObject(); + boost::json::object json_object; - writer.Key(kGrantType); - writer.String(kAppleGrantType); + json_object[kGrantType] = kAppleGrantType; - auto write_field = [&writer](const char* key, const std::string& value) { + auto write_field = [&json_object](const char* key, const std::string& value) { if (!value.empty()) { - writer.Key(key); - writer.String(value.c_str()); + json_object[key] = value; } }; @@ -137,9 +132,8 @@ client::OlpClient::RequestBodyType GenerateAppleSignInBody( write_field(kCountryCode, sign_in_properties.GetCountryCode()); write_field(kLanguage, sign_in_properties.GetLanguage()); - writer.EndObject(); - auto content = data.GetString(); - return std::make_shared(content, content + data.GetSize()); + auto content = boost::json::serialize(json_object); + return std::make_shared(content.begin(), content.end()); } client::HttpResponse CallApi(const client::OlpClient& client, @@ -219,20 +213,26 @@ olp::client::HttpResponse AuthenticationClientImpl::CallAuth( SignInResult AuthenticationClientImpl::ParseAuthResponse( int status, std::stringstream& auth_response) { - auto document = std::make_shared(); - rapidjson::IStreamWrapper stream(auth_response); - document->ParseStream(stream); + boost::json::error_code ec; + auto document = boost::json::parse(auth_response, ec); return std::make_shared( - status, olp::http::HttpErrorToString(status), document); + status, olp::http::HttpErrorToString(status), + ec.failed() || !document.is_object() + ? nullptr + : std::make_shared( + std::move(document.as_object()))); } SignInUserResult AuthenticationClientImpl::ParseUserAuthResponse( int status, std::stringstream& auth_response) { - auto document = std::make_shared(); - rapidjson::IStreamWrapper stream(auth_response); - document->ParseStream(stream); + boost::json::error_code ec; + auto document = boost::json::parse(auth_response, ec); return std::make_shared( - status, olp::http::HttpErrorToString(status), document); + status, olp::http::HttpErrorToString(status), + ec.failed() || !document.is_object() + ? nullptr + : std::make_shared( + std::move(document.as_object()))); } template @@ -397,23 +397,24 @@ client::CancellationToken AuthenticationClientImpl::SignInClient( TimeResponse AuthenticationClientImpl::ParseTimeResponse( std::stringstream& payload) { - rapidjson::Document document; - rapidjson::IStreamWrapper stream(payload); - document.ParseStream(stream); + boost::json::error_code ec; + auto json_value = boost::json::parse(payload, ec); - if (!document.IsObject()) { + if (ec.failed() || !json_value.is_object()) { return client::ApiError(client::ErrorCode::InternalFailure, "JSON document root is not an Object type"); } - const auto timestamp_it = document.FindMember("timestamp"); - if (timestamp_it == document.MemberEnd() || !timestamp_it->value.IsUint()) { + auto& object = json_value.as_object(); + const auto timestamp_it = object.find("timestamp"); + if (timestamp_it == object.end() || (!timestamp_it->value().is_uint64() && + !timestamp_it->value().is_int64())) { return client::ApiError( client::ErrorCode::InternalFailure, "JSON document must contain timestamp integer field"); } - return timestamp_it->value.GetUint(); + return timestamp_it->value().to_number(); } TimeResponse AuthenticationClientImpl::GetTimeFromServer( @@ -622,10 +623,14 @@ client::CancellationToken AuthenticationClientImpl::SignUpHereUser( return client::ApiError(status, response_text); } - auto document = std::make_shared(); - document->Parse(response_text.c_str()); + boost::json::error_code ec; + auto document = boost::json::parse(response_text, ec); return {std::make_shared( - status, olp::http::HttpErrorToString(status), document)}; + status, olp::http::HttpErrorToString(status), + ec.failed() || !document.is_object() + ? nullptr + : std::make_shared( + std::move(document.as_object())))}; }; return AddTask(settings_.task_scheduler, pending_requests_, @@ -667,10 +672,14 @@ client::CancellationToken AuthenticationClientImpl::SignOut( return client::ApiError(status, response_text); } - auto document = std::make_shared(); - document->Parse(response_text.c_str()); + boost::json::error_code ec; + auto document = boost::json::parse(response_text, ec); return {std::make_shared( - status, olp::http::HttpErrorToString(status), document)}; + status, olp::http::HttpErrorToString(status), + ec.failed() || !document.is_object() + ? nullptr + : std::make_shared( + std::move(document.as_object())))}; }; return AddTask(settings_.task_scheduler, pending_requests_, @@ -700,24 +709,23 @@ client::CancellationToken AuthenticationClientImpl::IntrospectApp( auto http_result = client.CallApi(kIntrospectAppEndpoint, "GET", {}, {}, {}, nullptr, {}, context); - rapidjson::Document document; - rapidjson::IStreamWrapper stream(http_result.GetRawResponse()); - document.ParseStream(stream); + boost::json::error_code ec; + auto document = boost::json::parse(http_result.GetRawResponse(), ec); if (http_result.GetStatus() != http::HttpStatusCode::OK) { // HttpResult response can be error message or valid json with it. std::string msg = http_result.GetResponseAsString(); - if (!document.HasParseError() && document.HasMember(Constants::MESSAGE)) { - msg = document[Constants::MESSAGE].GetString(); + if (!ec.failed() && document.as_object().contains(Constants::MESSAGE)) { + msg = document.as_object()[Constants::MESSAGE].as_string().c_str(); } return client::ApiError({http_result.GetStatus(), msg}); } - if (document.HasParseError()) { + if (ec.failed() || !document.is_object()) { return client::ApiError({static_cast(http::ErrorCode::UNKNOWN_ERROR), "Failed to parse response"}); } - return GetIntrospectAppResult(document); + return GetIntrospectAppResult(document.as_object()); }; return AddTask(settings_.task_scheduler, pending_requests_, @@ -747,25 +755,27 @@ client::CancellationToken AuthenticationClientImpl::Authorize( GenerateAuthorizeBody(request), kApplicationJson, context); - rapidjson::Document document; - rapidjson::IStreamWrapper stream(http_result.GetRawResponse()); - document.ParseStream(stream); + boost::json::error_code ec; + auto document = boost::json::parse(http_result.GetRawResponse(), ec); if (http_result.GetStatus() != http::HttpStatusCode::OK) { // HttpResult response can be error message or valid json with it. std::string msg = http_result.GetResponseAsString(); - if (!document.HasParseError() && document.HasMember(Constants::MESSAGE)) { - msg = document[Constants::MESSAGE].GetString(); + if (!ec.failed() && document.as_object().contains(Constants::MESSAGE)) { + msg = document.as_object()[Constants::MESSAGE].as_string().c_str(); } return client::ApiError({http_result.GetStatus(), msg}); - } else if (!document.HasParseError() && - document.HasMember(Constants::ERROR_CODE) && - document[Constants::ERROR_CODE].IsInt()) { + } + + if (!ec.failed() && document.as_object().contains(Constants::ERROR_CODE) && + document.as_object()[Constants::ERROR_CODE].is_int64()) { std::string msg = "Error code: " + - std::to_string(document[Constants::ERROR_CODE].GetInt()); - if (document.HasMember(Constants::MESSAGE)) { + std::to_string( + document.as_object()[Constants::ERROR_CODE].as_int64()); + if (document.as_object().contains(Constants::MESSAGE)) { msg.append(" ("); - msg.append(document[Constants::MESSAGE].GetString()); + msg.append( + document.as_object()[Constants::MESSAGE].as_string().c_str()); msg.append(")"); } @@ -773,12 +783,12 @@ client::CancellationToken AuthenticationClientImpl::Authorize( {static_cast(http::ErrorCode::UNKNOWN_ERROR), msg}); } - if (document.HasParseError()) { + if (ec.failed() || !document.is_object()) { return client::ApiError({static_cast(http::ErrorCode::UNKNOWN_ERROR), "Failed to parse response"}); } - return GetAuthorizeResult(document); + return GetAuthorizeResult(document.as_object()); }; return AddTask(settings_.task_scheduler, pending_requests_, std::move(task), @@ -819,237 +829,187 @@ client::OlpClient::RequestBodyType AuthenticationClientImpl::GenerateClientBody( return std::make_shared(content.data(), content.data() + content.size()); }; - rapidjson::StringBuffer data; - rapidjson::Writer writer(data); - writer.StartObject(); - writer.Key(kGrantType); - writer.String(kClientGrantType); + boost::json::object object; + + object[kGrantType] = kClientGrantType; auto expires_in = static_cast(properties.expires_in.count()); if (expires_in > 0) { - writer.Key(Constants::EXPIRES_IN); - writer.Uint(expires_in); + object[Constants::EXPIRES_IN] = expires_in; } if (properties.scope) { - writer.Key(kScope); - writer.String(properties.scope->c_str()); + object[kScope] = *properties.scope; } if (properties.device_id) { - writer.Key(kDeviceId); - writer.String(properties.device_id->c_str()); + object[kDeviceId] = *properties.device_id; } - writer.EndObject(); - auto content = data.GetString(); - return std::make_shared(content, content + data.GetSize()); + auto content = boost::json::serialize(object); + return std::make_shared(content.begin(), content.end()); } client::OlpClient::RequestBodyType AuthenticationClientImpl::GenerateUserBody( const UserProperties& properties) { - rapidjson::StringBuffer data; - rapidjson::Writer writer(data); - writer.StartObject(); + boost::json::object object; - writer.Key(kGrantType); - writer.String(kUserGrantType); + object[kGrantType] = kUserGrantType; if (!properties.email.empty()) { - writer.Key(kEmail); - writer.String(properties.email.c_str()); + object[kEmail] = properties.email; } if (!properties.password.empty()) { - writer.Key(kPassword); - writer.String(properties.password.c_str()); + object[kPassword] = properties.password; } if (properties.expires_in > 0) { - writer.Key(Constants::EXPIRES_IN); - writer.Uint(properties.expires_in); + object[Constants::EXPIRES_IN] = properties.expires_in; } - writer.EndObject(); - auto content = data.GetString(); - return std::make_shared(content, content + data.GetSize()); + + auto content = boost::json::serialize(object); + return std::make_shared(content.begin(), content.end()); } client::OlpClient::RequestBodyType AuthenticationClientImpl::GenerateFederatedBody( const FederatedSignInType type, const FederatedProperties& properties) { - rapidjson::StringBuffer data; - rapidjson::Writer writer(data); - writer.StartObject(); + boost::json::object object; - writer.Key(kGrantType); switch (type) { case FederatedSignInType::FacebookSignIn: - writer.String(kFacebookGrantType); + object[kGrantType] = kFacebookGrantType; break; case FederatedSignInType::ArcgisSignIn: - writer.String(kArcgisGrantType); + object[kGrantType] = kArcgisGrantType; break; default: return nullptr; } if (!properties.access_token.empty()) { - writer.Key(Constants::ACCESS_TOKEN); - writer.String(properties.access_token.c_str()); + object[Constants::ACCESS_TOKEN] = properties.access_token; } if (!properties.country_code.empty()) { - writer.Key(kCountryCode); - writer.String(properties.country_code.c_str()); + object[kCountryCode] = properties.country_code; } if (!properties.language.empty()) { - writer.Key(kLanguage); - writer.String(properties.language.c_str()); + object[kLanguage] = properties.language; } if (!properties.email.empty()) { - writer.Key(kEmail); - writer.String(properties.email.c_str()); + object[kEmail] = properties.email; } if (properties.expires_in > 0) { - writer.Key(Constants::EXPIRES_IN); - writer.Uint(properties.expires_in); + object[Constants::EXPIRES_IN] = properties.expires_in; } - writer.EndObject(); - auto content = data.GetString(); - return std::make_shared(content, content + data.GetSize()); + auto content = boost::json::serialize(object); + return std::make_shared(content.begin(), content.end()); } client::OlpClient::RequestBodyType AuthenticationClientImpl::GenerateRefreshBody( const RefreshProperties& properties) { - rapidjson::StringBuffer data; - rapidjson::Writer writer(data); - writer.StartObject(); + boost::json::object object; - writer.Key(kGrantType); - writer.String(kRefreshGrantType); + object[kGrantType] = kRefreshGrantType; if (!properties.access_token.empty()) { - writer.Key(Constants::ACCESS_TOKEN); - writer.String(properties.access_token.c_str()); + object[Constants::ACCESS_TOKEN] = properties.access_token; } if (!properties.refresh_token.empty()) { - writer.Key(Constants::REFRESH_TOKEN); - writer.String(properties.refresh_token.c_str()); + object[Constants::REFRESH_TOKEN] = properties.refresh_token; } if (properties.expires_in > 0) { - writer.Key(Constants::EXPIRES_IN); - writer.Uint(properties.expires_in); + object[Constants::EXPIRES_IN] = properties.expires_in; } - writer.EndObject(); - auto content = data.GetString(); - return std::make_shared(content, content + data.GetSize()); + + auto content = boost::json::serialize(object); + return std::make_shared(content.begin(), content.end()); } client::OlpClient::RequestBodyType AuthenticationClientImpl::GenerateSignUpBody( const SignUpProperties& properties) { - rapidjson::StringBuffer data; - rapidjson::Writer writer(data); - writer.StartObject(); + boost::json::object object; if (!properties.email.empty()) { - writer.Key(kEmail); - writer.String(properties.email.c_str()); + object[kEmail] = properties.email; } if (!properties.password.empty()) { - writer.Key(kPassword); - writer.String(properties.password.c_str()); + object[kPassword] = properties.password; } if (!properties.date_of_birth.empty()) { - writer.Key(kDateOfBirth); - writer.String(properties.date_of_birth.c_str()); + object[kDateOfBirth] = properties.date_of_birth; } if (!properties.first_name.empty()) { - writer.Key(kFirstName); - writer.String(properties.first_name.c_str()); + object[kFirstName] = properties.first_name; } if (!properties.last_name.empty()) { - writer.Key(kLastName); - writer.String(properties.last_name.c_str()); + object[kLastName] = properties.last_name; } if (!properties.country_code.empty()) { - writer.Key(kCountryCode); - writer.String(properties.country_code.c_str()); + object[kCountryCode] = properties.country_code; } if (!properties.language.empty()) { - writer.Key(kLanguage); - writer.String(properties.language.c_str()); + object[kLanguage] = properties.language; } if (properties.marketing_enabled) { - writer.Key(kMarketingEnabled); - writer.Bool(true); + object[kMarketingEnabled] = true; } if (!properties.phone_number.empty()) { - writer.Key(kPhoneNumber); - writer.String(properties.phone_number.c_str()); + object[kPhoneNumber] = properties.phone_number; } if (!properties.realm.empty()) { - writer.Key(kRealm); - writer.String(properties.realm.c_str()); + object[kRealm] = properties.realm; } if (!properties.invite_token.empty()) { - writer.Key(kInviteToken); - writer.String(properties.invite_token.c_str()); + object[kInviteToken] = properties.invite_token; } - writer.EndObject(); - auto content = data.GetString(); - return std::make_shared(content, content + data.GetSize()); + auto content = boost::json::serialize(object); + return std::make_shared(content.begin(), content.end()); } client::OlpClient::RequestBodyType AuthenticationClientImpl::GenerateAcceptTermBody( const std::string& reacceptance_token) { - rapidjson::StringBuffer data; - rapidjson::Writer writer(data); - writer.StartObject(); + boost::json::object object; - writer.Key(kTermsReacceptanceToken); - writer.String(reacceptance_token.c_str()); + object[kTermsReacceptanceToken] = reacceptance_token; - writer.EndObject(); - auto content = data.GetString(); - return std::make_shared(content, content + data.GetSize()); + auto content = boost::json::serialize(object); + return std::make_shared(content.begin(), content.end()); } client::OlpClient::RequestBodyType AuthenticationClientImpl::GenerateAuthorizeBody( const AuthorizeRequest& properties) { - rapidjson::StringBuffer data; - rapidjson::Writer writer(data); - writer.StartObject(); - writer.Key(kServiceId); - writer.String(properties.GetServiceId().c_str()); - writer.Key(kActions); - writer.StartArray(); - for (const auto& action : properties.GetActions()) { - writer.StartObject(); - writer.Key(kAction); - writer.String(action.first.c_str()); - if (!action.second.empty()) { - writer.Key(kResource); - writer.String(action.second.c_str()); + boost::json::object object; + + object[kServiceId] = properties.GetServiceId(); + + { + boost::json::array actions; + for (const auto& action : properties.GetActions()) { + boost::json::object action_value; + action_value[kAction] = action.first; + if (!action.second.empty()) { + action_value.emplace(kResource, action.second); + } + actions.emplace_back(std::move(action_value)); } - writer.EndObject(); + object.emplace(kActions, std::move(actions)); } - writer.EndArray(); - writer.Key(kDiagnostics); - writer.Bool(properties.GetDiagnostics()); + object[kDiagnostics] = properties.GetDiagnostics(); // default value is 'and', ignore parameter if operator type is 'and' if (properties.GetOperatorType() == AuthorizeRequest::DecisionOperatorType::kOr) { - writer.Key(kOperator); - writer.String("or"); + object[kOperator] = "or"; } - writer.EndObject(); - auto content = data.GetString(); - return std::make_shared(content, content + data.GetSize()); + auto content = boost::json::serialize(object); + return std::make_shared(content.begin(), content.end()); } std::string AuthenticationClientImpl::GenerateUid() const { diff --git a/olp-cpp-sdk-authentication/src/AuthenticationClientUtils.cpp b/olp-cpp-sdk-authentication/src/AuthenticationClientUtils.cpp index dd7c45c2a..3fc9715a8 100644 --- a/olp-cpp-sdk-authentication/src/AuthenticationClientUtils.cpp +++ b/olp-cpp-sdk-authentication/src/AuthenticationClientUtils.cpp @@ -26,10 +26,9 @@ #include #include -#include -#include -#include -#include +#include +#include +#include #include "Constants.h" #include "ResponseFromJsonBuilder.h" #include "Rfc1123Helper.h" @@ -72,25 +71,25 @@ std::string Base64Encode(const Crypto::Sha256Digest& digest) { return ret; } -Response Parse(client::HttpResponse& http_response) { - rapidjson::IStreamWrapper stream(http_response.GetRawResponse()); - rapidjson::Document document; - document.ParseStream(stream); +Response Parse(client::HttpResponse& http_response) { + boost::json::error_code ec; + auto document = boost::json::parse(http_response.GetRawResponse(), ec); if (http_response.GetStatus() != http::HttpStatusCode::OK) { // HttpResult response can be error message or valid json with it. std::string msg = http_response.GetResponseAsString(); - if (!document.HasParseError() && document.HasMember(Constants::MESSAGE)) { - msg = document[Constants::MESSAGE].GetString(); + if (!ec.failed() && document.is_object() && + document.as_object().contains(Constants::MESSAGE)) { + msg = document.as_object()[Constants::MESSAGE].get_string().c_str(); } return client::ApiError({http_response.GetStatus(), msg}); } - if (document.HasParseError()) { + if (ec.failed() || !document.is_object()) { return client::ApiError({static_cast(http::ErrorCode::UNKNOWN_ERROR), "Failed to parse response"}); } - return Response(std::move(document)); + return {std::move(document).as_object()}; } } // namespace @@ -119,7 +118,7 @@ porting::optional GetTimestampFromHeaders( return porting::none; } -IntrospectAppResult GetIntrospectAppResult(const rapidjson::Document& doc) { +IntrospectAppResult GetIntrospectAppResult(const boost::json::object& doc) { return ResponseFromJsonBuilder::Build(doc) .Value(Constants::CLIENT_ID, &IntrospectAppResult::SetClientId) .Value(Constants::NAME, &IntrospectAppResult::SetName) @@ -150,22 +149,25 @@ DecisionType GetDecision(const std::string& str) { : DecisionType::kDeny; } -std::vector GetDiagnostics(rapidjson::Document& doc) { +std::vector GetDiagnostics(boost::json::object& doc) { std::vector results; - const auto& array = doc[Constants::DIAGNOSTICS].GetArray(); - for (auto& element : array) { + auto& array = doc[Constants::DIAGNOSTICS].get_array(); + for (auto& element_value : array) { + auto& element = element_value.get_object(); ActionResult action; - if (element.HasMember(Constants::DECISION)) { - action.SetDecision(GetDecision(element[Constants::DECISION].GetString())); + if (element.contains(Constants::DECISION)) { + action.SetDecision( + GetDecision(element[Constants::DECISION].get_string().c_str())); // get permissions if avialible - if (element.HasMember(Constants::PERMISSIONS) && - element[Constants::PERMISSIONS].IsArray()) { + if (element.contains(Constants::PERMISSIONS) && + element[Constants::PERMISSIONS].is_array()) { std::vector permissions; const auto& permissions_array = - element[Constants::PERMISSIONS].GetArray(); + element[Constants::PERMISSIONS].get_array(); for (auto& permission_element : permissions_array) { Permission permission = - ResponseFromJsonBuilder::Build(permission_element) + ResponseFromJsonBuilder::Build( + permission_element.get_object()) .Value(Constants::ACTION, &Permission::SetAction) .Value(Constants::DECISION, &Permission::SetDecision, &GetDecision) @@ -182,26 +184,27 @@ std::vector GetDiagnostics(rapidjson::Document& doc) { return results; } -AuthorizeResult GetAuthorizeResult(rapidjson::Document& doc) { +AuthorizeResult GetAuthorizeResult(boost::json::object& doc) { AuthorizeResult result; - if (doc.HasMember(Constants::IDENTITY)) { - auto uris = doc[Constants::IDENTITY].GetObject(); + if (doc.contains(Constants::IDENTITY)) { + auto uris = doc[Constants::IDENTITY].get_object(); - if (uris.HasMember(Constants::CLIENT_ID)) { - result.SetClientId(uris[Constants::CLIENT_ID].GetString()); - } else if (uris.HasMember(Constants::USER_ID)) { - result.SetClientId(uris[Constants::USER_ID].GetString()); + if (uris.contains(Constants::CLIENT_ID)) { + result.SetClientId(uris[Constants::CLIENT_ID].get_string().c_str()); + } else if (uris.contains(Constants::USER_ID)) { + result.SetClientId(uris[Constants::USER_ID].get_string().c_str()); } } - if (doc.HasMember(Constants::DECISION)) { - result.SetDecision(GetDecision(doc[Constants::DECISION].GetString())); + if (doc.contains(Constants::DECISION)) { + result.SetDecision( + GetDecision(doc[Constants::DECISION].get_string().c_str())); } // get diagnostics if available - if (doc.HasMember(Constants::DIAGNOSTICS) && - doc[Constants::DIAGNOSTICS].IsArray()) { + if (doc.contains(Constants::DIAGNOSTICS) && + doc[Constants::DIAGNOSTICS].is_array()) { result.SetActionResults(GetDiagnostics(doc)); } return result; diff --git a/olp-cpp-sdk-authentication/src/AuthenticationClientUtils.h b/olp-cpp-sdk-authentication/src/AuthenticationClientUtils.h index 3904627df..6fdb5cd82 100644 --- a/olp-cpp-sdk-authentication/src/AuthenticationClientUtils.h +++ b/olp-cpp-sdk-authentication/src/AuthenticationClientUtils.h @@ -1,5 +1,5 @@ /* - * Copyright (C) 2020-2021 HERE Europe B.V. + * Copyright (C) 2020-2026 HERE Europe B.V. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -19,11 +19,12 @@ #pragma once +#include #include #include #include -#include +#include #include "olp/authentication/AuthenticationCredentials.h" #include "olp/authentication/AuthenticationSettings.h" @@ -78,7 +79,7 @@ porting::optional GetTimestampFromHeaders( * @param doc json document. * @return result for introspect app. */ -IntrospectAppResult GetIntrospectAppResult(const rapidjson::Document& doc); +IntrospectAppResult GetIntrospectAppResult(const boost::json::object& value); /* * @brief Convert string representation of decision to DecisionType. @@ -92,14 +93,14 @@ DecisionType GetDecision(const std::string& str); * @param doc json document. * @return result of ActionResults. */ -std::vector GetDiagnostics(rapidjson::Document& doc); +std::vector GetDiagnostics(boost::json::object& value); /* * @brief Parse json document to AuthorizeResult type. * @param doc json document. * @return result for authorize. */ -AuthorizeResult GetAuthorizeResult(rapidjson::Document& doc); +AuthorizeResult GetAuthorizeResult(boost::json::object& value); /* * @brief Parse HTTP response to UserAccountInfoResponse type or error message. diff --git a/olp-cpp-sdk-authentication/src/BaseResult.cpp b/olp-cpp-sdk-authentication/src/BaseResult.cpp index edd86f7c9..f19399961 100644 --- a/olp-cpp-sdk-authentication/src/BaseResult.cpp +++ b/olp-cpp-sdk-authentication/src/BaseResult.cpp @@ -1,5 +1,5 @@ /* - * Copyright (C) 2019-2021 HERE Europe B.V. + * Copyright (C) 2019-2026 HERE Europe B.V. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -19,8 +19,10 @@ #include "BaseResult.h" -#include -#include +#include + +#include +#include #include "Constants.h" #include "olp/core/http/HttpStatusCode.h" @@ -35,52 +37,49 @@ static const char* ERROR_MESSAGE = "message"; static const char* LINE_END = "."; BaseResult::BaseResult(int status, std::string error, - std::shared_ptr json_document) + std::shared_ptr json_document) : status_() { status_ = status; error_.message = std::move(error); - is_valid_ = (json_document && !json_document->HasParseError()); + is_valid_ = json_document != nullptr; // If HTTP error, try to get error details - if (!HasError() || !is_valid_ || !json_document->HasMember(ERROR_CODE)) { + if (!HasError() || !is_valid_ || !json_document->contains(ERROR_CODE)) { return; } // The JSON document has an error code member, so save full JSON content to // the `full_message_` string. - rapidjson::StringBuffer buffer; - rapidjson::Writer writer(buffer); - json_document->Accept(writer); - full_message_ = buffer.GetString(); + full_message_ = boost::json::serialize(*json_document); - if (json_document->HasMember(ERROR_ID)) { - error_.error_id = (*json_document)[ERROR_ID].GetString(); + if (json_document->contains(ERROR_ID)) { + error_.error_id = (*json_document)[ERROR_ID].get_string().c_str(); } // Enhance error message with network response error details - error_.code = (*json_document)[ERROR_CODE].GetUint(); + error_.code = (*json_document)[ERROR_CODE].to_number(); - if (!json_document->HasMember(ERROR_MESSAGE)) { + if (!json_document->contains(ERROR_MESSAGE)) { return; } - std::string message = (*json_document)[ERROR_MESSAGE].GetString(); - if (!json_document->HasMember(ERROR_FIELDS)) { + std::string message = (*json_document)[ERROR_MESSAGE].get_string().c_str(); + if (!json_document->contains(ERROR_FIELDS)) { error_.message = message; return; } error_.message = message.substr(0, message.find_first_of(LINE_END) + 1); - const rapidjson::Value& fields = (*json_document)[ERROR_FIELDS]; - if (fields.GetType() == rapidjson::kArrayType) { - for (rapidjson::SizeType i = 0u; i < fields.Size(); i++) { - const rapidjson::Value& field = fields[i]; - if (field.HasMember(ERROR_MESSAGE)) { + auto& fields = (*json_document)[ERROR_FIELDS]; + if (auto* fields_array = fields.if_array()) { + for (auto& field : *fields_array) { + if (field.is_object() && field.as_object().contains(ERROR_MESSAGE)) { ErrorField error_field; - error_field.name = field[FIELD_NAME].GetString(); - error_field.code = field[ERROR_CODE].GetUint(); - error_field.message = field[ERROR_MESSAGE].GetString(); + error_field.name = field.as_object()[FIELD_NAME].get_string().c_str(); + error_field.code = field.as_object()[ERROR_CODE].to_number(); + error_field.message = + field.as_object()[ERROR_MESSAGE].get_string().c_str(); error_fields_.emplace_back(error_field); } } diff --git a/olp-cpp-sdk-authentication/src/BaseResult.h b/olp-cpp-sdk-authentication/src/BaseResult.h index cd581275f..e0dae31c2 100644 --- a/olp-cpp-sdk-authentication/src/BaseResult.h +++ b/olp-cpp-sdk-authentication/src/BaseResult.h @@ -1,5 +1,5 @@ /* - * Copyright (C) 2019-2021 HERE Europe B.V. + * Copyright (C) 2019-2026 HERE Europe B.V. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -24,7 +24,7 @@ #include #include -#include +#include #include "olp/authentication/ErrorResponse.h" @@ -33,7 +33,7 @@ namespace authentication { class BaseResult { public: BaseResult(int status, std::string error, - std::shared_ptr json_document = nullptr); + std::shared_ptr json_document = nullptr); virtual ~BaseResult(); /** diff --git a/olp-cpp-sdk-authentication/src/ResponseFromJsonBuilder.h b/olp-cpp-sdk-authentication/src/ResponseFromJsonBuilder.h index 8d4ee37d5..ff49374ac 100644 --- a/olp-cpp-sdk-authentication/src/ResponseFromJsonBuilder.h +++ b/olp-cpp-sdk-authentication/src/ResponseFromJsonBuilder.h @@ -1,5 +1,5 @@ /* - * Copyright (C) 2020-2021 HERE Europe B.V. + * Copyright (C) 2020-2026 HERE Europe B.V. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -19,6 +19,10 @@ #pragma once +#include +#include +#include + #include #include @@ -35,7 +39,8 @@ struct Identity { template class ResponseFromJsonBuilder { - using JsonValue = rapidjson::Document::ValueType; + using JsonDoc = boost::json::object; + using JsonValue = boost::json::value; public: template @@ -46,16 +51,16 @@ class ResponseFromJsonBuilder { const std::string kLogTag = "ResponseFromJsonBuilder"; public: - explicit BuilderHelper(const JsonValue& json_value) : json_{json_value} {} + explicit BuilderHelper(const JsonDoc& json_value) : json_{json_value} {} template BuilderHelper& Value(const char* name, void (TargetType::*set_fn)(ArgType), Projection projection = {}) { using CompatibleType = decltype(GetCompatibleType()); fields_.emplace(name, [=](TargetType& target_obj, - const JsonValue& value) { - if (value.Is()) { - (target_obj.*set_fn)(projection(value.Get())); + const JsonValue& json_value) { + if (auto value = If(json_value)) { + (target_obj.*set_fn)(projection(*value)); } else { OLP_SDK_LOG_WARNING_F(kLogTag, "Wrong type, response=%s, field=%s", kTargetTypeName.c_str(), name); @@ -71,13 +76,13 @@ class ResponseFromJsonBuilder { decltype(GetCompatibleType()); fields_.emplace(name, [=](TargetType& target_obj, const JsonValue& value) { - if (value.IsArray()) { - const auto& array = value.GetArray(); + if (value.is_array()) { + const auto& array = value.get_array(); ArrayType array_result; - array_result.reserve(array.Size()); + array_result.reserve(array.size()); for (const auto& element : array) { - if (element.Is()) { - array_result.push_back(element.Get()); + if (auto element_value = If(element)) { + array_result.push_back(*element_value); } } (target_obj.*set_fn)(std::move(array_result)); @@ -92,12 +97,12 @@ class ResponseFromJsonBuilder { TargetType Finish() { TargetType result; - auto it = json_.MemberBegin(); - auto it_end = json_.MemberEnd(); + auto it = json_.cbegin(); + auto it_end = json_.cend(); for (; it != it_end; ++it) { - auto find_it = fields_.find(std::string{it->name.GetString()}); + auto find_it = fields_.find(std::string{it->key_c_str()}); if (find_it != fields_.end()) { - find_it->second(result, it->value); + find_it->second(result, it->value()); // erasing already processed value fields_.erase(find_it); continue; @@ -105,7 +110,7 @@ class ResponseFromJsonBuilder { OLP_SDK_LOG_WARNING_F(kLogTag, "Unexpected value, response=%s, field=%s", - kTargetTypeName.c_str(), it->name.GetString()); + kTargetTypeName.c_str(), it->key_c_str()); } // in the ideal scenario all fields should be processed @@ -133,11 +138,39 @@ class ResponseFromJsonBuilder { std::is_same::value>::type> int64_t GetCompatibleType(); + template ::value>::type> + const bool* If(const JsonValue& value) { + return value.if_bool(); + } + + template ::value || + std::is_same::value>::type> + const int64_t* If(const JsonValue& value) { + return value.if_int64(); + } + + template ::value>::type> + const uint64_t* If(const JsonValue& value) { + return value.if_uint64(); + } + + template ::value>::type> + porting::optional If(const JsonValue& value) { + if (auto* str = value.if_string()) { + return str->c_str(); + } + return nullptr; + } + using Fields = std::unordered_map>; - const JsonValue& json_; + const JsonDoc& json_; Fields fields_; }; diff --git a/olp-cpp-sdk-authentication/src/SignInResultImpl.cpp b/olp-cpp-sdk-authentication/src/SignInResultImpl.cpp index 96cfa8d7b..334de6cb1 100644 --- a/olp-cpp-sdk-authentication/src/SignInResultImpl.cpp +++ b/olp-cpp-sdk-authentication/src/SignInResultImpl.cpp @@ -1,5 +1,5 @@ /* - * Copyright (C) 2019-2025 HERE Europe B.V. + * Copyright (C) 2019-2026 HERE Europe B.V. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -19,6 +19,8 @@ #include "SignInResultImpl.h" +#include + #include "Constants.h" #include "olp/core/http/HttpStatusCode.h" @@ -33,45 +35,43 @@ constexpr auto kTokenTypeSnakeCase = "token_type"; constexpr auto kAccessTokenSnakeCase = "access_token"; constexpr auto kExpiresInSnakeCase = "expires_in"; -bool HasAccessToken(const rapidjson::Document& document) { - return document.HasMember(Constants::ACCESS_TOKEN) || - document.HasMember(kAccessTokenSnakeCase); +bool HasAccessToken(const boost::json::object& document) { + return document.contains(Constants::ACCESS_TOKEN) || + document.contains(kAccessTokenSnakeCase); } -std::string ParseAccessToken(const rapidjson::Document& document) { - if (document.HasMember(Constants::ACCESS_TOKEN)) { - return document[Constants::ACCESS_TOKEN].GetString(); +std::string ParseAccessToken(const boost::json::object& document) { + if (document.contains(Constants::ACCESS_TOKEN)) { + return document.at(Constants::ACCESS_TOKEN).get_string().c_str(); } - - return document[kAccessTokenSnakeCase].GetString(); + return document.at(kAccessTokenSnakeCase).get_string().c_str(); } -bool HasExpiresIn(const rapidjson::Document& document) { - return document.HasMember(Constants::EXPIRES_IN) || - document.HasMember(kExpiresInSnakeCase); +bool HasExpiresIn(const boost::json::object& document) { + return document.contains(Constants::EXPIRES_IN) || + document.contains(kExpiresInSnakeCase); } -unsigned ParseExpiresIn(const rapidjson::Document& document) { - if (document.HasMember(Constants::EXPIRES_IN)) { - return document[Constants::EXPIRES_IN].GetUint(); +uint64_t ParseExpiresIn(const boost::json::object& document) { + if (document.contains(Constants::EXPIRES_IN)) { + return document.at(Constants::EXPIRES_IN).to_number(); } - return document[kExpiresInSnakeCase].GetUint(); + return document.at(kExpiresInSnakeCase).to_number(); } -bool HasTokenType(const rapidjson::Document& document) { - return document.HasMember(kTokenType) || - document.HasMember(kTokenTypeSnakeCase); +bool HasTokenType(const boost::json::object& document) { + return document.contains(kTokenType) || + document.contains(kTokenTypeSnakeCase); } -std::string ParseTokenType(const rapidjson::Document& document) { - if (document.HasMember(kTokenType)) { - return document[kTokenType].GetString(); +std::string ParseTokenType(const boost::json::object& document) { + if (document.contains(kTokenType)) { + return document.at(kTokenType).get_string().c_str(); } - - return document[kTokenTypeSnakeCase].GetString(); + return document.at(kTokenTypeSnakeCase).get_string().c_str(); } -bool IsDocumentValid(const rapidjson::Document& document) { +bool IsDocumentValid(const boost::json::object& document) { return HasAccessToken(document) && HasExpiresIn(document) && HasTokenType(document); } @@ -84,7 +84,7 @@ SignInResultImpl::SignInResultImpl() noexcept SignInResultImpl::SignInResultImpl( int status, std::string error, - std::shared_ptr json_document) noexcept + std::shared_ptr json_document) noexcept : BaseResult(status, std::move(error), json_document), expiry_time_(), expires_in_() { @@ -100,17 +100,18 @@ SignInResultImpl::SignInResultImpl( access_token_ = ParseAccessToken(*json_document); if (HasTokenType(*json_document)) token_type_ = ParseTokenType(*json_document); - if (json_document->HasMember(Constants::REFRESH_TOKEN)) - refresh_token_ = (*json_document)[Constants::REFRESH_TOKEN].GetString(); + if (json_document->contains(Constants::REFRESH_TOKEN)) + refresh_token_ = + json_document->at(Constants::REFRESH_TOKEN).get_string().c_str(); if (HasExpiresIn(*json_document)) { const auto expires_in = ParseExpiresIn(*json_document); expiry_time_ = std::time(nullptr) + expires_in; expires_in_ = std::chrono::seconds(expires_in); } - if (json_document->HasMember(kUserId)) - user_identifier_ = (*json_document)[kUserId].GetString(); - if (json_document->HasMember(kScope)) - scope_ = (*json_document)[kScope].GetString(); + if (json_document->contains(kUserId)) + user_identifier_ = json_document->at(kUserId).get_string().c_str(); + if (json_document->contains(kScope)) + scope_ = json_document->at(kScope).get_string().c_str(); } } } diff --git a/olp-cpp-sdk-authentication/src/SignInResultImpl.h b/olp-cpp-sdk-authentication/src/SignInResultImpl.h index 1712f443f..bad5abad5 100644 --- a/olp-cpp-sdk-authentication/src/SignInResultImpl.h +++ b/olp-cpp-sdk-authentication/src/SignInResultImpl.h @@ -1,5 +1,5 @@ /* - * Copyright (C) 2019-2021 HERE Europe B.V. + * Copyright (C) 2019-2026 HERE Europe B.V. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -19,10 +19,10 @@ #pragma once +#include #include #include #include -#include #include "BaseResult.h" @@ -34,7 +34,7 @@ class SignInResultImpl : public BaseResult { SignInResultImpl( int status, std::string error, - std::shared_ptr json_document = nullptr) noexcept; + std::shared_ptr json_document = nullptr) noexcept; ~SignInResultImpl() override; @@ -65,7 +65,7 @@ class SignInResultImpl : public BaseResult { */ time_t GetExpiryTime() const; - /** + /** * @brief Gets the access token expiry time in seconds. * @return Duration for which token stays valid. */ diff --git a/olp-cpp-sdk-authentication/src/SignInUserResultImpl.cpp b/olp-cpp-sdk-authentication/src/SignInUserResultImpl.cpp index 36530f40d..10eddcc76 100644 --- a/olp-cpp-sdk-authentication/src/SignInUserResultImpl.cpp +++ b/olp-cpp-sdk-authentication/src/SignInUserResultImpl.cpp @@ -1,5 +1,5 @@ /* - * Copyright (C) 2019-2021 HERE Europe B.V. + * Copyright (C) 2019-2026 HERE Europe B.V. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -19,6 +19,8 @@ #include "SignInUserResultImpl.h" +#include + #include "Constants.h" #include "olp/core/http/HttpStatusCode.h" @@ -40,23 +42,24 @@ SignInUserResultImpl::SignInUserResultImpl() noexcept SignInUserResultImpl::SignInUserResultImpl( int status, std::string error, - std::shared_ptr json_document) noexcept + std::shared_ptr json_document) noexcept : SignInResultImpl(status, std::move(error), json_document) { if (BaseResult::IsValid()) { - if (json_document->HasMember(kTermsReacceptanceToken)) + if (json_document->contains(kTermsReacceptanceToken)) term_acceptance_token_ = - (*json_document)[kTermsReacceptanceToken].GetString(); - if (json_document->HasMember(kTermsUrls)) { - rapidjson::Document::Object obj = - (*json_document)[kTermsUrls].GetObject(); - if (obj.HasMember(kTermsOfServiceUrl)) - terms_of_service_url_ = obj[kTermsOfServiceUrl].GetString(); - if (obj.HasMember(kTermsOfServiceUrlJson)) - terms_of_service_url_json_ = obj[kTermsOfServiceUrlJson].GetString(); - if (obj.HasMember(kPrivatePolicyUrl)) - private_policy_url_ = obj[kPrivatePolicyUrl].GetString(); - if (obj.HasMember(kPrivatePolicyUrlJson)) - private_policy_url_json_ = obj[kPrivatePolicyUrlJson].GetString(); + (*json_document)[kTermsReacceptanceToken].get_string().c_str(); + if (json_document->contains(kTermsUrls)) { + auto& obj = (*json_document)[kTermsUrls].get_object(); + if (obj.contains(kTermsOfServiceUrl)) + terms_of_service_url_ = obj[kTermsOfServiceUrl].get_string().c_str(); + if (obj.contains(kTermsOfServiceUrlJson)) + terms_of_service_url_json_ = + obj[kTermsOfServiceUrlJson].get_string().c_str(); + if (obj.contains(kPrivatePolicyUrl)) + private_policy_url_ = obj[kPrivatePolicyUrl].get_string().c_str(); + if (obj.contains(kPrivatePolicyUrlJson)) + private_policy_url_json_ = + obj[kPrivatePolicyUrlJson].get_string().c_str(); } } } diff --git a/olp-cpp-sdk-authentication/src/SignInUserResultImpl.h b/olp-cpp-sdk-authentication/src/SignInUserResultImpl.h index c6fd5218c..15425e57f 100644 --- a/olp-cpp-sdk-authentication/src/SignInUserResultImpl.h +++ b/olp-cpp-sdk-authentication/src/SignInUserResultImpl.h @@ -1,5 +1,5 @@ /* - * Copyright (C) 2019-2021 HERE Europe B.V. + * Copyright (C) 2019-2026 HERE Europe B.V. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -20,6 +20,7 @@ #pragma once #include +#include #include #include "SignInResultImpl.h" @@ -41,7 +42,7 @@ class SignInUserResultImpl : public SignInResultImpl { SignInUserResultImpl( int status, std::string error, - std::shared_ptr json_document = nullptr) noexcept; + std::shared_ptr json_document = nullptr) noexcept; ~SignInUserResultImpl() override; diff --git a/olp-cpp-sdk-authentication/src/SignOutResultImpl.cpp b/olp-cpp-sdk-authentication/src/SignOutResultImpl.cpp index d223919f4..3b381d9c0 100644 --- a/olp-cpp-sdk-authentication/src/SignOutResultImpl.cpp +++ b/olp-cpp-sdk-authentication/src/SignOutResultImpl.cpp @@ -1,5 +1,5 @@ /* - * Copyright (C) 2019-2021 HERE Europe B.V. + * Copyright (C) 2019-2026 HERE Europe B.V. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -19,6 +19,8 @@ #include "SignOutResultImpl.h" +#include + #include "Constants.h" #include "olp/core/http/HttpStatusCode.h" @@ -31,7 +33,7 @@ SignOutResultImpl::SignOutResultImpl() noexcept SignOutResultImpl::SignOutResultImpl( int status, std::string error, - std::shared_ptr json_document) noexcept + std::shared_ptr json_document) noexcept : BaseResult(status, std::move(error), json_document) {} SignOutResultImpl::~SignOutResultImpl() = default; diff --git a/olp-cpp-sdk-authentication/src/SignOutResultImpl.h b/olp-cpp-sdk-authentication/src/SignOutResultImpl.h index 8c13229db..d23dccff5 100644 --- a/olp-cpp-sdk-authentication/src/SignOutResultImpl.h +++ b/olp-cpp-sdk-authentication/src/SignOutResultImpl.h @@ -1,5 +1,5 @@ /* - * Copyright (C) 2019 HERE Europe B.V. + * Copyright (C) 2019-2026 HERE Europe B.V. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -33,7 +33,7 @@ class SignOutResultImpl : public BaseResult { SignOutResultImpl( int status, std::string error, - std::shared_ptr json_document = nullptr) noexcept; + std::shared_ptr json_document = nullptr) noexcept; ~SignOutResultImpl() override; }; diff --git a/olp-cpp-sdk-authentication/src/SignUpResultImpl.cpp b/olp-cpp-sdk-authentication/src/SignUpResultImpl.cpp index 27ea17db3..a62e080c3 100644 --- a/olp-cpp-sdk-authentication/src/SignUpResultImpl.cpp +++ b/olp-cpp-sdk-authentication/src/SignUpResultImpl.cpp @@ -1,5 +1,5 @@ /* - * Copyright (C) 2019-2021 HERE Europe B.V. + * Copyright (C) 2019-2026 HERE Europe B.V. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -19,6 +19,8 @@ #include "SignUpResultImpl.h" +#include + #include "Constants.h" #include "olp/core/http/HttpStatusCode.h" @@ -35,11 +37,11 @@ SignUpResultImpl::SignUpResultImpl() noexcept SignUpResultImpl::SignUpResultImpl( int status, std::string error, - std::shared_ptr json_document) noexcept + std::shared_ptr json_document) noexcept : BaseResult(status, std::move(error), json_document) { if (BaseResult::IsValid()) { - if (json_document->HasMember(kUserId)) - user_identifier_ = (*json_document)[kUserId].GetString(); + if (json_document->contains(kUserId)) + user_identifier_ = (*json_document)[kUserId].get_string().c_str(); } } diff --git a/olp-cpp-sdk-authentication/src/SignUpResultImpl.h b/olp-cpp-sdk-authentication/src/SignUpResultImpl.h index 7434d8e0a..e51adf3ee 100644 --- a/olp-cpp-sdk-authentication/src/SignUpResultImpl.h +++ b/olp-cpp-sdk-authentication/src/SignUpResultImpl.h @@ -1,5 +1,5 @@ /* - * Copyright (C) 2019-2021 HERE Europe B.V. + * Copyright (C) 2019-2026 HERE Europe B.V. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -23,7 +23,7 @@ #include #include -#include +#include #include "BaseResult.h" @@ -35,7 +35,7 @@ class SignUpResultImpl : public BaseResult { SignUpResultImpl( int status, std::string error, - std::shared_ptr json_document = nullptr) noexcept; + std::shared_ptr json_document = nullptr) noexcept; ~SignUpResultImpl() override; diff --git a/olp-cpp-sdk-authentication/src/TokenEndpointImpl.cpp b/olp-cpp-sdk-authentication/src/TokenEndpointImpl.cpp index 52bf22fa9..a3808009a 100644 --- a/olp-cpp-sdk-authentication/src/TokenEndpointImpl.cpp +++ b/olp-cpp-sdk-authentication/src/TokenEndpointImpl.cpp @@ -1,5 +1,5 @@ /* - * Copyright (C) 2021-2024 HERE Europe B.V. + * Copyright (C) 2021-2026 HERE Europe B.V. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -29,10 +29,9 @@ #include #include #include -#include -#include -#include -#include +#include +#include +#include #include #include #include "AuthenticationClientUtils.h" @@ -102,22 +101,24 @@ void RetryDelay(const client::RetrySettings& retry_settings, size_t retry) { } TimeResponse ParseTimeResponse(const std::string& payload) { - rapidjson::Document document; - document.Parse(payload.c_str()); + boost::json::error_code ec; + auto document = boost::json::parse(payload, ec); - if (!document.IsObject()) { + if (!document.is_object()) { return client::ApiError(client::ErrorCode::InternalFailure, "JSON document root is not an Object type"); } - const auto timestamp_it = document.FindMember("timestamp"); - if (timestamp_it == document.MemberEnd() || !timestamp_it->value.IsUint()) { + const auto timestamp_it = document.as_object().find("timestamp"); + if (timestamp_it == document.as_object().end() || + (!timestamp_it->value().is_uint64() && + !timestamp_it->value().is_int64())) { return client::ApiError( client::ErrorCode::InternalFailure, "JSON document must contain timestamp integer field"); } - return timestamp_it->value.GetUint(); + return timestamp_it->value().to_number(); } std::string GenerateUid() { @@ -130,28 +131,22 @@ std::string GenerateUid() { client::OlpClient::RequestBodyType GenerateClientBody( const TokenRequest& token_request, const porting::optional& scope) { - rapidjson::StringBuffer data; - rapidjson::Writer writer(data); - writer.StartObject(); + boost::json::object object; - writer.Key(kGrantType); - writer.String(kClientGrantType); + object[kGrantType] = kClientGrantType; auto expires_in = static_cast(token_request.GetExpiresIn().count()); if (expires_in > 0) { - writer.Key(Constants::EXPIRES_IN); - writer.Uint(expires_in); + object[Constants::EXPIRES_IN] = expires_in; } if (scope) { - writer.Key(kScope); - writer.String(scope->c_str()); + object[kScope] = *scope; } - writer.EndObject(); - auto content = data.GetString(); - return std::make_shared(content, content + data.GetSize()); + auto content = boost::json::serialize(object); + return std::make_shared(content.begin(), content.end()); } TimeResponse GetTimeFromServer(client::CancellationContext& context, @@ -334,11 +329,13 @@ SignInResponse TokenEndpointImpl::SignInClient( SignInResult TokenEndpointImpl::ParseAuthResponse( int status, std::stringstream& auth_response) { - auto document = std::make_shared(); - rapidjson::IStreamWrapper stream(auth_response); - document->ParseStream(stream); + boost::json::error_code ec; + auto document = boost::json::parse(auth_response, ec); return std::make_shared( - status, http::HttpErrorToString(status), document); + status, http::HttpErrorToString(status), + ec.failed() || !document.is_object() + ? nullptr + : std::make_shared(document.as_object())); } client::HttpResponse TokenEndpointImpl::CallAuth( diff --git a/olp-cpp-sdk-authentication/src/utils/BoostJsonSrc.cpp b/olp-cpp-sdk-authentication/src/utils/BoostJsonSrc.cpp new file mode 100644 index 000000000..017758210 --- /dev/null +++ b/olp-cpp-sdk-authentication/src/utils/BoostJsonSrc.cpp @@ -0,0 +1,20 @@ +/* + * Copyright (C) 2026 HERE Europe B.V. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * SPDX-License-Identifier: Apache-2.0 + * License-Filename: LICENSE + */ + +#include diff --git a/olp-cpp-sdk-authentication/tests/SignInResultImplTest.cpp b/olp-cpp-sdk-authentication/tests/SignInResultImplTest.cpp index 08599cc54..3381c0123 100644 --- a/olp-cpp-sdk-authentication/tests/SignInResultImplTest.cpp +++ b/olp-cpp-sdk-authentication/tests/SignInResultImplTest.cpp @@ -1,5 +1,5 @@ /* - * Copyright (C) 2020-2025 HERE Europe B.V. + * Copyright (C) 2020-2026 HERE Europe B.V. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -19,6 +19,7 @@ #include #include +#include #include "../src/SignInResultImpl.h" namespace { @@ -82,8 +83,12 @@ constexpr auto kWrongFormatResponse = TEST(SignInResultImplTest, Constructor) { { SCOPED_TRACE("Valid token"); - auto doc = std::make_shared(); - doc->Parse(kTokenResponse); + + boost::system::error_code error_code; + auto doc = std::make_shared( + boost::json::parse(kTokenResponse, error_code).as_object()); + ASSERT_FALSE(error_code.failed()); + olp::authentication::SignInResultImpl result(olp::http::HttpStatusCode::OK, std::string(), doc); @@ -95,8 +100,12 @@ TEST(SignInResultImplTest, Constructor) { { SCOPED_TRACE("Valid token from snake case response"); - auto doc = std::make_shared(); - doc->Parse(kTokenResponseSnakeCase); + + boost::system::error_code error_code; + auto doc = std::make_shared( + boost::json::parse(kTokenResponseSnakeCase, error_code).as_object()); + ASSERT_FALSE(error_code.failed()); + olp::authentication::SignInResultImpl result(olp::http::HttpStatusCode::OK, std::string(), doc); @@ -108,8 +117,12 @@ TEST(SignInResultImplTest, Constructor) { { SCOPED_TRACE("Bad response"); - auto doc = std::make_shared(); - doc->Parse(kWrongFormatResponse); + + boost::system::error_code error_code; + auto doc = std::make_shared( + boost::json::parse(kWrongFormatResponse, error_code).as_object()); + ASSERT_FALSE(error_code.failed()); + olp::authentication::SignInResultImpl result(olp::http::HttpStatusCode::OK, std::string(), doc); diff --git a/tests/functional/olp-cpp-sdk-authentication/AuthenticationTestUtils.cpp b/tests/functional/olp-cpp-sdk-authentication/AuthenticationTestUtils.cpp index ce5b2c7bd..00313d280 100644 --- a/tests/functional/olp-cpp-sdk-authentication/AuthenticationTestUtils.cpp +++ b/tests/functional/olp-cpp-sdk-authentication/AuthenticationTestUtils.cpp @@ -1,5 +1,5 @@ /* - * Copyright (C) 2019 HERE Europe B.V. + * Copyright (C) 2019-2026 HERE Europe B.V. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -19,26 +19,34 @@ #include "AuthenticationTestUtils.h" -#include #include +#include #ifndef WIN32 #include #endif -#include -#include -#include -#include +#include +#include +#include + #include #include #include #include #include "TestConstants.h" -using namespace ::olp::authentication; - namespace { + +using olp::authentication::kAccessToken; +using olp::authentication::kAndParam; +using olp::authentication::kEqualsParam; +using olp::authentication::kHereAccountStagingURL; +using olp::authentication::kMaxRetryCount; +using olp::authentication::kQuestionParam; +using olp::authentication::kRetryDelayInSecs; +using olp::authentication::kTestUserName; + constexpr auto kFacebookUrl = "https://graph.facebook.com/v2.12"; constexpr auto kId = "id"; @@ -79,8 +87,8 @@ bool AuthenticationTestUtils::CreateFacebookTestUser( unsigned int retry = 0u; do { if (retry > 0u) { - OLP_SDK_LOG_WARNING(__func__, "Request retry attempted (" << retry - << ")"); + OLP_SDK_LOG_WARNING(__func__, + "Request retry attempted (" << retry << ")"); std::this_thread::sleep_for( std::chrono::seconds(retry * kRetryDelayInSecs)); } @@ -89,27 +97,26 @@ bool AuthenticationTestUtils::CreateFacebookTestUser( std::promise promise; auto future = promise.get_future(); - network.Send(request, payload, - [payload, &promise, - &user](const olp::http::NetworkResponse &network_response) { - user.token.status = network_response.GetStatus(); - if (user.token.status == olp::http::HttpStatusCode::OK) { - auto document = std::make_shared(); - rapidjson::IStreamWrapper stream(*payload); - document->ParseStream(stream); - const bool is_valid = - !document->HasParseError() && - document->HasMember(kAccessToken.c_str()) && - document->HasMember(kId); - - if (is_valid) { - user.token.access_token = - (*document)[kAccessToken.c_str()].GetString(); - user.id = (*document)[kId].GetString(); - } - } - promise.set_value(); - }); + network.Send( + request, payload, + [payload, &promise, + &user](const olp::http::NetworkResponse &network_response) { + user.token.status = network_response.GetStatus(); + if (user.token.status == olp::http::HttpStatusCode::OK) { + boost::json::error_code ec; + auto document = boost::json::parse(*payload, ec); + const bool is_valid = !ec.failed() && document.is_object() && + document.as_object().contains(kAccessToken) && + document.as_object().contains(kId); + + if (is_valid) { + user.token.access_token = + document.as_object()[kAccessToken].get_string().c_str(); + user.id = document.as_object()[kId].get_string().c_str(); + } + } + promise.set_value(); + }); future.wait(); } while ((user.token.status < 0) && (++retry < kMaxRetryCount)); @@ -132,8 +139,8 @@ bool AuthenticationTestUtils::DeleteFacebookTestUser( unsigned int retry = 0u; do { if (retry > 0u) { - OLP_SDK_LOG_WARNING(__func__, "Request retry attempted (" << retry - << ")"); + OLP_SDK_LOG_WARNING(__func__, + "Request retry attempted (" << retry << ")"); std::this_thread::sleep_for( std::chrono::seconds(retry * kRetryDelayInSecs)); } @@ -220,8 +227,8 @@ bool AuthenticationTestUtils::GetAccessTokenImpl( unsigned int retry = 0u; do { if (retry > 0u) { - OLP_SDK_LOG_WARNING(__func__, "Request retry attempted (" << retry - << ")"); + OLP_SDK_LOG_WARNING(__func__, + "Request retry attempted (" << retry << ")"); std::this_thread::sleep_for( std::chrono::seconds(retry * kRetryDelayInSecs)); } @@ -230,23 +237,23 @@ bool AuthenticationTestUtils::GetAccessTokenImpl( std::promise promise; auto future = promise.get_future(); - network.Send(request, payload, - [payload, &promise, - &token](const olp::http::NetworkResponse &network_response) { - token.status = network_response.GetStatus(); - if (token.status == olp::http::HttpStatusCode::OK) { - auto document = std::make_shared(); - rapidjson::IStreamWrapper stream(*payload); - document->ParseStream(stream); - bool is_valid = !document->HasParseError() && - document->HasMember(kAccessToken.c_str()); - if (is_valid) { - token.access_token = - (*document)[kAccessToken.c_str()].GetString(); - } - } - promise.set_value(); - }); + network.Send( + request, payload, + [payload, &promise, + &token](const olp::http::NetworkResponse &network_response) { + token.status = network_response.GetStatus(); + if (token.status == olp::http::HttpStatusCode::OK) { + boost::json::error_code ec; + auto document = boost::json::parse(*payload, ec); + const bool is_valid = !ec.failed() && document.is_object() && + document.as_object().contains(kAccessToken); + if (is_valid) { + token.access_token = + document.as_object()[kAccessToken].get_string().c_str(); + } + } + promise.set_value(); + }); future.wait(); } while ((token.status < 0) && (++retry < kMaxRetryCount)); diff --git a/tests/functional/olp-cpp-sdk-authentication/FederatedAuthenticationTest.cpp b/tests/functional/olp-cpp-sdk-authentication/FederatedAuthenticationTest.cpp index 9003077f8..a49db9101 100644 --- a/tests/functional/olp-cpp-sdk-authentication/FederatedAuthenticationTest.cpp +++ b/tests/functional/olp-cpp-sdk-authentication/FederatedAuthenticationTest.cpp @@ -1,5 +1,5 @@ /* - * Copyright (C) 2020 HERE Europe B.V. + * Copyright (C) 2020-2025 HERE Europe B.V. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -17,9 +17,8 @@ * License-Filename: LICENSE */ -#include -#include -#include +#include +#include #include #include @@ -27,8 +26,6 @@ #include "AuthenticationTestUtils.h" #include "TestConstants.h" -using namespace ::olp::authentication; - namespace { class FederatedAuthenticationTest : public AuthenticationCommonTestFixture { @@ -65,23 +62,13 @@ class FederatedAuthenticationTest : public AuthenticationCommonTestFixture { std::string GoogleAuthenticationBody(const std::string& email, const std::string& access_token) { - rapidjson::StringBuffer data; - - rapidjson::Writer writer(data); - writer.StartObject(); - writer.Key("grantType"); - writer.String("google"); - writer.Key("accessToken"); - writer.String(access_token.c_str()); - writer.Key("countryCode"); - writer.String("USA"); - writer.Key("language"); - writer.String("en"); - writer.Key("email"); - writer.String(email.c_str()); - writer.EndObject(); - - return data.GetString(); + boost::json::object object; + object["grantType"] = "google"; + object["accessToken"] = access_token; + object["countryCode"] = "USA"; + object["language"] = "en"; + object["email"] = email; + return boost::json::serialize(object); } protected: From e8ee4383c448356f14db862b87bc6d9e96fb5a92 Mon Sep 17 00:00:00 2001 From: Rustam Gamidov <108531570+rustam-gamidov-here@users.noreply.github.com> Date: Wed, 4 Mar 2026 14:25:52 +0200 Subject: [PATCH 06/12] Build with OLP_SDK_NO_EXCEPTION=ON using clang (#1676) It appeared that Clang and GCC complains on different lines at least in case of Boost codebase Relates-To: MINOR Signed-off-by: Rustam Gamidov --- .github/workflows/psv_pipelines.yml | 4 +-- .../boost/boost_182_json_noexceptions.diff | 26 +++++++++++++++++++ 2 files changed, 28 insertions(+), 2 deletions(-) diff --git a/.github/workflows/psv_pipelines.yml b/.github/workflows/psv_pipelines.yml index be86659d2..16cb1deed 100644 --- a/.github/workflows/psv_pipelines.yml +++ b/.github/workflows/psv_pipelines.yml @@ -197,14 +197,14 @@ jobs: shell: bash psv-linux-22-04-clang-hidden-build: - name: PSV.Linux.22.04.clang.hidden + name: PSV.Linux.22.04.clang.hidden.OLP_SDK_NO_EXCEPTION=ON runs-on: ubuntu-22.04 env: BUILD_TYPE: RelWithDebInfo CC: clang-11 CXX: clang++-11 CXXFLAGS: -Wno-deprecated-copy - EXTRA_CMAKE_OPTIONS: -DCMAKE_CXX_VISIBILITY_PRESET=hidden -DOLP_SDK_ENABLE_TESTING=OFF + EXTRA_CMAKE_OPTIONS: -DCMAKE_CXX_VISIBILITY_PRESET=hidden -DOLP_SDK_ENABLE_TESTING=OFF -DOLP_SDK_NO_EXCEPTION=ON steps: - name: Check out repository uses: actions/checkout@v4 diff --git a/external/boost/boost_182_json_noexceptions.diff b/external/boost/boost_182_json_noexceptions.diff index 507e3cecf..a0defe5eb 100644 --- a/external/boost/boost_182_json_noexceptions.diff +++ b/external/boost/boost_182_json_noexceptions.diff @@ -1,3 +1,29 @@ +diff --git a/libs/json/include/boost/json/detail/value_to.hpp b/libs/json/include/boost/json/detail/value_to.hpp +index 7cb779e..6df1c9d 100644 +--- a/libs/json/include/boost/json/detail/value_to.hpp ++++ b/libs/json/include/boost/json/detail/value_to.hpp +@@ -652,10 +652,13 @@ value_to_impl( + value const& jv, + user_conversion_tag) + { ++#ifndef BOOST_NO_EXCEPTIONS + try + { ++#endif // BOOST_NO_EXCEPTIONS + return { + boost::system::in_place_value, tag_invoke(value_to_tag(), jv)}; ++#ifndef BOOST_NO_EXCEPTIONS + } + catch( std::bad_alloc const&) + { +@@ -671,6 +674,7 @@ value_to_impl( + BOOST_JSON_FAIL(ec, error::exception); + return {boost::system::in_place_error, ec}; + } ++#endif // BOOST_NO_EXCEPTIONS + } + + // no suitable conversion implementation diff --git a/libs/json/include/boost/json/impl/value.ipp b/libs/json/include/boost/json/impl/value.ipp index 7460c02..7513b38 100644 --- a/libs/json/include/boost/json/impl/value.ipp From 755e26653fe8489fd9a20db6d208606c692392d8 Mon Sep 17 00:00:00 2001 From: Rustam Gamidov <108531570+rustam-gamidov-here@users.noreply.github.com> Date: Thu, 5 Mar 2026 14:33:14 +0200 Subject: [PATCH 07/12] Boost includes to private section of auth lib (#1678) Migrating from RapidJSON Relates-To: OCMAM-443 Signed-off-by: Rustam Gamidov --- olp-cpp-sdk-authentication/CMakeLists.txt | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/olp-cpp-sdk-authentication/CMakeLists.txt b/olp-cpp-sdk-authentication/CMakeLists.txt index 64908df2e..f36f48759 100644 --- a/olp-cpp-sdk-authentication/CMakeLists.txt +++ b/olp-cpp-sdk-authentication/CMakeLists.txt @@ -27,10 +27,13 @@ add_library(${PROJECT_NAME} ${AUTHENTICATION_SRC} ${AUTHENTICATION_INC}) -target_include_directories(${PROJECT_NAME} PUBLIC - $ - $ - $) +target_include_directories(${PROJECT_NAME} + PUBLIC + $ + $ + PRIVATE + $ +) # Used also in the package config file set(PROJECT_LIBS olp-cpp-sdk-core) From 8803644797b41ee5f9db0e0afdb8fad75fec9e49 Mon Sep 17 00:00:00 2001 From: Rustam Gamidov <108531570+rustam-gamidov-here@users.noreply.github.com> Date: Wed, 11 Mar 2026 14:11:20 +0200 Subject: [PATCH 08/12] Use Boost::json in olp-cpp-sdk-dataservice-write (#1681) Migrating from RapidJSON Copy json implementation wrappers to write lib This allows to keep other libs untouched until fully migrated to the boost::json and remove write lib dependency from public json wrappers. Alternative solutions tried are: - add boost json wrappers to the same files in the core but to additional namespace - changes in core, json still exposed - move boost json wrappers from core to internal for the repository include location and add it to all DataSDK projects - huge change Relates-To: OCMAM-445 Signed-off-by: Rustam Gamidov --- olp-cpp-sdk-dataservice-write/CMakeLists.txt | 20 +- .../src/CatalogSettings.cpp | 6 +- .../src/JsonResultParser.h | 4 +- .../src/generated/parser/ApiParser.cpp | 8 +- .../src/generated/parser/ApiParser.h | 6 +- .../src/generated/parser/CatalogParser.cpp | 34 ++-- .../src/generated/parser/CatalogParser.h | 30 +-- .../src/generated/parser/DetailsParser.cpp | 8 +- .../src/generated/parser/DetailsParser.h | 6 +- .../src/generated/parser/JsonParser.h | 78 ++++++++ .../generated/parser/LayerVersionsParser.cpp | 12 +- .../generated/parser/LayerVersionsParser.h | 8 +- .../src/generated/parser/ParserWrapper.h | 102 ++++++++++ .../src/generated/parser/PartitionParser.h | 8 +- .../src/generated/parser/PartitionsParser.cpp | 12 +- .../src/generated/parser/PartitionsParser.h | 8 +- .../generated/parser/PublicationParser.cpp | 9 +- .../src/generated/parser/PublicationParser.h | 6 +- .../parser/PublishDataRequestParser.cpp | 10 +- .../parser/PublishDataRequestParser.h | 6 +- .../parser/PublishPartitionParser.cpp | 10 +- .../generated/parser/PublishPartitionParser.h | 6 +- .../parser/PublishPartitionsParser.cpp | 8 +- .../parser/PublishPartitionsParser.h | 6 +- .../src/generated/parser/ResponseOkParser.cpp | 15 +- .../src/generated/parser/ResponseOkParser.h | 8 +- .../parser/ResponseOkSingleParser.cpp | 8 +- .../generated/parser/ResponseOkSingleParser.h | 6 +- .../parser/VersionDependencyParser.cpp | 8 +- .../parser/VersionDependencyParser.h | 6 +- .../parser/VersionResponseParser.cpp | 8 +- .../generated/parser/VersionResponseParser.h | 6 +- .../generated/serializer/ApiSerializer.cpp | 20 +- .../src/generated/serializer/ApiSerializer.h | 7 +- .../serializer/CatalogSerializer.cpp | 179 ++++++++---------- .../generated/serializer/CatalogSerializer.h | 45 ++--- .../serializer/IndexInfoSerializer.cpp | 80 ++++---- .../serializer/IndexInfoSerializer.h | 8 +- .../src/generated/serializer/JsonSerializer.h | 23 +-- .../serializer/PublicationSerializer.cpp | 55 +++--- .../serializer/PublicationSerializer.h | 7 +- .../PublishDataRequestSerializer.cpp | 23 +-- .../serializer/PublishDataRequestSerializer.h | 7 +- .../serializer/PublishPartitionSerializer.cpp | 27 ++- .../serializer/PublishPartitionSerializer.h | 7 +- .../PublishPartitionsSerializer.cpp | 17 +- .../serializer/PublishPartitionsSerializer.h | 7 +- .../generated/serializer/SerializerWrapper.h | 102 ++++++++++ .../UpdateIndexRequestSerializer.cpp | 89 ++++----- .../serializer/UpdateIndexRequestSerializer.h | 7 +- .../src/utils/BoostJsonSrc.cpp | 20 ++ .../tests/ParserTest.cpp | 4 +- ...ionedLayerClientImplPublishToBatchTest.cpp | 4 +- .../tests/VersionedLayerClientImplTest.cpp | 4 +- ...VersionedLayerClientPublishToBatchTest.cpp | 4 +- .../VersionedLayerClientTest.cpp | 4 +- 56 files changed, 748 insertions(+), 478 deletions(-) create mode 100644 olp-cpp-sdk-dataservice-write/src/generated/parser/JsonParser.h create mode 100644 olp-cpp-sdk-dataservice-write/src/generated/parser/ParserWrapper.h create mode 100644 olp-cpp-sdk-dataservice-write/src/generated/serializer/SerializerWrapper.h create mode 100644 olp-cpp-sdk-dataservice-write/src/utils/BoostJsonSrc.cpp diff --git a/olp-cpp-sdk-dataservice-write/CMakeLists.txt b/olp-cpp-sdk-dataservice-write/CMakeLists.txt index 8678b7ecb..91f2a3d86 100644 --- a/olp-cpp-sdk-dataservice-write/CMakeLists.txt +++ b/olp-cpp-sdk-dataservice-write/CMakeLists.txt @@ -18,6 +18,8 @@ project(olp-cpp-sdk-dataservice-write VERSION 1.24.0) set(DESCRIPTION "C++ API library for writing data to OLP") +find_package(Boost REQUIRED) + set(OLP_SDK_DATASERVICE_WRITE_API_HEADERS ./include/olp/dataservice/write/DataServiceWriteApi.h ./include/olp/dataservice/write/IndexLayerClient.h @@ -159,16 +161,21 @@ set(OLP_SDK_DATASERVICE_WRITE_SOURCES ./src/generated/serializer/PublishPartitionsSerializer.h ./src/generated/serializer/UpdateIndexRequestSerializer.cpp ./src/generated/serializer/UpdateIndexRequestSerializer.h + + ./src/utils/BoostJsonSrc.cpp ) add_library(${PROJECT_NAME} ${OLP_SDK_DATASERVICE_WRITE_INCLUDES} ${OLP_SDK_DATASERVICE_WRITE_SOURCES}) -target_include_directories(${PROJECT_NAME} PUBLIC - $ - $ - PRIVATE $) +target_include_directories(${PROJECT_NAME} + PUBLIC + $ + $ + PRIVATE + $ + $) target_compile_definitions(${PROJECT_NAME} PRIVATE DATASERVICE_WRITE_LIBRARY) @@ -177,6 +184,11 @@ if(BUILD_SHARED_LIBS) PUBLIC DATASERVICE_WRITE_SHARED_LIBRARY) endif() +target_compile_definitions(${PROJECT_NAME} + PRIVATE + BOOST_ALL_NO_LIB + BOOST_JSON_NO_LIB) + # Used also in the package config file set(PROJECT_LIBS olp-cpp-sdk-core) diff --git a/olp-cpp-sdk-dataservice-write/src/CatalogSettings.cpp b/olp-cpp-sdk-dataservice-write/src/CatalogSettings.cpp index 5d3476263..43a225c88 100644 --- a/olp-cpp-sdk-dataservice-write/src/CatalogSettings.cpp +++ b/olp-cpp-sdk-dataservice-write/src/CatalogSettings.cpp @@ -1,5 +1,5 @@ /* - * Copyright (C) 2020 HERE Europe B.V. + * Copyright (C) 2020-2026 HERE Europe B.V. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -19,6 +19,8 @@ #include "CatalogSettings.h" +#include + #include #include #include @@ -29,7 +31,7 @@ #include #include #include -#include +#include // clang-format on namespace olp { diff --git a/olp-cpp-sdk-dataservice-write/src/JsonResultParser.h b/olp-cpp-sdk-dataservice-write/src/JsonResultParser.h index a5dea90f8..de069190c 100644 --- a/olp-cpp-sdk-dataservice-write/src/JsonResultParser.h +++ b/olp-cpp-sdk-dataservice-write/src/JsonResultParser.h @@ -1,5 +1,5 @@ /* - * Copyright (C) 2020 HERE Europe B.V. + * Copyright (C) 2020-2026 HERE Europe B.V. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -23,8 +23,8 @@ #include #include +#include #include -#include #include namespace olp { diff --git a/olp-cpp-sdk-dataservice-write/src/generated/parser/ApiParser.cpp b/olp-cpp-sdk-dataservice-write/src/generated/parser/ApiParser.cpp index 5f47acdad..a98304a8d 100644 --- a/olp-cpp-sdk-dataservice-write/src/generated/parser/ApiParser.cpp +++ b/olp-cpp-sdk-dataservice-write/src/generated/parser/ApiParser.cpp @@ -1,5 +1,5 @@ /* - * Copyright (C) 2019 HERE Europe B.V. + * Copyright (C) 2019-2026 HERE Europe B.V. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -19,11 +19,13 @@ #include "ApiParser.h" -#include +#include + +#include namespace olp { namespace parser { -void from_json(const rapidjson::Value& value, +void from_json(const boost::json::value& value, olp::dataservice::write::model::Api& x) { x.SetApi(parse(value, "api")); x.SetVersion(parse(value, "version")); diff --git a/olp-cpp-sdk-dataservice-write/src/generated/parser/ApiParser.h b/olp-cpp-sdk-dataservice-write/src/generated/parser/ApiParser.h index e3b949c79..eef0478a8 100644 --- a/olp-cpp-sdk-dataservice-write/src/generated/parser/ApiParser.h +++ b/olp-cpp-sdk-dataservice-write/src/generated/parser/ApiParser.h @@ -1,5 +1,5 @@ /* - * Copyright (C) 2019 HERE Europe B.V. + * Copyright (C) 2019-2026 HERE Europe B.V. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -19,14 +19,14 @@ #pragma once -#include +#include #include "generated/model/Api.h" #include namespace olp { namespace parser { -void from_json(const rapidjson::Value& value, +void from_json(const boost::json::value& value, olp::dataservice::write::model::Api& x); } // namespace parser diff --git a/olp-cpp-sdk-dataservice-write/src/generated/parser/CatalogParser.cpp b/olp-cpp-sdk-dataservice-write/src/generated/parser/CatalogParser.cpp index 8e019993b..1d6f7ba96 100644 --- a/olp-cpp-sdk-dataservice-write/src/generated/parser/CatalogParser.cpp +++ b/olp-cpp-sdk-dataservice-write/src/generated/parser/CatalogParser.cpp @@ -1,5 +1,5 @@ /* - * Copyright (C) 2019 HERE Europe B.V. + * Copyright (C) 2019-2026 HERE Europe B.V. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -19,48 +19,50 @@ #include "CatalogParser.h" -#include +#include + +#include namespace olp { namespace parser { -using namespace olp::dataservice::write; +namespace model = olp::dataservice::write::model; -void from_json(const rapidjson::Value& value, model::Coverage& x) { +void from_json(const boost::json::value& value, model::Coverage& x) { x.SetAdminAreas(parse >(value, "adminAreas")); } -void from_json(const rapidjson::Value& value, model::IndexDefinition& x) { +void from_json(const boost::json::value& value, model::IndexDefinition& x) { x.SetName(parse(value, "name")); x.SetType(parse(value, "type")); x.SetDuration(parse(value, "duration")); x.SetZoomLevel(parse(value, "zoomLevel")); } -void from_json(const rapidjson::Value& value, model::IndexProperties& x) { +void from_json(const boost::json::value& value, model::IndexProperties& x) { x.SetTtl(parse(value, "ttl")); x.SetIndexDefinitions( parse >(value, "indexDefinitions")); } -void from_json(const rapidjson::Value& value, model::Creator& x) { +void from_json(const boost::json::value& value, model::Creator& x) { x.SetId(parse(value, "id")); } -void from_json(const rapidjson::Value& value, model::Owner& x) { +void from_json(const boost::json::value& value, model::Owner& x) { x.SetCreator(parse(value, "creator")); x.SetOrganisation(parse(value, "organisation")); } -void from_json(const rapidjson::Value& value, model::Partitioning& x) { +void from_json(const boost::json::value& value, model::Partitioning& x) { x.SetScheme(parse(value, "scheme")); x.SetTileLevels(parse >(value, "tileLevels")); } -void from_json(const rapidjson::Value& value, model::Schema& x) { +void from_json(const boost::json::value& value, model::Schema& x) { x.SetHrn(parse(value, "hrn")); } -void from_json(const rapidjson::Value& value, model::StreamProperties& x) { +void from_json(const boost::json::value& value, model::StreamProperties& x) { // Parsing these as double even though OepnAPI sepcs says int64 because // Backend returns the value in decimal format (e.g. 1.0) and this triggers an // assert in RapidJSON when parsing. @@ -70,18 +72,18 @@ void from_json(const rapidjson::Value& value, model::StreamProperties& x) { static_cast(parse(value, "dataOutThroughputMbps"))); } -void from_json(const rapidjson::Value& value, model::Encryption& x) { +void from_json(const boost::json::value& value, model::Encryption& x) { x.SetAlgorithm(parse(value, "algorithm")); } -void from_json(const rapidjson::Value& value, model::Volume& x) { +void from_json(const boost::json::value& value, model::Volume& x) { x.SetVolumeType(parse(value, "volumeType")); x.SetMaxMemoryPolicy(parse(value, "maxMemoryPolicy")); x.SetPackageType(parse(value, "packageType")); x.SetEncryption(parse(value, "encryption")); } -void from_json(const rapidjson::Value& value, model::Layer& x) { +void from_json(const boost::json::value& value, model::Layer& x) { x.SetId(parse(value, "id")); x.SetName(parse(value, "name")); x.SetSummary(parse(value, "summary")); @@ -103,11 +105,11 @@ void from_json(const rapidjson::Value& value, model::Layer& x) { x.SetVolume(parse(value, "volume")); } -void from_json(const rapidjson::Value& value, model::Notifications& x) { +void from_json(const boost::json::value& value, model::Notifications& x) { x.SetEnabled(parse(value, "enabled")); } -void from_json(const rapidjson::Value& value, model::Catalog& x) { +void from_json(const boost::json::value& value, model::Catalog& x) { x.SetId(parse(value, "id")); x.SetHrn(parse(value, "hrn")); x.SetName(parse(value, "name")); diff --git a/olp-cpp-sdk-dataservice-write/src/generated/parser/CatalogParser.h b/olp-cpp-sdk-dataservice-write/src/generated/parser/CatalogParser.h index 5200ce64c..832e686cf 100644 --- a/olp-cpp-sdk-dataservice-write/src/generated/parser/CatalogParser.h +++ b/olp-cpp-sdk-dataservice-write/src/generated/parser/CatalogParser.h @@ -1,5 +1,5 @@ /* - * Copyright (C) 2019 HERE Europe B.V. + * Copyright (C) 2019-2026 HERE Europe B.V. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -21,49 +21,49 @@ #include -#include +#include #include namespace olp { namespace parser { -void from_json(const rapidjson::Value& value, +void from_json(const boost::json::value& value, olp::dataservice::write::model::Coverage& x); -void from_json(const rapidjson::Value& value, +void from_json(const boost::json::value& value, olp::dataservice::write::model::IndexDefinition& x); -void from_json(const rapidjson::Value& value, +void from_json(const boost::json::value& value, olp::dataservice::write::model::IndexProperties& x); -void from_json(const rapidjson::Value& value, +void from_json(const boost::json::value& value, olp::dataservice::write::model::Creator& x); -void from_json(const rapidjson::Value& value, +void from_json(const boost::json::value& value, olp::dataservice::write::model::Owner& x); -void from_json(const rapidjson::Value& value, +void from_json(const boost::json::value& value, olp::dataservice::write::model::Partitioning& x); -void from_json(const rapidjson::Value& value, +void from_json(const boost::json::value& value, olp::dataservice::write::model::Schema& x); -void from_json(const rapidjson::Value& value, +void from_json(const boost::json::value& value, olp::dataservice::write::model::StreamProperties& x); -void from_json(const rapidjson::Value& value, +void from_json(const boost::json::value& value, olp::dataservice::write::model::Encryption& x); -void from_json(const rapidjson::Value& value, +void from_json(const boost::json::value& value, olp::dataservice::write::model::Volume& x); -void from_json(const rapidjson::Value& value, +void from_json(const boost::json::value& value, olp::dataservice::write::model::Layer& x); -void from_json(const rapidjson::Value& value, +void from_json(const boost::json::value& value, olp::dataservice::write::model::Notifications& x); -void from_json(const rapidjson::Value& value, +void from_json(const boost::json::value& value, olp::dataservice::write::model::Catalog& x); } // namespace parser } // namespace olp diff --git a/olp-cpp-sdk-dataservice-write/src/generated/parser/DetailsParser.cpp b/olp-cpp-sdk-dataservice-write/src/generated/parser/DetailsParser.cpp index 25a613b02..275807cff 100644 --- a/olp-cpp-sdk-dataservice-write/src/generated/parser/DetailsParser.cpp +++ b/olp-cpp-sdk-dataservice-write/src/generated/parser/DetailsParser.cpp @@ -1,5 +1,5 @@ /* - * Copyright (C) 2019 HERE Europe B.V. + * Copyright (C) 2019-2026 HERE Europe B.V. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -19,11 +19,13 @@ #include "DetailsParser.h" -#include +#include + +#include namespace olp { namespace parser { -void from_json(const rapidjson::Value& value, +void from_json(const boost::json::value& value, olp::dataservice::write::model::Details& x) { x.SetState(parse(value, "state")); x.SetMessage(parse(value, "message")); diff --git a/olp-cpp-sdk-dataservice-write/src/generated/parser/DetailsParser.h b/olp-cpp-sdk-dataservice-write/src/generated/parser/DetailsParser.h index f61d37a2f..c1dfb3108 100644 --- a/olp-cpp-sdk-dataservice-write/src/generated/parser/DetailsParser.h +++ b/olp-cpp-sdk-dataservice-write/src/generated/parser/DetailsParser.h @@ -1,5 +1,5 @@ /* - * Copyright (C) 2019 HERE Europe B.V. + * Copyright (C) 2019-2026 HERE Europe B.V. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -19,13 +19,13 @@ #pragma once -#include +#include #include namespace olp { namespace parser { -void from_json(const rapidjson::Value& value, +void from_json(const boost::json::value& value, dataservice::write::model::Details& x); } // namespace parser } // namespace olp diff --git a/olp-cpp-sdk-dataservice-write/src/generated/parser/JsonParser.h b/olp-cpp-sdk-dataservice-write/src/generated/parser/JsonParser.h new file mode 100644 index 000000000..48f30401e --- /dev/null +++ b/olp-cpp-sdk-dataservice-write/src/generated/parser/JsonParser.h @@ -0,0 +1,78 @@ +/* + * Copyright (C) 2019-2026 HERE Europe B.V. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * SPDX-License-Identifier: Apache-2.0 + * License-Filename: LICENSE + */ + +#pragma once + +#include +#include +#include +#include + +#include + +#include "ParserWrapper.h" + +namespace olp { +namespace parser { + +template +inline T parse(const std::string& json) { + boost::json::error_code ec; + auto value = boost::json::parse(json, ec); + T result{}; + if (value.is_object() || value.is_array()) { + from_json(value, result); + } + return result; +} + +template +inline T parse(std::stringstream& json_stream, bool& res) { + res = false; + boost::json::error_code ec; + auto value = boost::json::parse(json_stream, ec); + T result{}; + if (value.is_object() || value.is_array()) { + from_json(value, result); + res = true; + } + return result; +} + +template +inline T parse(std::stringstream& json_stream) { + bool res = true; + return parse(json_stream, res); +} + +template +inline T parse(const std::shared_ptr>& json_bytes) { + boost::json::string_view json(reinterpret_cast(json_bytes->data()), + json_bytes->size()); + boost::json::error_code ec; + auto value = boost::json::parse(json, ec); + T result{}; + if (value.is_object() || value.is_array()) { + from_json(value, result); + } + return result; +} + +} // namespace parser +} // namespace olp diff --git a/olp-cpp-sdk-dataservice-write/src/generated/parser/LayerVersionsParser.cpp b/olp-cpp-sdk-dataservice-write/src/generated/parser/LayerVersionsParser.cpp index 424bdcd6f..845e797b4 100644 --- a/olp-cpp-sdk-dataservice-write/src/generated/parser/LayerVersionsParser.cpp +++ b/olp-cpp-sdk-dataservice-write/src/generated/parser/LayerVersionsParser.cpp @@ -1,5 +1,5 @@ /* - * Copyright (C) 2019 HERE Europe B.V. + * Copyright (C) 2019-2026 HERE Europe B.V. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -19,19 +19,21 @@ #include "LayerVersionsParser.h" -#include +#include + +#include namespace olp { namespace parser { -using namespace olp::dataservice::write; +namespace model = olp::dataservice::write::model; -void from_json(const rapidjson::Value& value, model::LayerVersion& x) { +void from_json(const boost::json::value& value, model::LayerVersion& x) { x.SetLayer(parse(value, "layer")); x.SetVersion(parse(value, "version")); x.SetTimestamp(parse(value, "timestamp")); } -void from_json(const rapidjson::Value& value, model::LayerVersions& x) { +void from_json(const boost::json::value& value, model::LayerVersions& x) { x.SetLayerVersions( parse>(value, "layerVersions")); x.SetVersion(parse(value, "version")); diff --git a/olp-cpp-sdk-dataservice-write/src/generated/parser/LayerVersionsParser.h b/olp-cpp-sdk-dataservice-write/src/generated/parser/LayerVersionsParser.h index b3fd60089..ccda3b492 100644 --- a/olp-cpp-sdk-dataservice-write/src/generated/parser/LayerVersionsParser.h +++ b/olp-cpp-sdk-dataservice-write/src/generated/parser/LayerVersionsParser.h @@ -1,5 +1,5 @@ /* - * Copyright (C) 2019 HERE Europe B.V. + * Copyright (C) 2019-2026 HERE Europe B.V. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -19,17 +19,17 @@ #pragma once -#include +#include #include "generated/model/LayerVersions.h" #include namespace olp { namespace parser { -void from_json(const rapidjson::Value& value, +void from_json(const boost::json::value& value, olp::dataservice::write::model::LayerVersion& x); -void from_json(const rapidjson::Value& value, +void from_json(const boost::json::value& value, olp::dataservice::write::model::LayerVersions& x); } // namespace parser diff --git a/olp-cpp-sdk-dataservice-write/src/generated/parser/ParserWrapper.h b/olp-cpp-sdk-dataservice-write/src/generated/parser/ParserWrapper.h new file mode 100644 index 000000000..284238474 --- /dev/null +++ b/olp-cpp-sdk-dataservice-write/src/generated/parser/ParserWrapper.h @@ -0,0 +1,102 @@ +/* + * Copyright (C) 2019-2026 HERE Europe B.V. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * SPDX-License-Identifier: Apache-2.0 + * License-Filename: LICENSE + */ + +#pragma once + +#include +#include +#include +#include +#include + +#include +#include + +namespace olp { +namespace parser { + +inline void from_json(const boost::json::value& value, std::string& x) { + const auto& str = value.get_string(); + x.assign(str.begin(), str.end()); +} + +inline void from_json(const boost::json::value& value, int32_t& x) { + x = static_cast(value.to_number()); +} + +inline void from_json(const boost::json::value& value, int64_t& x) { + x = value.to_number(); +} + +inline void from_json(const boost::json::value& value, double& x) { + x = value.to_number(); +} + +inline void from_json(const boost::json::value& value, bool& x) { + x = value.get_bool(); +} + +inline void from_json(const boost::json::value& value, + std::shared_ptr>& x) { + const auto& s = value.get_string(); + x = std::make_shared>(s.begin(), s.end()); +} + +template +inline void from_json(const boost::json::value& value, + porting::optional& x) { + T result = T(); + from_json(value, result); + x = result; +} + +template +inline void from_json(const boost::json::value& value, + std::map& results) { + const auto& object = value.get_object(); + for (const auto& object_value : object) { + std::string key = object_value.key(); + from_json(object_value.value(), results[key]); + } +} + +template +inline void from_json(const boost::json::value& value, + std::vector& results) { + const auto& array = value.get_array(); + for (const auto& array_value : array) { + T result; + from_json(array_value, result); + results.emplace_back(std::move(result)); + } +} + +template +inline T parse(const boost::json::value& value, const std::string& name) { + T result = T(); + const auto& object = value.get_object(); + auto itr = object.find(name); + if (itr != object.end()) { + from_json(itr->value(), result); + } + return result; +} + +} // namespace parser +} // namespace olp diff --git a/olp-cpp-sdk-dataservice-write/src/generated/parser/PartitionParser.h b/olp-cpp-sdk-dataservice-write/src/generated/parser/PartitionParser.h index b087c6094..25f6d22dc 100644 --- a/olp-cpp-sdk-dataservice-write/src/generated/parser/PartitionParser.h +++ b/olp-cpp-sdk-dataservice-write/src/generated/parser/PartitionParser.h @@ -1,5 +1,5 @@ /* - * Copyright (C) 2019 HERE Europe B.V. + * Copyright (C) 2019-2026 HERE Europe B.V. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -19,17 +19,17 @@ #pragma once -#include +#include #include "olp/dataservice/write/model/Partitions.h" #include namespace olp { namespace parser { -void from_json(const rapidjson::Value& value, +void from_json(const boost::json::value& value, olp::dataservice::write::model::Partition& x); -void from_json(const rapidjson::Value& value, +void from_json(const boost::json::value& value, olp::dataservice::write::model::Partitions& x); } // namespace parser diff --git a/olp-cpp-sdk-dataservice-write/src/generated/parser/PartitionsParser.cpp b/olp-cpp-sdk-dataservice-write/src/generated/parser/PartitionsParser.cpp index 8e3420373..15f6bacb3 100644 --- a/olp-cpp-sdk-dataservice-write/src/generated/parser/PartitionsParser.cpp +++ b/olp-cpp-sdk-dataservice-write/src/generated/parser/PartitionsParser.cpp @@ -1,5 +1,5 @@ /* - * Copyright (C) 2019 HERE Europe B.V. + * Copyright (C) 2019-2026 HERE Europe B.V. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -19,13 +19,15 @@ #include "PartitionsParser.h" -#include +#include + +#include namespace olp { namespace parser { -namespace model = dataservice::write::model; +namespace model = olp::dataservice::write::model; -void from_json(const rapidjson::Value& value, model::Partition& x) { +void from_json(const boost::json::value& value, model::Partition& x) { x.SetChecksum(parse>(value, "checksum")); x.SetCompressedDataSize( parse>(value, "compressedDataSize")); @@ -35,7 +37,7 @@ void from_json(const rapidjson::Value& value, model::Partition& x) { x.SetVersion(parse>(value, "version")); } -void from_json(const rapidjson::Value& value, model::Partitions& x) { +void from_json(const boost::json::value& value, model::Partitions& x) { x.SetPartitions(parse>(value, "partitions")); } diff --git a/olp-cpp-sdk-dataservice-write/src/generated/parser/PartitionsParser.h b/olp-cpp-sdk-dataservice-write/src/generated/parser/PartitionsParser.h index 9f45ba291..04db33058 100644 --- a/olp-cpp-sdk-dataservice-write/src/generated/parser/PartitionsParser.h +++ b/olp-cpp-sdk-dataservice-write/src/generated/parser/PartitionsParser.h @@ -1,5 +1,5 @@ /* - * Copyright (C) 2019 HERE Europe B.V. + * Copyright (C) 2019-2026 HERE Europe B.V. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -19,17 +19,17 @@ #pragma once -#include +#include #include "generated/model/Partitions.h" #include namespace olp { namespace parser { -void from_json(const rapidjson::Value& value, +void from_json(const boost::json::value& value, olp::dataservice::write::model::Partition& x); -void from_json(const rapidjson::Value& value, +void from_json(const boost::json::value& value, olp::dataservice::write::model::Partitions& x); } // namespace parser diff --git a/olp-cpp-sdk-dataservice-write/src/generated/parser/PublicationParser.cpp b/olp-cpp-sdk-dataservice-write/src/generated/parser/PublicationParser.cpp index 2eff59a0d..0acb2c867 100644 --- a/olp-cpp-sdk-dataservice-write/src/generated/parser/PublicationParser.cpp +++ b/olp-cpp-sdk-dataservice-write/src/generated/parser/PublicationParser.cpp @@ -1,5 +1,5 @@ /* - * Copyright (C) 2019 HERE Europe B.V. + * Copyright (C) 2019-2026 HERE Europe B.V. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -19,15 +19,18 @@ #include "PublicationParser.h" +#include +#include + // clang-format off #include #include -#include +#include // clang-format on namespace olp { namespace parser { -void from_json(const rapidjson::Value& value, +void from_json(const boost::json::value& value, olp::dataservice::write::model::Publication& x) { x.SetId(parse(value, "id")); x.SetDetails( diff --git a/olp-cpp-sdk-dataservice-write/src/generated/parser/PublicationParser.h b/olp-cpp-sdk-dataservice-write/src/generated/parser/PublicationParser.h index eb2f67a69..1edeaa216 100644 --- a/olp-cpp-sdk-dataservice-write/src/generated/parser/PublicationParser.h +++ b/olp-cpp-sdk-dataservice-write/src/generated/parser/PublicationParser.h @@ -1,5 +1,5 @@ /* - * Copyright (C) 2019 HERE Europe B.V. + * Copyright (C) 2019-2026 HERE Europe B.V. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -19,13 +19,13 @@ #pragma once -#include +#include #include namespace olp { namespace parser { -void from_json(const rapidjson::Value& value, +void from_json(const boost::json::value& value, dataservice::write::model::Publication& x); } // namespace parser } // namespace olp diff --git a/olp-cpp-sdk-dataservice-write/src/generated/parser/PublishDataRequestParser.cpp b/olp-cpp-sdk-dataservice-write/src/generated/parser/PublishDataRequestParser.cpp index 45f514774..7f217012a 100644 --- a/olp-cpp-sdk-dataservice-write/src/generated/parser/PublishDataRequestParser.cpp +++ b/olp-cpp-sdk-dataservice-write/src/generated/parser/PublishDataRequestParser.cpp @@ -1,5 +1,5 @@ /* - * Copyright (C) 2019 HERE Europe B.V. + * Copyright (C) 2019-2026 HERE Europe B.V. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -19,13 +19,17 @@ #include "PublishDataRequestParser.h" +#include +#include +#include + // clang-format off -#include +#include // clang-format on namespace olp { namespace parser { -void from_json(const rapidjson::Value& value, +void from_json(const boost::json::value& value, olp::dataservice::write::model::PublishDataRequest& x) { x.WithData( (parse>>(value, "data"))); diff --git a/olp-cpp-sdk-dataservice-write/src/generated/parser/PublishDataRequestParser.h b/olp-cpp-sdk-dataservice-write/src/generated/parser/PublishDataRequestParser.h index 7dd60e032..abf7e89d9 100644 --- a/olp-cpp-sdk-dataservice-write/src/generated/parser/PublishDataRequestParser.h +++ b/olp-cpp-sdk-dataservice-write/src/generated/parser/PublishDataRequestParser.h @@ -1,5 +1,5 @@ /* - * Copyright (C) 2019 HERE Europe B.V. + * Copyright (C) 2019-2026 HERE Europe B.V. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -19,13 +19,13 @@ #pragma once -#include +#include #include namespace olp { namespace parser { -void from_json(const rapidjson::Value& value, +void from_json(const boost::json::value& value, dataservice::write::model::PublishDataRequest& x); } // namespace parser } // namespace olp diff --git a/olp-cpp-sdk-dataservice-write/src/generated/parser/PublishPartitionParser.cpp b/olp-cpp-sdk-dataservice-write/src/generated/parser/PublishPartitionParser.cpp index 4e4b620af..ec8d6a75d 100644 --- a/olp-cpp-sdk-dataservice-write/src/generated/parser/PublishPartitionParser.cpp +++ b/olp-cpp-sdk-dataservice-write/src/generated/parser/PublishPartitionParser.cpp @@ -1,5 +1,5 @@ /* - * Copyright (C) 2019 HERE Europe B.V. + * Copyright (C) 2019-2026 HERE Europe B.V. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -19,11 +19,15 @@ #include "PublishPartitionParser.h" -#include +#include +#include +#include + +#include "generated/parser/ParserWrapper.h" namespace olp { namespace parser { -void from_json(const rapidjson::Value& value, +void from_json(const boost::json::value& value, olp::dataservice::write::model::PublishPartition& x) { x.SetPartition(parse(value, "partition")); x.SetChecksum(parse(value, "checksum")); diff --git a/olp-cpp-sdk-dataservice-write/src/generated/parser/PublishPartitionParser.h b/olp-cpp-sdk-dataservice-write/src/generated/parser/PublishPartitionParser.h index 80ad26a18..b0b6e469b 100644 --- a/olp-cpp-sdk-dataservice-write/src/generated/parser/PublishPartitionParser.h +++ b/olp-cpp-sdk-dataservice-write/src/generated/parser/PublishPartitionParser.h @@ -1,5 +1,5 @@ /* - * Copyright (C) 2019 HERE Europe B.V. + * Copyright (C) 2019-2026 HERE Europe B.V. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -19,13 +19,13 @@ #pragma once -#include +#include #include "generated/model/PublishPartition.h" namespace olp { namespace parser { -void from_json(const rapidjson::Value& value, +void from_json(const boost::json::value& value, dataservice::write::model::PublishPartition& x); } // namespace parser } // namespace olp diff --git a/olp-cpp-sdk-dataservice-write/src/generated/parser/PublishPartitionsParser.cpp b/olp-cpp-sdk-dataservice-write/src/generated/parser/PublishPartitionsParser.cpp index 77fa92dcd..37392cf15 100644 --- a/olp-cpp-sdk-dataservice-write/src/generated/parser/PublishPartitionsParser.cpp +++ b/olp-cpp-sdk-dataservice-write/src/generated/parser/PublishPartitionsParser.cpp @@ -1,5 +1,5 @@ /* - * Copyright (C) 2019 HERE Europe B.V. + * Copyright (C) 2019-2026 HERE Europe B.V. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -19,14 +19,16 @@ #include "PublishPartitionsParser.h" +#include + // clang-format off #include -#include +#include // clang-format on namespace olp { namespace parser { -void from_json(const rapidjson::Value& value, +void from_json(const boost::json::value& value, olp::dataservice::write::model::PublishPartitions& x) { x.SetPartitions( parse>( diff --git a/olp-cpp-sdk-dataservice-write/src/generated/parser/PublishPartitionsParser.h b/olp-cpp-sdk-dataservice-write/src/generated/parser/PublishPartitionsParser.h index c7b02a402..abc403199 100644 --- a/olp-cpp-sdk-dataservice-write/src/generated/parser/PublishPartitionsParser.h +++ b/olp-cpp-sdk-dataservice-write/src/generated/parser/PublishPartitionsParser.h @@ -1,5 +1,5 @@ /* - * Copyright (C) 2019 HERE Europe B.V. + * Copyright (C) 2019-2026 HERE Europe B.V. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -19,13 +19,13 @@ #pragma once -#include +#include #include "generated/model/PublishPartitions.h" namespace olp { namespace parser { -void from_json(const rapidjson::Value& value, +void from_json(const boost::json::value& value, dataservice::write::model::PublishPartitions& x); } // namespace parser } // namespace olp diff --git a/olp-cpp-sdk-dataservice-write/src/generated/parser/ResponseOkParser.cpp b/olp-cpp-sdk-dataservice-write/src/generated/parser/ResponseOkParser.cpp index 77a770f1e..c8b4153fc 100644 --- a/olp-cpp-sdk-dataservice-write/src/generated/parser/ResponseOkParser.cpp +++ b/olp-cpp-sdk-dataservice-write/src/generated/parser/ResponseOkParser.cpp @@ -1,5 +1,5 @@ /* - * Copyright (C) 2019 HERE Europe B.V. + * Copyright (C) 2019-2026 HERE Europe B.V. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -19,19 +19,22 @@ #include "ResponseOkParser.h" -#include +#include +#include -using namespace olp::dataservice::write::model; +#include + +namespace model = olp::dataservice::write::model; namespace olp { namespace parser { -void from_json(const rapidjson::Value& value, TraceID& x) { +void from_json(const boost::json::value& value, model::TraceID& x) { x.SetParentID(parse(value, "ParentID")); x.SetGeneratedIDs(parse >(value, "GeneratedIDs")); } -void from_json(const rapidjson::Value& value, ResponseOk& x) { - x.SetTraceID(parse(value, "TraceID")); +void from_json(const boost::json::value& value, model::ResponseOk& x) { + x.SetTraceID(parse(value, "TraceID")); } } // namespace parser diff --git a/olp-cpp-sdk-dataservice-write/src/generated/parser/ResponseOkParser.h b/olp-cpp-sdk-dataservice-write/src/generated/parser/ResponseOkParser.h index f545cd854..f4b752aac 100644 --- a/olp-cpp-sdk-dataservice-write/src/generated/parser/ResponseOkParser.h +++ b/olp-cpp-sdk-dataservice-write/src/generated/parser/ResponseOkParser.h @@ -1,5 +1,5 @@ /* - * Copyright (C) 2019 HERE Europe B.V. + * Copyright (C) 2019-2026 HERE Europe B.V. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -19,16 +19,16 @@ #pragma once -#include +#include #include namespace olp { namespace parser { -void from_json(const rapidjson::Value& value, +void from_json(const boost::json::value& value, dataservice::write::model::TraceID& x); -void from_json(const rapidjson::Value& value, +void from_json(const boost::json::value& value, dataservice::write::model::ResponseOk& x); } // namespace parser diff --git a/olp-cpp-sdk-dataservice-write/src/generated/parser/ResponseOkSingleParser.cpp b/olp-cpp-sdk-dataservice-write/src/generated/parser/ResponseOkSingleParser.cpp index 3ee2b9a09..172488c3d 100644 --- a/olp-cpp-sdk-dataservice-write/src/generated/parser/ResponseOkSingleParser.cpp +++ b/olp-cpp-sdk-dataservice-write/src/generated/parser/ResponseOkSingleParser.cpp @@ -1,5 +1,5 @@ /* - * Copyright (C) 2019 HERE Europe B.V. + * Copyright (C) 2019-2026 HERE Europe B.V. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -19,11 +19,13 @@ #include "ResponseOkSingleParser.h" -#include +#include + +#include namespace olp { namespace parser { -void from_json(const rapidjson::Value& value, +void from_json(const boost::json::value& value, dataservice::write::model::ResponseOkSingle& x) { x.SetTraceID(parse(value, "TraceID")); } diff --git a/olp-cpp-sdk-dataservice-write/src/generated/parser/ResponseOkSingleParser.h b/olp-cpp-sdk-dataservice-write/src/generated/parser/ResponseOkSingleParser.h index 96b463708..1b14212d3 100644 --- a/olp-cpp-sdk-dataservice-write/src/generated/parser/ResponseOkSingleParser.h +++ b/olp-cpp-sdk-dataservice-write/src/generated/parser/ResponseOkSingleParser.h @@ -1,5 +1,5 @@ /* - * Copyright (C) 2019 HERE Europe B.V. + * Copyright (C) 2019-2026 HERE Europe B.V. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -19,13 +19,13 @@ #pragma once -#include +#include #include namespace olp { namespace parser { -void from_json(const rapidjson::Value& value, +void from_json(const boost::json::value& value, dataservice::write::model::ResponseOkSingle& x); } // namespace parser diff --git a/olp-cpp-sdk-dataservice-write/src/generated/parser/VersionDependencyParser.cpp b/olp-cpp-sdk-dataservice-write/src/generated/parser/VersionDependencyParser.cpp index c5992657f..0a830bb66 100644 --- a/olp-cpp-sdk-dataservice-write/src/generated/parser/VersionDependencyParser.cpp +++ b/olp-cpp-sdk-dataservice-write/src/generated/parser/VersionDependencyParser.cpp @@ -1,5 +1,5 @@ /* - * Copyright (C) 2019 HERE Europe B.V. + * Copyright (C) 2019-2026 HERE Europe B.V. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -19,11 +19,13 @@ #include "VersionDependencyParser.h" -#include +#include + +#include namespace olp { namespace parser { -void from_json(const rapidjson::Value& value, +void from_json(const boost::json::value& value, olp::dataservice::write::model::VersionDependency& x) { x.SetDirect(parse(value, "direct")); x.SetHrn(parse(value, "hrn")); diff --git a/olp-cpp-sdk-dataservice-write/src/generated/parser/VersionDependencyParser.h b/olp-cpp-sdk-dataservice-write/src/generated/parser/VersionDependencyParser.h index 7a69b4105..c7d606823 100644 --- a/olp-cpp-sdk-dataservice-write/src/generated/parser/VersionDependencyParser.h +++ b/olp-cpp-sdk-dataservice-write/src/generated/parser/VersionDependencyParser.h @@ -1,5 +1,5 @@ /* - * Copyright (C) 2019 HERE Europe B.V. + * Copyright (C) 2019-2026 HERE Europe B.V. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -19,13 +19,13 @@ #pragma once -#include +#include #include namespace olp { namespace parser { -void from_json(const rapidjson::Value& value, +void from_json(const boost::json::value& value, dataservice::write::model::VersionDependency& x); } // namespace parser } // namespace olp diff --git a/olp-cpp-sdk-dataservice-write/src/generated/parser/VersionResponseParser.cpp b/olp-cpp-sdk-dataservice-write/src/generated/parser/VersionResponseParser.cpp index 723463a62..233233139 100644 --- a/olp-cpp-sdk-dataservice-write/src/generated/parser/VersionResponseParser.cpp +++ b/olp-cpp-sdk-dataservice-write/src/generated/parser/VersionResponseParser.cpp @@ -1,5 +1,5 @@ /* - * Copyright (C) 2019 HERE Europe B.V. + * Copyright (C) 2019-2026 HERE Europe B.V. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -19,13 +19,13 @@ #include "VersionResponseParser.h" -#include +#include namespace olp { namespace parser { -using namespace olp::dataservice::write; +namespace model = olp::dataservice::write::model; -void from_json(const rapidjson::Value& value, model::VersionResponse& x) { +void from_json(const boost::json::value& value, model::VersionResponse& x) { x.SetVersion(parse(value, "version")); } diff --git a/olp-cpp-sdk-dataservice-write/src/generated/parser/VersionResponseParser.h b/olp-cpp-sdk-dataservice-write/src/generated/parser/VersionResponseParser.h index f24794631..6d26573bc 100644 --- a/olp-cpp-sdk-dataservice-write/src/generated/parser/VersionResponseParser.h +++ b/olp-cpp-sdk-dataservice-write/src/generated/parser/VersionResponseParser.h @@ -1,5 +1,5 @@ /* - * Copyright (C) 2019 HERE Europe B.V. + * Copyright (C) 2019-2026 HERE Europe B.V. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -19,14 +19,14 @@ #pragma once -#include +#include #include "olp/dataservice/write/model/VersionResponse.h" #include namespace olp { namespace parser { -void from_json(const rapidjson::Value& value, +void from_json(const boost::json::value& value, olp::dataservice::write::model::VersionResponse& x); } // namespace parser diff --git a/olp-cpp-sdk-dataservice-write/src/generated/serializer/ApiSerializer.cpp b/olp-cpp-sdk-dataservice-write/src/generated/serializer/ApiSerializer.cpp index 3e14d9a14..67bdb0c75 100644 --- a/olp-cpp-sdk-dataservice-write/src/generated/serializer/ApiSerializer.cpp +++ b/olp-cpp-sdk-dataservice-write/src/generated/serializer/ApiSerializer.cpp @@ -1,5 +1,5 @@ /* - * Copyright (C) 2020 HERE Europe B.V. + * Copyright (C) 2020-2026 HERE Europe B.V. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -17,21 +17,21 @@ * License-Filename: LICENSE */ -#include +#include #include "ApiSerializer.h" -#include +#include namespace olp { namespace serializer { -void to_json(const dataservice::write::model::Api& x, rapidjson::Value& value, - rapidjson::Document::AllocatorType& allocator) { - value.SetObject(); - serialize("api", x.GetApi(), value, allocator); - serialize("version", x.GetVersion(), value, allocator); - serialize("baseURL", x.GetBaseUrl(), value, allocator); - serialize("parameters", x.GetParameters(), value, allocator); +void to_json(const dataservice::write::model::Api& x, + boost::json::value& value) { + auto& object = value.emplace_object(); + serialize("api", x.GetApi(), object); + serialize("version", x.GetVersion(), object); + serialize("baseURL", x.GetBaseUrl(), object); + serialize("parameters", x.GetParameters(), object); } } // namespace serializer } // namespace olp diff --git a/olp-cpp-sdk-dataservice-write/src/generated/serializer/ApiSerializer.h b/olp-cpp-sdk-dataservice-write/src/generated/serializer/ApiSerializer.h index 57ad803f3..a36962d04 100644 --- a/olp-cpp-sdk-dataservice-write/src/generated/serializer/ApiSerializer.h +++ b/olp-cpp-sdk-dataservice-write/src/generated/serializer/ApiSerializer.h @@ -1,5 +1,5 @@ /* - * Copyright (C) 2020 HERE Europe B.V. + * Copyright (C) 2020-2026 HERE Europe B.V. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -21,14 +21,13 @@ #include -#include +#include #include "generated/model/Api.h" namespace olp { namespace serializer { void to_json(const dataservice::write::model::Api& x, - rapidjson::Value& value, - rapidjson::Document::AllocatorType& allocator); + boost::json::value& value); } // namespace serializer } // namespace olp diff --git a/olp-cpp-sdk-dataservice-write/src/generated/serializer/CatalogSerializer.cpp b/olp-cpp-sdk-dataservice-write/src/generated/serializer/CatalogSerializer.cpp index ed6cf3643..1dd1ff303 100644 --- a/olp-cpp-sdk-dataservice-write/src/generated/serializer/CatalogSerializer.cpp +++ b/olp-cpp-sdk-dataservice-write/src/generated/serializer/CatalogSerializer.cpp @@ -1,5 +1,5 @@ /* - * Copyright (C) 2019-2021 HERE Europe B.V. + * Copyright (C) 2019-2026 HERE Europe B.V. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -17,142 +17,129 @@ * License-Filename: LICENSE */ -#include +#include #include "CatalogSerializer.h" -#include +#include namespace olp { namespace serializer { void to_json(const dataservice::write::model::Coverage& x, - rapidjson::Value& value, - rapidjson::Document::AllocatorType& allocator) { - value.SetObject(); - serialize("adminAreas", x.GetAdminAreas(), value, allocator); + boost::json::value& value) { + auto& object = value.emplace_object(); + serialize("adminAreas", x.GetAdminAreas(), object); } void to_json(const dataservice::write::model::IndexDefinition& x, - rapidjson::Value& value, - rapidjson::Document::AllocatorType& allocator) { - value.SetObject(); - serialize("name", x.GetName(), value, allocator); - serialize("type", x.GetType(), value, allocator); - serialize("duration", x.GetDuration(), value, allocator); - serialize("zoomLevel", x.GetZoomLevel(), value, allocator); + boost::json::value& value) { + auto& object = value.emplace_object(); + serialize("name", x.GetName(), object); + serialize("type", x.GetType(), object); + serialize("duration", x.GetDuration(), object); + serialize("zoomLevel", x.GetZoomLevel(), object); } void to_json(const dataservice::write::model::IndexProperties& x, - rapidjson::Value& value, - rapidjson::Document::AllocatorType& allocator) { - value.SetObject(); - serialize("ttl", x.GetTtl(), value, allocator); - serialize("indexDefinitions", x.GetIndexDefinitions(), value, allocator); + boost::json::value& value) { + auto& object = value.emplace_object(); + serialize("ttl", x.GetTtl(), object); + serialize("indexDefinitions", x.GetIndexDefinitions(), object); } void to_json(const dataservice::write::model::Creator& x, - rapidjson::Value& value, - rapidjson::Document::AllocatorType& allocator) { - value.SetObject(); - serialize("id", x.GetId(), value, allocator); + boost::json::value& value) { + auto& object = value.emplace_object(); + serialize("id", x.GetId(), object); } -void to_json(const dataservice::write::model::Owner& x, rapidjson::Value& value, - rapidjson::Document::AllocatorType& allocator) { - value.SetObject(); - serialize("creator", x.GetCreator(), value, allocator); - serialize("organisation", x.GetOrganisation(), value, allocator); +void to_json(const dataservice::write::model::Owner& x, + boost::json::value& value) { + auto& object = value.emplace_object(); + serialize("creator", x.GetCreator(), object); + serialize("organisation", x.GetOrganisation(), object); } void to_json(const dataservice::write::model::Partitioning& x, - rapidjson::Value& value, - rapidjson::Document::AllocatorType& allocator) { - value.SetObject(); - serialize("scheme", x.GetScheme(), value, allocator); - serialize("tileLevels", x.GetTileLevels(), value, allocator); + boost::json::value& value) { + auto& object = value.emplace_object(); + serialize("scheme", x.GetScheme(), object); + serialize("tileLevels", x.GetTileLevels(), object); } void to_json(const dataservice::write::model::Schema& x, - rapidjson::Value& value, - rapidjson::Document::AllocatorType& allocator) { - value.SetObject(); - serialize("hrn", x.GetHrn(), value, allocator); + boost::json::value& value) { + auto& object = value.emplace_object(); + serialize("hrn", x.GetHrn(), object); } void to_json(const dataservice::write::model::StreamProperties& x, - rapidjson::Value& value, - rapidjson::Document::AllocatorType& allocator) { - value.SetObject(); - serialize("dataInThroughputMbps", x.GetDataInThroughputMbps(), value, - allocator); - serialize("dataOutThroughputMbps", x.GetDataOutThroughputMbps(), value, - allocator); + boost::json::value& value) { + auto& object = value.emplace_object(); + serialize("dataInThroughputMbps", x.GetDataInThroughputMbps(), object); + serialize("dataOutThroughputMbps", x.GetDataOutThroughputMbps(), object); } void to_json(const dataservice::write::model::Encryption& x, - rapidjson::Value& value, - rapidjson::Document::AllocatorType& allocator) { - value.SetObject(); - serialize("algorithm", x.GetAlgorithm(), value, allocator); + boost::json::value& value) { + auto& object = value.emplace_object(); + serialize("algorithm", x.GetAlgorithm(), object); } void to_json(const dataservice::write::model::Volume& x, - rapidjson::Value& value, - rapidjson::Document::AllocatorType& allocator) { - value.SetObject(); - serialize("volumeType", x.GetVolumeType(), value, allocator); - serialize("maxMemoryPolicy", x.GetMaxMemoryPolicy(), value, allocator); - serialize("packageType", x.GetPackageType(), value, allocator); - serialize("encryption", x.GetEncryption(), value, allocator); + boost::json::value& value) { + auto& object = value.emplace_object(); + serialize("volumeType", x.GetVolumeType(), object); + serialize("maxMemoryPolicy", x.GetMaxMemoryPolicy(), object); + serialize("packageType", x.GetPackageType(), object); + serialize("encryption", x.GetEncryption(), object); } -void to_json(const dataservice::write::model::Layer& x, rapidjson::Value& value, - rapidjson::Document::AllocatorType& allocator) { - value.SetObject(); - serialize("id", x.GetId(), value, allocator); - serialize("name", x.GetName(), value, allocator); - serialize("summary", x.GetSummary(), value, allocator); - serialize("description", x.GetDescription(), value, allocator); - serialize("owner", x.GetOwner(), value, allocator); - serialize("coverage", x.GetCoverage(), value, allocator); - serialize("schema", x.GetSchema(), value, allocator); - serialize("contentType", x.GetContentType(), value, allocator); - serialize("contentEncoding", x.GetContentEncoding(), value, allocator); - serialize("partitioning", x.GetPartitioning(), value, allocator); - serialize("layerType", x.GetLayerType(), value, allocator); - serialize("digest", x.GetDigest(), value, allocator); - serialize("tags", x.GetTags(), value, allocator); - serialize("billingTags", x.GetBillingTags(), value, allocator); - serialize("ttl", x.GetTtl(), value, allocator); - serialize("indexProperties", x.GetIndexProperties(), value, allocator); - serialize("streamProperties", x.GetStreamProperties(), value, allocator); - serialize("volume", x.GetVolume(), value, allocator); +void to_json(const dataservice::write::model::Layer& x, + boost::json::value& value) { + auto& object = value.emplace_object(); + serialize("id", x.GetId(), object); + serialize("name", x.GetName(), object); + serialize("summary", x.GetSummary(), object); + serialize("description", x.GetDescription(), object); + serialize("owner", x.GetOwner(), object); + serialize("coverage", x.GetCoverage(), object); + serialize("schema", x.GetSchema(), object); + serialize("contentType", x.GetContentType(), object); + serialize("contentEncoding", x.GetContentEncoding(), object); + serialize("partitioning", x.GetPartitioning(), object); + serialize("layerType", x.GetLayerType(), object); + serialize("digest", x.GetDigest(), object); + serialize("tags", x.GetTags(), object); + serialize("billingTags", x.GetBillingTags(), object); + serialize("ttl", x.GetTtl(), object); + serialize("indexProperties", x.GetIndexProperties(), object); + serialize("streamProperties", x.GetStreamProperties(), object); + serialize("volume", x.GetVolume(), object); } void to_json(const dataservice::write::model::Notifications& x, - rapidjson::Value& value, - rapidjson::Document::AllocatorType& allocator) { - value.SetObject(); - serialize("enabled", x.GetEnabled(), value, allocator); + boost::json::value& value) { + auto& object = value.emplace_object(); + serialize("enabled", x.GetEnabled(), object); } void to_json(const dataservice::write::model::Catalog& x, - rapidjson::Value& value, - rapidjson::Document::AllocatorType& allocator) { - value.SetObject(); - serialize("id", x.GetId(), value, allocator); - serialize("hrn", x.GetHrn(), value, allocator); - serialize("name", x.GetName(), value, allocator); - serialize("summary", x.GetSummary(), value, allocator); - serialize("description", x.GetDescription(), value, allocator); - serialize("coverage", x.GetCoverage(), value, allocator); - serialize("owner", x.GetOwner(), value, allocator); - serialize("tags", x.GetTags(), value, allocator); - serialize("billingTags", x.GetBillingTags(), value, allocator); - serialize("created", x.GetCreated(), value, allocator); - serialize("layers", x.GetLayers(), value, allocator); - serialize("version", x.GetVersion(), value, allocator); - serialize("notifications", x.GetNotifications(), value, allocator); + boost::json::value& value) { + auto& object = value.emplace_object(); + serialize("id", x.GetId(), object); + serialize("hrn", x.GetHrn(), object); + serialize("name", x.GetName(), object); + serialize("summary", x.GetSummary(), object); + serialize("description", x.GetDescription(), object); + serialize("coverage", x.GetCoverage(), object); + serialize("owner", x.GetOwner(), object); + serialize("tags", x.GetTags(), object); + serialize("billingTags", x.GetBillingTags(), object); + serialize("created", x.GetCreated(), object); + serialize("layers", x.GetLayers(), object); + serialize("version", x.GetVersion(), object); + serialize("notifications", x.GetNotifications(), object); } } // namespace serializer diff --git a/olp-cpp-sdk-dataservice-write/src/generated/serializer/CatalogSerializer.h b/olp-cpp-sdk-dataservice-write/src/generated/serializer/CatalogSerializer.h index 934b6f516..dab097e47 100644 --- a/olp-cpp-sdk-dataservice-write/src/generated/serializer/CatalogSerializer.h +++ b/olp-cpp-sdk-dataservice-write/src/generated/serializer/CatalogSerializer.h @@ -1,5 +1,5 @@ /* - * Copyright (C) 2019-2021 HERE Europe B.V. + * Copyright (C) 2019-2026 HERE Europe B.V. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -19,61 +19,50 @@ #pragma once -#include +#include #include "../model/Catalog.h" namespace olp { namespace serializer { void to_json(const dataservice::write::model::Coverage& x, - rapidjson::Value& value, - rapidjson::Document::AllocatorType& allocator); + boost::json::value& value); void to_json(const dataservice::write::model::IndexDefinition& x, - rapidjson::Value& value, - rapidjson::Document::AllocatorType& allocator); + boost::json::value& value); void to_json(const dataservice::write::model::IndexProperties& x, - rapidjson::Value& value, - rapidjson::Document::AllocatorType& allocator); + boost::json::value& value); void to_json(const dataservice::write::model::Creator& x, - rapidjson::Value& value, - rapidjson::Document::AllocatorType& allocator); + boost::json::value& value); -void to_json(const dataservice::write::model::Owner& x, rapidjson::Value& value, - rapidjson::Document::AllocatorType& allocator); +void to_json(const dataservice::write::model::Owner& x, + boost::json::value& value); void to_json(const dataservice::write::model::Partitioning& x, - rapidjson::Value& value, - rapidjson::Document::AllocatorType& allocator); + boost::json::value& value); void to_json(const dataservice::write::model::Schema& x, - rapidjson::Value& value, - rapidjson::Document::AllocatorType& allocator); + boost::json::value& value); void to_json(const dataservice::write::model::StreamProperties& x, - rapidjson::Value& value, - rapidjson::Document::AllocatorType& allocator); + boost::json::value& value); void to_json(const dataservice::write::model::Encryption& x, - rapidjson::Value& value, - rapidjson::Document::AllocatorType& allocator); + boost::json::value& value); void to_json(const dataservice::write::model::Volume& x, - rapidjson::Value& value, - rapidjson::Document::AllocatorType& allocator); + boost::json::value& value); -void to_json(const dataservice::write::model::Layer& x, rapidjson::Value& value, - rapidjson::Document::AllocatorType& allocator); +void to_json(const dataservice::write::model::Layer& x, + boost::json::value& value); void to_json(const dataservice::write::model::Notifications& x, - rapidjson::Value& value, - rapidjson::Document::AllocatorType& allocator); + boost::json::value& value); void to_json(const dataservice::write::model::Catalog& x, - rapidjson::Value& value, - rapidjson::Document::AllocatorType& allocator); + boost::json::value& value); } // namespace serializer } // namespace olp diff --git a/olp-cpp-sdk-dataservice-write/src/generated/serializer/IndexInfoSerializer.cpp b/olp-cpp-sdk-dataservice-write/src/generated/serializer/IndexInfoSerializer.cpp index f95c7a0f7..217cc9a08 100644 --- a/olp-cpp-sdk-dataservice-write/src/generated/serializer/IndexInfoSerializer.cpp +++ b/olp-cpp-sdk-dataservice-write/src/generated/serializer/IndexInfoSerializer.cpp @@ -1,5 +1,5 @@ /* - * Copyright (C) 2019-2021 HERE Europe B.V. + * Copyright (C) 2019-2026 HERE Europe B.V. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -19,71 +19,59 @@ #include "IndexInfoSerializer.h" +#include + namespace olp { namespace serializer { -void to_json(const dataservice::write::model::Index &x, rapidjson::Value &value, - rapidjson::Document::AllocatorType &allocator) { - rapidjson::Value jsonValue(rapidjson::kObjectType); - value.SetArray(); - jsonValue.AddMember("id", rapidjson::StringRef(x.GetId().c_str()), allocator); +void to_json(const dataservice::write::model::Index &x, + boost::json::value &value) { + boost::json::object jsonValue; + value.emplace_array(); + jsonValue.emplace("id", x.GetId()); - rapidjson::Value indexFields(rapidjson::kObjectType); + boost::json::object indexFields; for (auto &field_pair : x.GetIndexFields()) { - using dataservice::write::model::BooleanIndexValue; - using dataservice::write::model::HereTileIndexValue; - using dataservice::write::model::IndexType; - using dataservice::write::model::IntIndexValue; - using dataservice::write::model::StringIndexValue; - using dataservice::write::model::TimeWindowIndexValue; - + namespace model = dataservice::write::model; const auto &field = field_pair.second; - const auto key = rapidjson::StringRef(field_pair.first.c_str()); + const auto &key = field_pair.first; auto index_type = field->getIndexType(); - if (index_type == IndexType::String) { - auto s = std::static_pointer_cast(field); - rapidjson::Value str_val; - const auto &str = s->GetValue(); - str_val.SetString( - str.c_str(), static_cast(str.size()), allocator); - indexFields.AddMember(key, str_val, allocator); - } else if (index_type == IndexType::Int) { - auto s = std::static_pointer_cast(field); - indexFields.AddMember(key, s->GetValue(), allocator); - } else if (index_type == IndexType::Bool) { - auto s = std::static_pointer_cast(field); - indexFields.AddMember(key, s->GetValue(), allocator); - } else if (index_type == IndexType::Heretile) { - auto s = std::static_pointer_cast(field); - indexFields.AddMember(key, s->GetValue(), allocator); - } else if (index_type == IndexType::TimeWindow) { - auto s = std::static_pointer_cast(field); - indexFields.AddMember(key, s->GetValue(), allocator); + if (index_type == model::IndexType::String) { + auto s = std::static_pointer_cast(field); + boost::json::string str_val{s->GetValue()}; + indexFields.emplace(key, std::move(str_val)); + } else if (index_type == model::IndexType::Int) { + auto s = std::static_pointer_cast(field); + indexFields.emplace(key, s->GetValue()); + } else if (index_type == model::IndexType::Bool) { + auto s = std::static_pointer_cast(field); + indexFields.emplace(key, s->GetValue()); + } else if (index_type == model::IndexType::Heretile) { + auto s = std::static_pointer_cast(field); + indexFields.emplace(key, s->GetValue()); + } else if (index_type == model::IndexType::TimeWindow) { + auto s = std::static_pointer_cast(field); + indexFields.emplace(key, s->GetValue()); } } - jsonValue.AddMember("fields", indexFields, allocator); + jsonValue.emplace("fields", std::move(indexFields)); // TODO: Separate Metadata Model serialization into its own file when needed // by another model. if (x.GetMetadata()) { - rapidjson::Value metadatas(rapidjson::kObjectType); for (const auto &metadata : *x.GetMetadata()) { - auto metadata_value = metadata.second; - auto metadata_key = metadata.first.c_str(); - indexFields.AddMember( - rapidjson::StringRef(metadata_key), - rapidjson::StringRef(metadata_value.c_str(), metadata_value.size()), - allocator); + auto &metadata_value = metadata.second; + auto &metadata_key = metadata.first; + indexFields.emplace(metadata_key, metadata_value); } } if (x.GetCheckSum()) { - jsonValue.AddMember( - "checksum", rapidjson::StringRef(x.GetCheckSum()->c_str()), allocator); + jsonValue.emplace("checksum", *x.GetCheckSum()); } if (x.GetSize()) { - jsonValue.AddMember("size", *x.GetSize(), allocator); + jsonValue.emplace("size", *x.GetSize()); } - value.PushBack(jsonValue, allocator); + value.as_array().emplace_back(std::move(jsonValue)); } } // namespace serializer diff --git a/olp-cpp-sdk-dataservice-write/src/generated/serializer/IndexInfoSerializer.h b/olp-cpp-sdk-dataservice-write/src/generated/serializer/IndexInfoSerializer.h index e7732b763..b44fdc47f 100644 --- a/olp-cpp-sdk-dataservice-write/src/generated/serializer/IndexInfoSerializer.h +++ b/olp-cpp-sdk-dataservice-write/src/generated/serializer/IndexInfoSerializer.h @@ -1,5 +1,5 @@ /* - * Copyright (C) 2019 HERE Europe B.V. + * Copyright (C) 2019-2026 HERE Europe B.V. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -19,13 +19,13 @@ #pragma once -#include +#include #include namespace olp { namespace serializer { -void to_json(const dataservice::write::model::Index& x, rapidjson::Value& value, - rapidjson::Document::AllocatorType& allocator); +void to_json(const dataservice::write::model::Index& x, + boost::json::value& value); } // namespace serializer } // namespace olp diff --git a/olp-cpp-sdk-dataservice-write/src/generated/serializer/JsonSerializer.h b/olp-cpp-sdk-dataservice-write/src/generated/serializer/JsonSerializer.h index 504c6c12a..3d6915c0e 100644 --- a/olp-cpp-sdk-dataservice-write/src/generated/serializer/JsonSerializer.h +++ b/olp-cpp-sdk-dataservice-write/src/generated/serializer/JsonSerializer.h @@ -1,5 +1,5 @@ /* - * Copyright (C) 2019 HERE Europe B.V. + * Copyright (C) 2019-2026 HERE Europe B.V. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -19,24 +19,19 @@ #pragma once -#include -#include -#include +#include + +#include +#include namespace olp { namespace serializer { template inline std::string serialize(const T& object) { - rapidjson::Document doc; - auto& allocator = doc.GetAllocator(); - - doc.SetObject(); - to_json(object, doc, allocator); - - rapidjson::StringBuffer buffer; - rapidjson::Writer writer(buffer); - doc.Accept(writer); - return buffer.GetString(); + boost::json::value value; + value.emplace_object(); + to_json(object, value); + return boost::json::serialize(value); } } // namespace serializer diff --git a/olp-cpp-sdk-dataservice-write/src/generated/serializer/PublicationSerializer.cpp b/olp-cpp-sdk-dataservice-write/src/generated/serializer/PublicationSerializer.cpp index ee1df67fa..04b65ac2c 100644 --- a/olp-cpp-sdk-dataservice-write/src/generated/serializer/PublicationSerializer.cpp +++ b/olp-cpp-sdk-dataservice-write/src/generated/serializer/PublicationSerializer.cpp @@ -1,5 +1,5 @@ /* - * Copyright (C) 2019 HERE Europe B.V. + * Copyright (C) 2019-2026 HERE Europe B.V. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -19,59 +19,54 @@ #include "PublicationSerializer.h" +#include + namespace olp { namespace serializer { void to_json(const dataservice::write::model::Publication& x, - rapidjson::Value& value, - rapidjson::Document::AllocatorType& allocator) { + boost::json::value& value) { + auto& object = value.emplace_object(); if (x.GetId()) { - value.AddMember("id", rapidjson::StringRef(x.GetId()->c_str()), allocator); + object.emplace("id", *x.GetId()); } // TODO: Separate Details Model serializtion into it's own file when needed by // another model. if (x.GetDetails()) { - rapidjson::Value details(rapidjson::kObjectType); - details.AddMember("state", - rapidjson::StringRef(x.GetDetails()->GetState().c_str()), - allocator); - details.AddMember( - "message", rapidjson::StringRef(x.GetDetails()->GetMessage().c_str()), - allocator); - details.AddMember("started", x.GetDetails()->GetStarted(), allocator); - details.AddMember("modified", x.GetDetails()->GetModified(), allocator); - details.AddMember("expires", x.GetDetails()->GetExpires(), allocator); - value.AddMember("details", details, allocator); + boost::json::object details; + details.emplace("state", x.GetDetails()->GetState()); + details.emplace("message", x.GetDetails()->GetMessage()); + details.emplace("started", x.GetDetails()->GetStarted()); + details.emplace("modified", x.GetDetails()->GetModified()); + details.emplace("expires", x.GetDetails()->GetExpires()); + object.emplace("details", std::move(details)); } if (x.GetLayerIds()) { - rapidjson::Value layer_ids(rapidjson::kArrayType); + boost::json::array layer_ids; for (auto& layer_id : *x.GetLayerIds()) { - layer_ids.PushBack(rapidjson::StringRef(layer_id.c_str()), allocator); + layer_ids.emplace_back(layer_id); } - value.AddMember("layerIds", layer_ids, allocator); + object.emplace("layerIds", std::move(layer_ids)); } if (x.GetCatalogVersion()) { - value.AddMember("catalogVersion", *x.GetCatalogVersion(), allocator); + object.emplace("catalogVersion", *x.GetCatalogVersion()); } if (x.GetVersionDependencies()) { - rapidjson::Value version_dependencies(rapidjson::kArrayType); + boost::json::array version_dependencies; for (auto& version_dependency : *x.GetVersionDependencies()) { // TODO: Separate VersionDependency Model serializtion into it's own file // when needed by another model. - rapidjson::Value version_dependency_json(rapidjson::kObjectType); - version_dependency_json.AddMember( - "direct", version_dependency.GetDirect(), allocator); - version_dependency_json.AddMember( - "hrn", rapidjson::StringRef(version_dependency.GetHrn().c_str()), - allocator); - version_dependency_json.AddMember( - "version", version_dependency.GetVersion(), allocator); - version_dependencies.PushBack(version_dependency_json, allocator); + boost::json::object version_dependency_json; + version_dependency_json.emplace("direct", version_dependency.GetDirect()); + version_dependency_json.emplace("hrn", version_dependency.GetHrn()); + version_dependency_json.emplace("version", + version_dependency.GetVersion()); + version_dependencies.emplace_back(std::move(version_dependency_json)); } - value.AddMember("versionDependencies", version_dependencies, allocator); + object.emplace("versionDependencies", std::move(version_dependencies)); } } diff --git a/olp-cpp-sdk-dataservice-write/src/generated/serializer/PublicationSerializer.h b/olp-cpp-sdk-dataservice-write/src/generated/serializer/PublicationSerializer.h index c00df9918..1e70410d9 100644 --- a/olp-cpp-sdk-dataservice-write/src/generated/serializer/PublicationSerializer.h +++ b/olp-cpp-sdk-dataservice-write/src/generated/serializer/PublicationSerializer.h @@ -1,5 +1,5 @@ /* - * Copyright (C) 2019 HERE Europe B.V. + * Copyright (C) 2019-2026 HERE Europe B.V. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -19,14 +19,13 @@ #pragma once -#include +#include #include namespace olp { namespace serializer { void to_json(const dataservice::write::model::Publication& x, - rapidjson::Value& value, - rapidjson::Document::AllocatorType& allocator); + boost::json::value& value); } // namespace serializer } // namespace olp diff --git a/olp-cpp-sdk-dataservice-write/src/generated/serializer/PublishDataRequestSerializer.cpp b/olp-cpp-sdk-dataservice-write/src/generated/serializer/PublishDataRequestSerializer.cpp index c23abe886..2b863d4bc 100644 --- a/olp-cpp-sdk-dataservice-write/src/generated/serializer/PublishDataRequestSerializer.cpp +++ b/olp-cpp-sdk-dataservice-write/src/generated/serializer/PublishDataRequestSerializer.cpp @@ -1,5 +1,5 @@ /* - * Copyright (C) 2019 HERE Europe B.V. + * Copyright (C) 2019-2026 HERE Europe B.V. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -22,32 +22,27 @@ namespace olp { namespace serializer { void to_json(const dataservice::write::model::PublishDataRequest& x, - rapidjson::Value& value, - rapidjson::Document::AllocatorType& allocator) { + boost::json::value& value) { + auto& object = value.emplace_object(); if (x.GetData()) { const auto& data = x.GetData().get(); - auto data_stringref = rapidjson::StringRef( + auto data_stringref = boost::json::string_view( reinterpret_cast(data->data()), data->size()); - value.AddMember("data", std::move(data_stringref), allocator); + object.emplace("data", data_stringref); } - value.AddMember("layerId", rapidjson::StringRef(x.GetLayerId().c_str()), - allocator); + object.emplace("layerId", x.GetLayerId()); if (x.GetTraceId()) { - value.AddMember("traceId", rapidjson::StringRef(x.GetTraceId()->c_str()), - allocator); + object.emplace("traceId", *x.GetTraceId()); } if (x.GetBillingTag()) { - value.AddMember("billingTag", - rapidjson::StringRef(x.GetBillingTag()->c_str()), - allocator); + object.emplace("billingTag", *x.GetBillingTag()); } if (x.GetChecksum()) { - value.AddMember("checksum", rapidjson::StringRef(x.GetChecksum()->c_str()), - allocator); + object.emplace("checksum", *x.GetChecksum()); } } diff --git a/olp-cpp-sdk-dataservice-write/src/generated/serializer/PublishDataRequestSerializer.h b/olp-cpp-sdk-dataservice-write/src/generated/serializer/PublishDataRequestSerializer.h index 687349e27..8609bebd3 100644 --- a/olp-cpp-sdk-dataservice-write/src/generated/serializer/PublishDataRequestSerializer.h +++ b/olp-cpp-sdk-dataservice-write/src/generated/serializer/PublishDataRequestSerializer.h @@ -1,5 +1,5 @@ /* - * Copyright (C) 2019 HERE Europe B.V. + * Copyright (C) 2019-2026 HERE Europe B.V. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -19,14 +19,13 @@ #pragma once -#include +#include #include namespace olp { namespace serializer { void to_json(const dataservice::write::model::PublishDataRequest& x, - rapidjson::Value& value, - rapidjson::Document::AllocatorType& allocator); + boost::json::value& value); } // namespace serializer } // namespace olp diff --git a/olp-cpp-sdk-dataservice-write/src/generated/serializer/PublishPartitionSerializer.cpp b/olp-cpp-sdk-dataservice-write/src/generated/serializer/PublishPartitionSerializer.cpp index 875fc73da..05e1a3dcc 100644 --- a/olp-cpp-sdk-dataservice-write/src/generated/serializer/PublishPartitionSerializer.cpp +++ b/olp-cpp-sdk-dataservice-write/src/generated/serializer/PublishPartitionSerializer.cpp @@ -1,5 +1,5 @@ /* - * Copyright (C) 2019 HERE Europe B.V. + * Copyright (C) 2019-2026 HERE Europe B.V. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -22,42 +22,37 @@ namespace olp { namespace serializer { void to_json(const dataservice::write::model::PublishPartition& x, - rapidjson::Value& value, - rapidjson::Document::AllocatorType& allocator) { + boost::json::value& value) { + auto& object = value.emplace_object(); if (x.GetPartition()) { - value.AddMember("partition", - rapidjson::StringRef(x.GetPartition()->c_str()), allocator); + object.emplace("partition", *x.GetPartition()); } if (x.GetChecksum()) { - value.AddMember("checksum", rapidjson::StringRef(x.GetChecksum()->c_str()), - allocator); + object.emplace("checksum", *x.GetChecksum()); } if (x.GetCompressedDataSize()) { - value.AddMember("compressedDataSize", *x.GetCompressedDataSize(), - allocator); + object.emplace("compressedDataSize", *x.GetCompressedDataSize()); } if (x.GetDataSize()) { - value.AddMember("dataSize", *x.GetDataSize(), allocator); + object.emplace("dataSize", *x.GetDataSize()); } if (x.GetData()) { const auto& data = x.GetData().get(); - auto data_stringref = rapidjson::StringRef( + auto data_stringref = boost::json::string_view( reinterpret_cast(data->data()), data->size()); - value.AddMember("data", std::move(data_stringref), allocator); + object.emplace("data", data_stringref); } if (x.GetDataHandle()) { - value.AddMember("dataHandle", - rapidjson::StringRef(x.GetDataHandle()->c_str()), - allocator); + object.emplace("dataHandle", *x.GetDataHandle()); } if (x.GetTimestamp()) { - value.AddMember("timestamp", *x.GetTimestamp(), allocator); + object.emplace("timestamp", *x.GetTimestamp()); } } diff --git a/olp-cpp-sdk-dataservice-write/src/generated/serializer/PublishPartitionSerializer.h b/olp-cpp-sdk-dataservice-write/src/generated/serializer/PublishPartitionSerializer.h index 158b8d0df..2ddc4df67 100644 --- a/olp-cpp-sdk-dataservice-write/src/generated/serializer/PublishPartitionSerializer.h +++ b/olp-cpp-sdk-dataservice-write/src/generated/serializer/PublishPartitionSerializer.h @@ -1,5 +1,5 @@ /* - * Copyright (C) 2019 HERE Europe B.V. + * Copyright (C) 2019-2026 HERE Europe B.V. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -19,14 +19,13 @@ #pragma once -#include +#include #include "generated/model/PublishPartition.h" namespace olp { namespace serializer { void to_json(const dataservice::write::model::PublishPartition& x, - rapidjson::Value& value, - rapidjson::Document::AllocatorType& allocator); + boost::json::value& value); } // namespace serializer } // namespace olp diff --git a/olp-cpp-sdk-dataservice-write/src/generated/serializer/PublishPartitionsSerializer.cpp b/olp-cpp-sdk-dataservice-write/src/generated/serializer/PublishPartitionsSerializer.cpp index 96fa18438..55c6b914a 100644 --- a/olp-cpp-sdk-dataservice-write/src/generated/serializer/PublishPartitionsSerializer.cpp +++ b/olp-cpp-sdk-dataservice-write/src/generated/serializer/PublishPartitionsSerializer.cpp @@ -1,5 +1,5 @@ /* - * Copyright (C) 2019 HERE Europe B.V. + * Copyright (C) 2019-2026 HERE Europe B.V. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -19,21 +19,22 @@ #include "PublishPartitionsSerializer.h" +#include + #include "PublishPartitionSerializer.h" namespace olp { namespace serializer { void to_json(const dataservice::write::model::PublishPartitions& x, - rapidjson::Value& value, - rapidjson::Document::AllocatorType& allocator) { + boost::json::value& value) { if (x.GetPartitions()) { - rapidjson::Value partitions(rapidjson::kArrayType); + boost::json::array partitions; for (auto& partition : *x.GetPartitions()) { - rapidjson::Value partition_value(rapidjson::kObjectType); - to_json(partition, partition_value, allocator); - partitions.PushBack(partition_value, allocator); + boost::json::value partition_value(boost::json::object_kind_t{}); + to_json(partition, partition_value); + partitions.emplace_back(std::move(partition_value)); } - value.AddMember("partitions", partitions, allocator); + value.as_object().emplace("partitions", std::move(partitions)); } } diff --git a/olp-cpp-sdk-dataservice-write/src/generated/serializer/PublishPartitionsSerializer.h b/olp-cpp-sdk-dataservice-write/src/generated/serializer/PublishPartitionsSerializer.h index 583ee4e2d..640afbcf4 100644 --- a/olp-cpp-sdk-dataservice-write/src/generated/serializer/PublishPartitionsSerializer.h +++ b/olp-cpp-sdk-dataservice-write/src/generated/serializer/PublishPartitionsSerializer.h @@ -1,5 +1,5 @@ /* - * Copyright (C) 2019 HERE Europe B.V. + * Copyright (C) 2019-2026 HERE Europe B.V. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -19,14 +19,13 @@ #pragma once -#include +#include #include "generated/model/PublishPartitions.h" namespace olp { namespace serializer { void to_json(const dataservice::write::model::PublishPartitions& x, - rapidjson::Value& value, - rapidjson::Document::AllocatorType& allocator); + boost::json::value& value); } // namespace serializer } // namespace olp diff --git a/olp-cpp-sdk-dataservice-write/src/generated/serializer/SerializerWrapper.h b/olp-cpp-sdk-dataservice-write/src/generated/serializer/SerializerWrapper.h new file mode 100644 index 000000000..7005b9cec --- /dev/null +++ b/olp-cpp-sdk-dataservice-write/src/generated/serializer/SerializerWrapper.h @@ -0,0 +1,102 @@ +/* + * Copyright (C) 2019-2026 HERE Europe B.V. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * SPDX-License-Identifier: Apache-2.0 + * License-Filename: LICENSE + */ + +#pragma once + +#include +#include +#include +#include +#include + +#include +#include + +namespace olp { +namespace serializer { + +inline void to_json(const std::string& x, boost::json::value& value) { + value.emplace_string() = x; +} + +inline void to_json(int32_t x, boost::json::value& value) { + value.emplace_int64() = x; +} + +inline void to_json(int64_t x, boost::json::value& value) { + value.emplace_int64() = x; +} + +inline void to_json(double x, boost::json::value& value) { + value.emplace_double() = x; +} +inline void to_json(bool x, boost::json::value& value) { + value.emplace_bool() = x; +} + +inline void to_json(const std::shared_ptr>& x, + boost::json::value& value) { + value.emplace_string().assign(x->begin(), x->end()); +} + +template +inline void to_json(const porting::optional& x, boost::json::value& value) { + if (x) { + to_json(*x, value); + } else { + value.emplace_null(); + } +} + +template +inline void to_json(const std::map& x, + boost::json::value& value) { + auto& object = value.emplace_object(); + for (auto itr = x.begin(); itr != x.end(); ++itr) { + const auto& key = itr->first; + boost::json::value item_value; + to_json(itr->second, item_value); + object.emplace(key, std::move(item_value)); + } +} + +template +inline void to_json(const std::vector& x, boost::json::value& value) { + auto& array = value.emplace_array(); + array.reserve(x.size()); + for (typename std::vector::const_iterator itr = x.begin(); itr != x.end(); + ++itr) { + boost::json::value item_value; + to_json(*itr, item_value); + array.emplace_back(std::move(item_value)); + } +} + +template +inline void serialize(const std::string& key, const T& x, + boost::json::object& value) { + boost::json::value item_value; + to_json(x, item_value); + if (!item_value.is_null()) { + value.emplace(key, std::move(item_value)); + } +} + +} // namespace serializer +} // namespace olp diff --git a/olp-cpp-sdk-dataservice-write/src/generated/serializer/UpdateIndexRequestSerializer.cpp b/olp-cpp-sdk-dataservice-write/src/generated/serializer/UpdateIndexRequestSerializer.cpp index d9ce5729e..3d2dd9235 100644 --- a/olp-cpp-sdk-dataservice-write/src/generated/serializer/UpdateIndexRequestSerializer.cpp +++ b/olp-cpp-sdk-dataservice-write/src/generated/serializer/UpdateIndexRequestSerializer.cpp @@ -1,5 +1,5 @@ /* - * Copyright (C) 2019-2021 HERE Europe B.V. + * Copyright (C) 2019-2026 HERE Europe B.V. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -19,84 +19,69 @@ #include "UpdateIndexRequestSerializer.h" +#include + namespace olp { namespace serializer { void to_json(const dataservice::write::model::UpdateIndexRequest &x, - rapidjson::Value &value, - rapidjson::Document::AllocatorType &allocator) { - rapidjson::Value additions(rapidjson::kArrayType); + boost::json::value &value) { + boost::json::array additions; + value.emplace_object(); for (auto &addition : x.GetIndexAdditions()) { - rapidjson::Value additionValue(rapidjson::kObjectType); - additionValue.AddMember( - "id", rapidjson::StringRef(addition.GetId().c_str()), allocator); + boost::json::object additionValue; + additionValue.emplace("id", addition.GetId()); - rapidjson::Value indexFields(rapidjson::kObjectType); + boost::json::object indexFields; for (const auto &field_pair : addition.GetIndexFields()) { - using dataservice::write::model::BooleanIndexValue; - using dataservice::write::model::HereTileIndexValue; - using dataservice::write::model::IndexType; - using dataservice::write::model::IntIndexValue; - using dataservice::write::model::StringIndexValue; - using dataservice::write::model::TimeWindowIndexValue; - + namespace model = dataservice::write::model; const auto &field = field_pair.second; - const auto key = rapidjson::StringRef(field_pair.first.c_str()); + const auto &key = field_pair.first; auto index_type = field->getIndexType(); - if (index_type == IndexType::String) { - auto s = std::static_pointer_cast(field); - rapidjson::Value str_val; - const auto &str = s->GetValue(); - str_val.SetString(str.c_str(), - static_cast(str.size()), - allocator); - indexFields.AddMember(key, str_val, allocator); - } else if (index_type == IndexType::Int) { - auto s = std::static_pointer_cast(field); - indexFields.AddMember(key, s->GetValue(), allocator); - } else if (index_type == IndexType::Bool) { - auto s = std::static_pointer_cast(field); - indexFields.AddMember(key, s->GetValue(), allocator); - } else if (index_type == IndexType::Heretile) { - auto s = std::static_pointer_cast(field); - indexFields.AddMember(key, s->GetValue(), allocator); - } else if (index_type == IndexType::TimeWindow) { - auto s = std::static_pointer_cast(field); - indexFields.AddMember(key, s->GetValue(), allocator); + if (index_type == model::IndexType::String) { + auto s = std::static_pointer_cast(field); + boost::json::string str_val{s->GetValue()}; + indexFields.emplace(key, std::move(str_val)); + } else if (index_type == model::IndexType::Int) { + auto s = std::static_pointer_cast(field); + indexFields.emplace(key, s->GetValue()); + } else if (index_type == model::IndexType::Bool) { + auto s = std::static_pointer_cast(field); + indexFields.emplace(key, s->GetValue()); + } else if (index_type == model::IndexType::Heretile) { + auto s = std::static_pointer_cast(field); + indexFields.emplace(key, s->GetValue()); + } else if (index_type == model::IndexType::TimeWindow) { + auto s = std::static_pointer_cast(field); + indexFields.emplace(key, s->GetValue()); } } - additionValue.AddMember("fields", indexFields, allocator); + additionValue.emplace("fields", indexFields); // TODO: Separate Details Model serializtion into it's own file when needed // by another model. if (addition.GetMetadata()) { - rapidjson::Value metadatas(rapidjson::kObjectType); for (const auto &metadata : *addition.GetMetadata()) { const auto &metadata_value = metadata.second; - const auto &metadata_key = metadata.first.c_str(); - indexFields.AddMember( - rapidjson::StringRef(metadata_key), - rapidjson::StringRef(metadata_value.c_str(), metadata_value.size()), - allocator); + const auto &metadata_key = metadata.first; + indexFields.emplace(metadata_key, metadata_value); } } if (addition.GetCheckSum()) { - additionValue.AddMember( - "checksum", rapidjson::StringRef(addition.GetCheckSum()->c_str()), - allocator); + additionValue.emplace("checksum", *addition.GetCheckSum()); } if (addition.GetSize()) { - additionValue.AddMember("size", *addition.GetSize(), allocator); + additionValue.emplace("size", *addition.GetSize()); } - additions.PushBack(additionValue, allocator); + additions.emplace_back(additionValue); } - value.AddMember("additions", additions, allocator); - rapidjson::Value removals(rapidjson::kArrayType); + value.as_object().emplace("additions", std::move(additions)); + boost::json::array removals; for (auto &removal : x.GetIndexRemovals()) { - removals.PushBack(rapidjson::StringRef(removal.c_str()), allocator); + removals.emplace_back(removal); } - value.AddMember("removals", removals, allocator); + value.as_object().emplace("removals", std::move(removals)); } } // namespace serializer diff --git a/olp-cpp-sdk-dataservice-write/src/generated/serializer/UpdateIndexRequestSerializer.h b/olp-cpp-sdk-dataservice-write/src/generated/serializer/UpdateIndexRequestSerializer.h index dd8b8b5e4..77137249d 100644 --- a/olp-cpp-sdk-dataservice-write/src/generated/serializer/UpdateIndexRequestSerializer.h +++ b/olp-cpp-sdk-dataservice-write/src/generated/serializer/UpdateIndexRequestSerializer.h @@ -1,5 +1,5 @@ /* - * Copyright (C) 2019 HERE Europe B.V. + * Copyright (C) 2019-2026 HERE Europe B.V. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -19,15 +19,14 @@ #pragma once -#include +#include #include namespace olp { namespace serializer { void to_json(const dataservice::write::model::UpdateIndexRequest& x, - rapidjson::Value& value, - rapidjson::Document::AllocatorType& allocator); + boost::json::value& value); } // namespace serializer } // namespace olp diff --git a/olp-cpp-sdk-dataservice-write/src/utils/BoostJsonSrc.cpp b/olp-cpp-sdk-dataservice-write/src/utils/BoostJsonSrc.cpp new file mode 100644 index 000000000..017758210 --- /dev/null +++ b/olp-cpp-sdk-dataservice-write/src/utils/BoostJsonSrc.cpp @@ -0,0 +1,20 @@ +/* + * Copyright (C) 2026 HERE Europe B.V. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * SPDX-License-Identifier: Apache-2.0 + * License-Filename: LICENSE + */ + +#include diff --git a/olp-cpp-sdk-dataservice-write/tests/ParserTest.cpp b/olp-cpp-sdk-dataservice-write/tests/ParserTest.cpp index 746ec330f..60c7bf37d 100644 --- a/olp-cpp-sdk-dataservice-write/tests/ParserTest.cpp +++ b/olp-cpp-sdk-dataservice-write/tests/ParserTest.cpp @@ -1,5 +1,5 @@ /* - * Copyright (C) 2019 HERE Europe B.V. + * Copyright (C) 2019-2026 HERE Europe B.V. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -36,7 +36,7 @@ #include #include #include -#include +#include // clang-format on namespace { diff --git a/olp-cpp-sdk-dataservice-write/tests/VersionedLayerClientImplPublishToBatchTest.cpp b/olp-cpp-sdk-dataservice-write/tests/VersionedLayerClientImplPublishToBatchTest.cpp index b58adfcda..e54b04987 100644 --- a/olp-cpp-sdk-dataservice-write/tests/VersionedLayerClientImplPublishToBatchTest.cpp +++ b/olp-cpp-sdk-dataservice-write/tests/VersionedLayerClientImplPublishToBatchTest.cpp @@ -1,5 +1,5 @@ /* - * Copyright (C) 2020-2024 HERE Europe B.V. + * Copyright (C) 2020-2026 HERE Europe B.V. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -29,7 +29,7 @@ #include "generated/serializer/ApiSerializer.h" #include "generated/serializer/PublicationSerializer.h" #include "generated/serializer/CatalogSerializer.h" -#include +#include #include "generated/serializer/JsonSerializer.h" // clang-format on diff --git a/olp-cpp-sdk-dataservice-write/tests/VersionedLayerClientImplTest.cpp b/olp-cpp-sdk-dataservice-write/tests/VersionedLayerClientImplTest.cpp index e19ca97be..29b936da1 100644 --- a/olp-cpp-sdk-dataservice-write/tests/VersionedLayerClientImplTest.cpp +++ b/olp-cpp-sdk-dataservice-write/tests/VersionedLayerClientImplTest.cpp @@ -1,5 +1,5 @@ /* - * Copyright (C) 2020-2021 HERE Europe B.V. + * Copyright (C) 2020-2026 HERE Europe B.V. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -28,7 +28,7 @@ // clang-format off #include "generated/serializer/ApiSerializer.h" #include "generated/serializer/PublicationSerializer.h" -#include +#include #include "generated/serializer/JsonSerializer.h" // clang-format on diff --git a/tests/integration/olp-cpp-sdk-dataservice-write/VersionedLayerClientPublishToBatchTest.cpp b/tests/integration/olp-cpp-sdk-dataservice-write/VersionedLayerClientPublishToBatchTest.cpp index 74e5c8504..36ab71bf2 100644 --- a/tests/integration/olp-cpp-sdk-dataservice-write/VersionedLayerClientPublishToBatchTest.cpp +++ b/tests/integration/olp-cpp-sdk-dataservice-write/VersionedLayerClientPublishToBatchTest.cpp @@ -1,5 +1,5 @@ /* - * Copyright (C) 2020-2024 HERE Europe B.V. + * Copyright (C) 2020-2026 HERE Europe B.V. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -31,7 +31,7 @@ #include "generated/serializer/ApiSerializer.h" #include "generated/serializer/CatalogSerializer.h" #include "generated/serializer/PublicationSerializer.h" -#include +#include #include "generated/serializer/JsonSerializer.h" // clang-format on diff --git a/tests/integration/olp-cpp-sdk-dataservice-write/VersionedLayerClientTest.cpp b/tests/integration/olp-cpp-sdk-dataservice-write/VersionedLayerClientTest.cpp index 2389ad6f3..085f92791 100644 --- a/tests/integration/olp-cpp-sdk-dataservice-write/VersionedLayerClientTest.cpp +++ b/tests/integration/olp-cpp-sdk-dataservice-write/VersionedLayerClientTest.cpp @@ -1,5 +1,5 @@ /* - * Copyright (C) 2020-2021 HERE Europe B.V. + * Copyright (C) 2020-2026 HERE Europe B.V. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -30,7 +30,7 @@ // clang-format off #include "generated/serializer/ApiSerializer.h" #include "generated/serializer/PublicationSerializer.h" -#include +#include #include "generated/serializer/JsonSerializer.h" // clang-format on From ded68cb6b7f352af51e5f438b21d01de00459a79 Mon Sep 17 00:00:00 2001 From: Rustam Gamidov <108531570+rustam-gamidov-here@users.noreply.github.com> Date: Tue, 17 Mar 2026 16:46:05 +0200 Subject: [PATCH 09/12] Use Boost::json in olp-cpp-sdk-dataservice-read (#1684) Migrating from RapidJSON Copy json implementation wrappers to read lib This allows to keep other libs untouched until fully migrated to the boost::json and remove read lib dependency from public json wrappers. Alternative solutions tried are: - add boost json wrappers to the same files in the core but to additional namespace - changes in core, json still exposed - move boost json wrappers from core to internal for the repository include location and add it to all DataSDK projects - huge change Relates-To: OCMAM-444 Signed-off-by: Rustam Gamidov --- .../dataservice/read/model/StreamOffsets.h | 3 +- .../src/JsonResultParser.h | 4 +- .../src/generated/api/MetadataApi.cpp | 6 +- .../src/generated/parser/ApiParser.cpp | 8 +- .../src/generated/parser/ApiParser.h | 7 +- .../src/generated/parser/CatalogParser.cpp | 34 ++-- .../src/generated/parser/CatalogParser.h | 30 +-- .../src/generated/parser/IndexParser.cpp | 16 +- .../src/generated/parser/IndexParser.h | 11 +- .../src/generated/parser/JsonParser.h | 78 ++++++++ .../generated/parser/LayerVersionsParser.cpp | 12 +- .../generated/parser/LayerVersionsParser.h | 8 +- .../src/generated/parser/MessagesParser.cpp | 15 +- .../src/generated/parser/MessagesParser.h | 10 +- .../src/generated/parser/ParserWrapper.h | 102 ++++++++++ .../src/generated/parser/PartitionsParser.cpp | 15 +- .../src/generated/parser/PartitionsParser.h | 8 +- .../generated/parser/StreamOffsetParser.cpp | 8 +- .../src/generated/parser/StreamOffsetParser.h | 6 +- .../parser/SubscribeResponseParser.cpp | 10 +- .../parser/SubscribeResponseParser.h | 6 +- .../generated/parser/VersionInfosParser.cpp | 11 +- .../src/generated/parser/VersionInfosParser.h | 10 +- .../parser/VersionResponseParser.cpp | 8 +- .../generated/parser/VersionResponseParser.h | 6 +- .../parser/VersionsResponseParser.cpp | 12 +- .../generated/parser/VersionsResponseParser.h | 11 +- .../generated/serializer/ApiSerializer.cpp | 20 +- .../src/generated/serializer/ApiSerializer.h | 8 +- .../serializer/CatalogSerializer.cpp | 181 ++++++++---------- .../generated/serializer/CatalogSerializer.h | 43 ++--- .../serializer/CatalogVersionsSerializer.h | 38 ++-- .../serializer/ConsumerPropertiesSerializer.h | 23 +-- .../src/generated/serializer/JsonSerializer.h | 46 ++--- .../serializer/LayerVersionsSerializer.cpp | 26 ++- .../serializer/LayerVersionsSerializer.h | 11 +- .../serializer/PartitionsSerializer.cpp | 32 ++-- .../serializer/PartitionsSerializer.h | 10 +- .../generated/serializer/SerializerWrapper.h | 102 ++++++++++ .../serializer/StreamOffsetsSerializer.cpp | 20 +- .../serializer/StreamOffsetsSerializer.h | 10 +- .../serializer/VersionInfosSerializer.cpp | 35 ++-- .../serializer/VersionInfosSerializer.h | 13 +- .../serializer/VersionResponseSerializer.cpp | 13 +- .../serializer/VersionResponseSerializer.h | 7 +- .../src/repositories/AsyncJsonStream.h | 3 +- .../PartitionsCacheRepository.cpp | 6 +- .../src/repositories/QuadTreeIndex.cpp | 107 ++++++----- .../tests/ParserTest.cpp | 4 +- .../tests/PartitionsCacheRepositoryTest.cpp | 4 +- .../tests/PartitionsRepositoryTest.cpp | 2 +- tests/common/ResponseGenerator.cpp | 4 +- 52 files changed, 746 insertions(+), 477 deletions(-) create mode 100644 olp-cpp-sdk-dataservice-read/src/generated/parser/JsonParser.h create mode 100644 olp-cpp-sdk-dataservice-read/src/generated/parser/ParserWrapper.h create mode 100644 olp-cpp-sdk-dataservice-read/src/generated/serializer/SerializerWrapper.h diff --git a/olp-cpp-sdk-dataservice-read/include/olp/dataservice/read/model/StreamOffsets.h b/olp-cpp-sdk-dataservice-read/include/olp/dataservice/read/model/StreamOffsets.h index c84691a8a..0a1548e13 100644 --- a/olp-cpp-sdk-dataservice-read/include/olp/dataservice/read/model/StreamOffsets.h +++ b/olp-cpp-sdk-dataservice-read/include/olp/dataservice/read/model/StreamOffsets.h @@ -1,5 +1,5 @@ /* - * Copyright (C) 2020-2021 HERE Europe B.V. + * Copyright (C) 2020-2026 HERE Europe B.V. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -19,6 +19,7 @@ #pragma once +#include #include #include diff --git a/olp-cpp-sdk-dataservice-read/src/JsonResultParser.h b/olp-cpp-sdk-dataservice-read/src/JsonResultParser.h index a5dea90f8..de069190c 100644 --- a/olp-cpp-sdk-dataservice-read/src/JsonResultParser.h +++ b/olp-cpp-sdk-dataservice-read/src/JsonResultParser.h @@ -1,5 +1,5 @@ /* - * Copyright (C) 2020 HERE Europe B.V. + * Copyright (C) 2020-2026 HERE Europe B.V. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -23,8 +23,8 @@ #include #include +#include #include -#include #include namespace olp { diff --git a/olp-cpp-sdk-dataservice-read/src/generated/api/MetadataApi.cpp b/olp-cpp-sdk-dataservice-read/src/generated/api/MetadataApi.cpp index 2e391725d..4e26b2c41 100644 --- a/olp-cpp-sdk-dataservice-read/src/generated/api/MetadataApi.cpp +++ b/olp-cpp-sdk-dataservice-read/src/generated/api/MetadataApi.cpp @@ -1,5 +1,5 @@ /* - * Copyright (C) 2019-2024 HERE Europe B.V. + * Copyright (C) 2019-2026 HERE Europe B.V. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -22,6 +22,8 @@ #include #include #include +#include +#include #include #include @@ -235,8 +237,6 @@ MetadataApi::CompatibleVersionsResponse MetadataApi::GetCompatibleVersions( std::multimap query_params; query_params.emplace("limit", std::to_string(limit)); - rapidjson::Value value; - const auto serialized_dependencies = serializer::serialize(dependencies); const auto data = std::make_shared>( diff --git a/olp-cpp-sdk-dataservice-read/src/generated/parser/ApiParser.cpp b/olp-cpp-sdk-dataservice-read/src/generated/parser/ApiParser.cpp index 632c25d45..bc0913b12 100644 --- a/olp-cpp-sdk-dataservice-read/src/generated/parser/ApiParser.cpp +++ b/olp-cpp-sdk-dataservice-read/src/generated/parser/ApiParser.cpp @@ -1,5 +1,5 @@ /* - * Copyright (C) 2019 HERE Europe B.V. + * Copyright (C) 2019-2026 HERE Europe B.V. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -19,11 +19,13 @@ #include "ApiParser.h" -#include +#include + +#include namespace olp { namespace parser { -void from_json(const rapidjson::Value& value, +void from_json(const boost::json::value& value, olp::dataservice::read::model::Api& x) { x.SetApi(parse(value, "api")); x.SetVersion(parse(value, "version")); diff --git a/olp-cpp-sdk-dataservice-read/src/generated/parser/ApiParser.h b/olp-cpp-sdk-dataservice-read/src/generated/parser/ApiParser.h index d7d79f42b..20020c45e 100644 --- a/olp-cpp-sdk-dataservice-read/src/generated/parser/ApiParser.h +++ b/olp-cpp-sdk-dataservice-read/src/generated/parser/ApiParser.h @@ -1,5 +1,5 @@ /* - * Copyright (C) 2019 HERE Europe B.V. + * Copyright (C) 2019-2026 HERE Europe B.V. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -19,14 +19,15 @@ #pragma once -#include +#include #include "generated/model/Api.h" #include namespace olp { namespace parser { -void from_json(const rapidjson::Value& value, olp::dataservice::read::model::Api& x); +void from_json(const boost::json::value& value, + olp::dataservice::read::model::Api& x); } // namespace parser diff --git a/olp-cpp-sdk-dataservice-read/src/generated/parser/CatalogParser.cpp b/olp-cpp-sdk-dataservice-read/src/generated/parser/CatalogParser.cpp index 33d39c1fa..03d05238f 100644 --- a/olp-cpp-sdk-dataservice-read/src/generated/parser/CatalogParser.cpp +++ b/olp-cpp-sdk-dataservice-read/src/generated/parser/CatalogParser.cpp @@ -1,5 +1,5 @@ /* - * Copyright (C) 2019 HERE Europe B.V. + * Copyright (C) 2019-2026 HERE Europe B.V. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -19,48 +19,50 @@ #include "CatalogParser.h" -#include +#include + +#include namespace olp { namespace parser { -namespace model = dataservice::read::model; +namespace model = olp::dataservice::read::model; -void from_json(const rapidjson::Value& value, model::Coverage& x) { +void from_json(const boost::json::value& value, model::Coverage& x) { x.SetAdminAreas(parse>(value, "adminAreas")); } -void from_json(const rapidjson::Value& value, model::IndexDefinition& x) { +void from_json(const boost::json::value& value, model::IndexDefinition& x) { x.SetName(parse(value, "name")); x.SetType(parse(value, "type")); x.SetDuration(parse(value, "duration")); x.SetZoomLevel(parse(value, "zoomLevel")); } -void from_json(const rapidjson::Value& value, model::IndexProperties& x) { +void from_json(const boost::json::value& value, model::IndexProperties& x) { x.SetTtl(parse(value, "ttl")); x.SetIndexDefinitions( parse>(value, "indexDefinitions")); } -void from_json(const rapidjson::Value& value, model::Creator& x) { +void from_json(const boost::json::value& value, model::Creator& x) { x.SetId(parse(value, "id")); } -void from_json(const rapidjson::Value& value, model::Owner& x) { +void from_json(const boost::json::value& value, model::Owner& x) { x.SetCreator(parse(value, "creator")); x.SetOrganisation(parse(value, "organisation")); } -void from_json(const rapidjson::Value& value, model::Partitioning& x) { +void from_json(const boost::json::value& value, model::Partitioning& x) { x.SetScheme(parse(value, "scheme")); x.SetTileLevels(parse>(value, "tileLevels")); } -void from_json(const rapidjson::Value& value, model::Schema& x) { +void from_json(const boost::json::value& value, model::Schema& x) { x.SetHrn(parse(value, "hrn")); } -void from_json(const rapidjson::Value& value, model::StreamProperties& x) { +void from_json(const boost::json::value& value, model::StreamProperties& x) { // Parsing these as double even though OepnAPI sepcs says int64 because // Backend returns the value in decimal format (e.g. 1.0) and this triggers an // assert in RapidJSON when parsing. @@ -70,18 +72,18 @@ void from_json(const rapidjson::Value& value, model::StreamProperties& x) { static_cast(parse(value, "dataOutThroughputMbps"))); } -void from_json(const rapidjson::Value& value, model::Encryption& x) { +void from_json(const boost::json::value& value, model::Encryption& x) { x.SetAlgorithm(parse(value, "algorithm")); } -void from_json(const rapidjson::Value& value, model::Volume& x) { +void from_json(const boost::json::value& value, model::Volume& x) { x.SetVolumeType(parse(value, "volumeType")); x.SetMaxMemoryPolicy(parse(value, "maxMemoryPolicy")); x.SetPackageType(parse(value, "packageType")); x.SetEncryption(parse(value, "encryption")); } -void from_json(const rapidjson::Value& value, model::Layer& x) { +void from_json(const boost::json::value& value, model::Layer& x) { x.SetId(parse(value, "id")); x.SetName(parse(value, "name")); x.SetSummary(parse(value, "summary")); @@ -103,11 +105,11 @@ void from_json(const rapidjson::Value& value, model::Layer& x) { x.SetVolume(parse(value, "volume")); } -void from_json(const rapidjson::Value& value, model::Notifications& x) { +void from_json(const boost::json::value& value, model::Notifications& x) { x.SetEnabled(parse(value, "enabled")); } -void from_json(const rapidjson::Value& value, model::Catalog& x) { +void from_json(const boost::json::value& value, model::Catalog& x) { x.SetId(parse(value, "id")); x.SetHrn(parse(value, "hrn")); x.SetName(parse(value, "name")); diff --git a/olp-cpp-sdk-dataservice-read/src/generated/parser/CatalogParser.h b/olp-cpp-sdk-dataservice-read/src/generated/parser/CatalogParser.h index fde7f7cb7..73ecd68d2 100644 --- a/olp-cpp-sdk-dataservice-read/src/generated/parser/CatalogParser.h +++ b/olp-cpp-sdk-dataservice-read/src/generated/parser/CatalogParser.h @@ -1,5 +1,5 @@ /* - * Copyright (C) 2019 HERE Europe B.V. + * Copyright (C) 2019-2026 HERE Europe B.V. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -19,50 +19,50 @@ #pragma once -#include +#include #include "olp/dataservice/read/model/Catalog.h" #include namespace olp { namespace parser { -void from_json(const rapidjson::Value& value, +void from_json(const boost::json::value& value, olp::dataservice::read::model::Coverage& x); -void from_json(const rapidjson::Value& value, +void from_json(const boost::json::value& value, olp::dataservice::read::model::IndexDefinition& x); -void from_json(const rapidjson::Value& value, +void from_json(const boost::json::value& value, olp::dataservice::read::model::IndexProperties& x); -void from_json(const rapidjson::Value& value, +void from_json(const boost::json::value& value, olp::dataservice::read::model::Creator& x); -void from_json(const rapidjson::Value& value, +void from_json(const boost::json::value& value, olp::dataservice::read::model::Owner& x); -void from_json(const rapidjson::Value& value, +void from_json(const boost::json::value& value, olp::dataservice::read::model::Partitioning& x); -void from_json(const rapidjson::Value& value, +void from_json(const boost::json::value& value, olp::dataservice::read::model::Schema& x); -void from_json(const rapidjson::Value& value, +void from_json(const boost::json::value& value, olp::dataservice::read::model::StreamProperties& x); -void from_json(const rapidjson::Value& value, +void from_json(const boost::json::value& value, olp::dataservice::read::model::Encryption& x); -void from_json(const rapidjson::Value& value, +void from_json(const boost::json::value& value, olp::dataservice::read::model::Volume& x); -void from_json(const rapidjson::Value& value, +void from_json(const boost::json::value& value, olp::dataservice::read::model::Layer& x); -void from_json(const rapidjson::Value& value, +void from_json(const boost::json::value& value, olp::dataservice::read::model::Notifications& x); -void from_json(const rapidjson::Value& value, +void from_json(const boost::json::value& value, olp::dataservice::read::model::Catalog& x); } // namespace parser } // namespace olp diff --git a/olp-cpp-sdk-dataservice-read/src/generated/parser/IndexParser.cpp b/olp-cpp-sdk-dataservice-read/src/generated/parser/IndexParser.cpp index d9cfe81ab..2d07230a3 100644 --- a/olp-cpp-sdk-dataservice-read/src/generated/parser/IndexParser.cpp +++ b/olp-cpp-sdk-dataservice-read/src/generated/parser/IndexParser.cpp @@ -1,5 +1,5 @@ /* - * Copyright (C) 2019 HERE Europe B.V. + * Copyright (C) 2019-2026 HERE Europe B.V. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -19,13 +19,17 @@ #include "IndexParser.h" -#include +#include +#include + +#include namespace olp { namespace parser { -namespace model = dataservice::read::model; -void from_json(const rapidjson::Value& value, +namespace model = olp::dataservice::read::model; + +void from_json(const boost::json::value& value, std::shared_ptr& x) { auto quad = std::make_shared(); @@ -47,7 +51,7 @@ void from_json(const rapidjson::Value& value, x.swap(quad); } -void from_json(const rapidjson::Value& value, +void from_json(const boost::json::value& value, std::shared_ptr& x) { auto quad = std::make_shared(); @@ -69,7 +73,7 @@ void from_json(const rapidjson::Value& value, x.swap(quad); } -void from_json(const rapidjson::Value& value, model::Index& x) { +void from_json(const boost::json::value& value, model::Index& x) { x.SetParentQuads(parse>>( value, "parentQuads")); x.SetSubQuads( diff --git a/olp-cpp-sdk-dataservice-read/src/generated/parser/IndexParser.h b/olp-cpp-sdk-dataservice-read/src/generated/parser/IndexParser.h index 9cb7f0f4f..60fac610f 100644 --- a/olp-cpp-sdk-dataservice-read/src/generated/parser/IndexParser.h +++ b/olp-cpp-sdk-dataservice-read/src/generated/parser/IndexParser.h @@ -1,5 +1,5 @@ /* - * Copyright (C) 2019 HERE Europe B.V. + * Copyright (C) 2019-2026 HERE Europe B.V. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -19,19 +19,20 @@ #pragma once -#include +#include #include "generated/model/Index.h" +#include #include namespace olp { namespace parser { -void from_json(const rapidjson::Value& value, +void from_json(const boost::json::value& value, std::shared_ptr& x); -void from_json(const rapidjson::Value& value, +void from_json(const boost::json::value& value, std::shared_ptr& x); -void from_json(const rapidjson::Value& value, +void from_json(const boost::json::value& value, olp::dataservice::read::model::Index& x); } // namespace parser } // namespace olp diff --git a/olp-cpp-sdk-dataservice-read/src/generated/parser/JsonParser.h b/olp-cpp-sdk-dataservice-read/src/generated/parser/JsonParser.h new file mode 100644 index 000000000..48f30401e --- /dev/null +++ b/olp-cpp-sdk-dataservice-read/src/generated/parser/JsonParser.h @@ -0,0 +1,78 @@ +/* + * Copyright (C) 2019-2026 HERE Europe B.V. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * SPDX-License-Identifier: Apache-2.0 + * License-Filename: LICENSE + */ + +#pragma once + +#include +#include +#include +#include + +#include + +#include "ParserWrapper.h" + +namespace olp { +namespace parser { + +template +inline T parse(const std::string& json) { + boost::json::error_code ec; + auto value = boost::json::parse(json, ec); + T result{}; + if (value.is_object() || value.is_array()) { + from_json(value, result); + } + return result; +} + +template +inline T parse(std::stringstream& json_stream, bool& res) { + res = false; + boost::json::error_code ec; + auto value = boost::json::parse(json_stream, ec); + T result{}; + if (value.is_object() || value.is_array()) { + from_json(value, result); + res = true; + } + return result; +} + +template +inline T parse(std::stringstream& json_stream) { + bool res = true; + return parse(json_stream, res); +} + +template +inline T parse(const std::shared_ptr>& json_bytes) { + boost::json::string_view json(reinterpret_cast(json_bytes->data()), + json_bytes->size()); + boost::json::error_code ec; + auto value = boost::json::parse(json, ec); + T result{}; + if (value.is_object() || value.is_array()) { + from_json(value, result); + } + return result; +} + +} // namespace parser +} // namespace olp diff --git a/olp-cpp-sdk-dataservice-read/src/generated/parser/LayerVersionsParser.cpp b/olp-cpp-sdk-dataservice-read/src/generated/parser/LayerVersionsParser.cpp index 6b6920418..6a650535d 100644 --- a/olp-cpp-sdk-dataservice-read/src/generated/parser/LayerVersionsParser.cpp +++ b/olp-cpp-sdk-dataservice-read/src/generated/parser/LayerVersionsParser.cpp @@ -1,5 +1,5 @@ /* - * Copyright (C) 2019 HERE Europe B.V. + * Copyright (C) 2019-2026 HERE Europe B.V. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -19,19 +19,21 @@ #include "LayerVersionsParser.h" -#include +#include + +#include namespace olp { namespace parser { -using namespace olp::dataservice::read; +namespace model = olp::dataservice::read::model; -void from_json(const rapidjson::Value& value, model::LayerVersion& x) { +void from_json(const boost::json::value& value, model::LayerVersion& x) { x.SetLayer(parse(value, "layer")); x.SetVersion(parse(value, "version")); x.SetTimestamp(parse(value, "timestamp")); } -void from_json(const rapidjson::Value& value, model::LayerVersions& x) { +void from_json(const boost::json::value& value, model::LayerVersions& x) { x.SetLayerVersions( parse>(value, "layerVersions")); x.SetVersion(parse(value, "version")); diff --git a/olp-cpp-sdk-dataservice-read/src/generated/parser/LayerVersionsParser.h b/olp-cpp-sdk-dataservice-read/src/generated/parser/LayerVersionsParser.h index ca5136176..ef725789b 100644 --- a/olp-cpp-sdk-dataservice-read/src/generated/parser/LayerVersionsParser.h +++ b/olp-cpp-sdk-dataservice-read/src/generated/parser/LayerVersionsParser.h @@ -1,5 +1,5 @@ /* - * Copyright (C) 2019 HERE Europe B.V. + * Copyright (C) 2019-2026 HERE Europe B.V. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -19,17 +19,17 @@ #pragma once -#include +#include #include "generated/model/LayerVersions.h" #include namespace olp { namespace parser { -void from_json(const rapidjson::Value& value, +void from_json(const boost::json::value& value, olp::dataservice::read::model::LayerVersion& x); -void from_json(const rapidjson::Value& value, +void from_json(const boost::json::value& value, olp::dataservice::read::model::LayerVersions& x); } // namespace parser diff --git a/olp-cpp-sdk-dataservice-read/src/generated/parser/MessagesParser.cpp b/olp-cpp-sdk-dataservice-read/src/generated/parser/MessagesParser.cpp index 67ec4793a..8cd71add9 100644 --- a/olp-cpp-sdk-dataservice-read/src/generated/parser/MessagesParser.cpp +++ b/olp-cpp-sdk-dataservice-read/src/generated/parser/MessagesParser.cpp @@ -1,5 +1,5 @@ /* - * Copyright (C) 2020 HERE Europe B.V. + * Copyright (C) 2020-2026 HERE Europe B.V. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -19,16 +19,19 @@ #include "MessagesParser.h" +#include +#include + // clang-format off #include "generated/parser/StreamOffsetParser.h" -#include +#include // clang-format on namespace olp { namespace parser { -namespace model = dataservice::read::model; +namespace model = olp::dataservice::read::model; -void from_json(const rapidjson::Value& value, model::Metadata& x) { +void from_json(const boost::json::value& value, model::Metadata& x) { x.SetPartition(parse(value, "partition")); x.SetChecksum(parse>(value, "checksum")); x.SetCompressedDataSize( @@ -39,12 +42,12 @@ void from_json(const rapidjson::Value& value, model::Metadata& x) { x.SetTimestamp(parse>(value, "timestamp")); } -void from_json(const rapidjson::Value& value, model::Message& x) { +void from_json(const boost::json::value& value, model::Message& x) { x.SetMetaData(parse(value, "metaData")); x.SetOffset(parse(value, "offset")); } -void from_json(const rapidjson::Value& value, model::Messages& x) { +void from_json(const boost::json::value& value, model::Messages& x) { x.SetMessages(parse>(value, "messages")); } diff --git a/olp-cpp-sdk-dataservice-read/src/generated/parser/MessagesParser.h b/olp-cpp-sdk-dataservice-read/src/generated/parser/MessagesParser.h index 270a8dc36..df0e41add 100644 --- a/olp-cpp-sdk-dataservice-read/src/generated/parser/MessagesParser.h +++ b/olp-cpp-sdk-dataservice-read/src/generated/parser/MessagesParser.h @@ -1,5 +1,5 @@ /* - * Copyright (C) 2020 HERE Europe B.V. + * Copyright (C) 2020-2026 HERE Europe B.V. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -19,19 +19,19 @@ #pragma once -#include #include +#include namespace olp { namespace parser { -void from_json(const rapidjson::Value& value, +void from_json(const boost::json::value& value, olp::dataservice::read::model::Metadata& x); -void from_json(const rapidjson::Value& value, +void from_json(const boost::json::value& value, olp::dataservice::read::model::Message& x); -void from_json(const rapidjson::Value& value, +void from_json(const boost::json::value& value, olp::dataservice::read::model::Messages& x); } // namespace parser diff --git a/olp-cpp-sdk-dataservice-read/src/generated/parser/ParserWrapper.h b/olp-cpp-sdk-dataservice-read/src/generated/parser/ParserWrapper.h new file mode 100644 index 000000000..284238474 --- /dev/null +++ b/olp-cpp-sdk-dataservice-read/src/generated/parser/ParserWrapper.h @@ -0,0 +1,102 @@ +/* + * Copyright (C) 2019-2026 HERE Europe B.V. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * SPDX-License-Identifier: Apache-2.0 + * License-Filename: LICENSE + */ + +#pragma once + +#include +#include +#include +#include +#include + +#include +#include + +namespace olp { +namespace parser { + +inline void from_json(const boost::json::value& value, std::string& x) { + const auto& str = value.get_string(); + x.assign(str.begin(), str.end()); +} + +inline void from_json(const boost::json::value& value, int32_t& x) { + x = static_cast(value.to_number()); +} + +inline void from_json(const boost::json::value& value, int64_t& x) { + x = value.to_number(); +} + +inline void from_json(const boost::json::value& value, double& x) { + x = value.to_number(); +} + +inline void from_json(const boost::json::value& value, bool& x) { + x = value.get_bool(); +} + +inline void from_json(const boost::json::value& value, + std::shared_ptr>& x) { + const auto& s = value.get_string(); + x = std::make_shared>(s.begin(), s.end()); +} + +template +inline void from_json(const boost::json::value& value, + porting::optional& x) { + T result = T(); + from_json(value, result); + x = result; +} + +template +inline void from_json(const boost::json::value& value, + std::map& results) { + const auto& object = value.get_object(); + for (const auto& object_value : object) { + std::string key = object_value.key(); + from_json(object_value.value(), results[key]); + } +} + +template +inline void from_json(const boost::json::value& value, + std::vector& results) { + const auto& array = value.get_array(); + for (const auto& array_value : array) { + T result; + from_json(array_value, result); + results.emplace_back(std::move(result)); + } +} + +template +inline T parse(const boost::json::value& value, const std::string& name) { + T result = T(); + const auto& object = value.get_object(); + auto itr = object.find(name); + if (itr != object.end()) { + from_json(itr->value(), result); + } + return result; +} + +} // namespace parser +} // namespace olp diff --git a/olp-cpp-sdk-dataservice-read/src/generated/parser/PartitionsParser.cpp b/olp-cpp-sdk-dataservice-read/src/generated/parser/PartitionsParser.cpp index b09c7a370..68e162fe0 100644 --- a/olp-cpp-sdk-dataservice-read/src/generated/parser/PartitionsParser.cpp +++ b/olp-cpp-sdk-dataservice-read/src/generated/parser/PartitionsParser.cpp @@ -1,5 +1,5 @@ /* - * Copyright (C) 2019-2021 HERE Europe B.V. + * Copyright (C) 2019-2026 HERE Europe B.V. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -19,14 +19,15 @@ #include "PartitionsParser.h" -#include +#include + +#include namespace olp { namespace parser { -using dataservice::read::model::Partition; -using dataservice::read::model::Partitions; +namespace model = olp::dataservice::read::model; -void from_json(const rapidjson::Value& value, Partition& x) { +void from_json(const boost::json::value& value, model::Partition& x) { x.SetChecksum(parse>(value, "checksum")); x.SetCompressedDataSize( parse>(value, "compressedDataSize")); @@ -37,8 +38,8 @@ void from_json(const rapidjson::Value& value, Partition& x) { x.SetVersion(parse>(value, "version")); } -void from_json(const rapidjson::Value& value, Partitions& x) { - x.SetPartitions(parse>(value, "partitions")); +void from_json(const boost::json::value& value, model::Partitions& x) { + x.SetPartitions(parse>(value, "partitions")); } } // namespace parser diff --git a/olp-cpp-sdk-dataservice-read/src/generated/parser/PartitionsParser.h b/olp-cpp-sdk-dataservice-read/src/generated/parser/PartitionsParser.h index 120e1129f..f1742538d 100644 --- a/olp-cpp-sdk-dataservice-read/src/generated/parser/PartitionsParser.h +++ b/olp-cpp-sdk-dataservice-read/src/generated/parser/PartitionsParser.h @@ -1,5 +1,5 @@ /* - * Copyright (C) 2019 HERE Europe B.V. + * Copyright (C) 2019-2026 HERE Europe B.V. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -19,17 +19,17 @@ #pragma once -#include +#include #include "olp/dataservice/read/model/Partitions.h" #include namespace olp { namespace parser { -void from_json(const rapidjson::Value& value, +void from_json(const boost::json::value& value, olp::dataservice::read::model::Partition& x); -void from_json(const rapidjson::Value& value, +void from_json(const boost::json::value& value, olp::dataservice::read::model::Partitions& x); } // namespace parser diff --git a/olp-cpp-sdk-dataservice-read/src/generated/parser/StreamOffsetParser.cpp b/olp-cpp-sdk-dataservice-read/src/generated/parser/StreamOffsetParser.cpp index d11ba87e6..70adeab2b 100644 --- a/olp-cpp-sdk-dataservice-read/src/generated/parser/StreamOffsetParser.cpp +++ b/olp-cpp-sdk-dataservice-read/src/generated/parser/StreamOffsetParser.cpp @@ -1,5 +1,5 @@ /* - * Copyright (C) 2020 HERE Europe B.V. + * Copyright (C) 2020-2026 HERE Europe B.V. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -19,13 +19,13 @@ #include "StreamOffsetParser.h" -#include +#include namespace olp { namespace parser { -using namespace olp::dataservice::read; +namespace model = olp::dataservice::read::model; -void from_json(const rapidjson::Value& value, model::StreamOffset& x) { +void from_json(const boost::json::value& value, model::StreamOffset& x) { x.SetPartition(parse(value, "partition")); x.SetOffset(parse(value, "offset")); } diff --git a/olp-cpp-sdk-dataservice-read/src/generated/parser/StreamOffsetParser.h b/olp-cpp-sdk-dataservice-read/src/generated/parser/StreamOffsetParser.h index fdefafc65..ce6b7ef42 100644 --- a/olp-cpp-sdk-dataservice-read/src/generated/parser/StreamOffsetParser.h +++ b/olp-cpp-sdk-dataservice-read/src/generated/parser/StreamOffsetParser.h @@ -1,5 +1,5 @@ /* - * Copyright (C) 2020 HERE Europe B.V. + * Copyright (C) 2020-2026 HERE Europe B.V. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -19,13 +19,13 @@ #pragma once -#include #include +#include namespace olp { namespace parser { -void from_json(const rapidjson::Value& value, +void from_json(const boost::json::value& value, olp::dataservice::read::model::StreamOffset& x); } // namespace parser diff --git a/olp-cpp-sdk-dataservice-read/src/generated/parser/SubscribeResponseParser.cpp b/olp-cpp-sdk-dataservice-read/src/generated/parser/SubscribeResponseParser.cpp index 68d7c7ef8..710f4478f 100644 --- a/olp-cpp-sdk-dataservice-read/src/generated/parser/SubscribeResponseParser.cpp +++ b/olp-cpp-sdk-dataservice-read/src/generated/parser/SubscribeResponseParser.cpp @@ -1,5 +1,5 @@ /* - * Copyright (C) 2020 HERE Europe B.V. + * Copyright (C) 2020-2026 HERE Europe B.V. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -19,13 +19,15 @@ #include "SubscribeResponseParser.h" -#include +#include + +#include namespace olp { namespace parser { -using namespace olp::dataservice::read; +namespace model = olp::dataservice::read::model; -void from_json(const rapidjson::Value& value, model::SubscribeResponse& x) { +void from_json(const boost::json::value& value, model::SubscribeResponse& x) { x.SetNodeBaseURL(parse(value, "nodeBaseURL")); x.SetSubscriptionId(parse(value, "subscriptionId")); } diff --git a/olp-cpp-sdk-dataservice-read/src/generated/parser/SubscribeResponseParser.h b/olp-cpp-sdk-dataservice-read/src/generated/parser/SubscribeResponseParser.h index 226922b5a..283bb76a4 100644 --- a/olp-cpp-sdk-dataservice-read/src/generated/parser/SubscribeResponseParser.h +++ b/olp-cpp-sdk-dataservice-read/src/generated/parser/SubscribeResponseParser.h @@ -1,5 +1,5 @@ /* - * Copyright (C) 2020 HERE Europe B.V. + * Copyright (C) 2020-2026 HERE Europe B.V. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -19,13 +19,13 @@ #pragma once -#include +#include #include "generated/model/SubscribeResponse.h" namespace olp { namespace parser { -void from_json(const rapidjson::Value& value, +void from_json(const boost::json::value& value, olp::dataservice::read::model::SubscribeResponse& x); } // namespace parser diff --git a/olp-cpp-sdk-dataservice-read/src/generated/parser/VersionInfosParser.cpp b/olp-cpp-sdk-dataservice-read/src/generated/parser/VersionInfosParser.cpp index dc71aebac..3b38f9fc0 100644 --- a/olp-cpp-sdk-dataservice-read/src/generated/parser/VersionInfosParser.cpp +++ b/olp-cpp-sdk-dataservice-read/src/generated/parser/VersionInfosParser.cpp @@ -1,5 +1,5 @@ /* - * Copyright (C) 2020 HERE Europe B.V. + * Copyright (C) 2020-2026 HERE Europe B.V. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -20,21 +20,22 @@ #include "VersionInfosParser.h" #include +#include #include -#include +#include namespace olp { namespace parser { namespace model = olp::dataservice::read::model; -void from_json(const rapidjson::Value& value, model::VersionDependency& x) { +void from_json(const boost::json::value& value, model::VersionDependency& x) { x.SetHrn(parse(value, "hrn")); x.SetVersion(parse(value, "version")); x.SetDirect(parse(value, "direct")); } -void from_json(const rapidjson::Value& value, model::VersionInfo& x) { +void from_json(const boost::json::value& value, model::VersionInfo& x) { x.SetDependencies( parse>(value, "dependencies")); x.SetTimestamp(parse(value, "timestamp")); @@ -43,7 +44,7 @@ void from_json(const rapidjson::Value& value, model::VersionInfo& x) { parse>(value, "partitionCounts")); } -void from_json(const rapidjson::Value& value, model::VersionInfos& x) { +void from_json(const boost::json::value& value, model::VersionInfos& x) { x.SetVersions(parse>(value, "versions")); } diff --git a/olp-cpp-sdk-dataservice-read/src/generated/parser/VersionInfosParser.h b/olp-cpp-sdk-dataservice-read/src/generated/parser/VersionInfosParser.h index bd692e6a8..3934a9abb 100644 --- a/olp-cpp-sdk-dataservice-read/src/generated/parser/VersionInfosParser.h +++ b/olp-cpp-sdk-dataservice-read/src/generated/parser/VersionInfosParser.h @@ -1,5 +1,5 @@ /* - * Copyright (C) 2020 HERE Europe B.V. + * Copyright (C) 2020-2026 HERE Europe B.V. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -19,18 +19,18 @@ #pragma once -#include +#include #include "olp/dataservice/read/model/VersionInfos.h" namespace olp { namespace parser { -void from_json(const rapidjson::Value& value, +void from_json(const boost::json::value& value, olp::dataservice::read::model::VersionDependency& x); -void from_json(const rapidjson::Value& value, +void from_json(const boost::json::value& value, olp::dataservice::read::model::VersionInfo& x); -void from_json(const rapidjson::Value& value, +void from_json(const boost::json::value& value, olp::dataservice::read::model::VersionInfos& x); } // namespace parser diff --git a/olp-cpp-sdk-dataservice-read/src/generated/parser/VersionResponseParser.cpp b/olp-cpp-sdk-dataservice-read/src/generated/parser/VersionResponseParser.cpp index 107594f85..20dd8f6b4 100644 --- a/olp-cpp-sdk-dataservice-read/src/generated/parser/VersionResponseParser.cpp +++ b/olp-cpp-sdk-dataservice-read/src/generated/parser/VersionResponseParser.cpp @@ -1,5 +1,5 @@ /* - * Copyright (C) 2019 HERE Europe B.V. + * Copyright (C) 2019-2026 HERE Europe B.V. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -19,13 +19,13 @@ #include "VersionResponseParser.h" -#include +#include namespace olp { namespace parser { -using namespace olp::dataservice::read; +namespace model = olp::dataservice::read::model; -void from_json(const rapidjson::Value& value, model::VersionResponse& x) { +void from_json(const boost::json::value& value, model::VersionResponse& x) { x.SetVersion(parse(value, "version")); } diff --git a/olp-cpp-sdk-dataservice-read/src/generated/parser/VersionResponseParser.h b/olp-cpp-sdk-dataservice-read/src/generated/parser/VersionResponseParser.h index 4c57d9344..a0e595e8a 100644 --- a/olp-cpp-sdk-dataservice-read/src/generated/parser/VersionResponseParser.h +++ b/olp-cpp-sdk-dataservice-read/src/generated/parser/VersionResponseParser.h @@ -1,5 +1,5 @@ /* - * Copyright (C) 2019 HERE Europe B.V. + * Copyright (C) 2019-2026 HERE Europe B.V. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -19,14 +19,14 @@ #pragma once -#include +#include #include "olp/dataservice/read/model/VersionResponse.h" #include namespace olp { namespace parser { -void from_json(const rapidjson::Value& value, +void from_json(const boost::json::value& value, olp::dataservice::read::model::VersionResponse& x); } // namespace parser diff --git a/olp-cpp-sdk-dataservice-read/src/generated/parser/VersionsResponseParser.cpp b/olp-cpp-sdk-dataservice-read/src/generated/parser/VersionsResponseParser.cpp index 708f7e277..f403d32b5 100644 --- a/olp-cpp-sdk-dataservice-read/src/generated/parser/VersionsResponseParser.cpp +++ b/olp-cpp-sdk-dataservice-read/src/generated/parser/VersionsResponseParser.cpp @@ -1,5 +1,5 @@ /* - * Copyright (C) 2022 HERE Europe B.V. + * Copyright (C) 2022-2026 HERE Europe B.V. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -19,7 +19,9 @@ #include "VersionsResponseParser.h" -#include +#include + +#include namespace olp { namespace parser { @@ -29,18 +31,18 @@ using VersionsResponseEntry = olp::dataservice::read::model::VersionsResponseEntry; using CatalogVersion = olp::dataservice::read::model::CatalogVersion; -void from_json(const rapidjson::Value& value, CatalogVersion& x) { +void from_json(const boost::json::value& value, CatalogVersion& x) { x.SetHrn(parse(value, "hrn")); x.SetVersion(parse(value, "version")); } -void from_json(const rapidjson::Value& value, VersionsResponseEntry& x) { +void from_json(const boost::json::value& value, VersionsResponseEntry& x) { x.SetVersion(parse(value, "version")); x.SetCatalogVersions( parse>(value, "sharedDependencies")); } -void from_json(const rapidjson::Value& value, VersionsResponse& x) { +void from_json(const boost::json::value& value, VersionsResponse& x) { x.SetVersionResponseEntries( parse>(value, "versions")); } diff --git a/olp-cpp-sdk-dataservice-read/src/generated/parser/VersionsResponseParser.h b/olp-cpp-sdk-dataservice-read/src/generated/parser/VersionsResponseParser.h index 8d9eb783e..b12f20a85 100644 --- a/olp-cpp-sdk-dataservice-read/src/generated/parser/VersionsResponseParser.h +++ b/olp-cpp-sdk-dataservice-read/src/generated/parser/VersionsResponseParser.h @@ -1,5 +1,5 @@ /* - * Copyright (C) 2022 HERE Europe B.V. + * Copyright (C) 2022-2026 HERE Europe B.V. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -21,18 +21,17 @@ #include -#include +#include #include "olp/dataservice/read/model/VersionsResponse.h" - namespace olp { namespace parser { -void from_json(const rapidjson::Value& value, +void from_json(const boost::json::value& value, olp::dataservice::read::model::CatalogVersion& x); -void from_json(const rapidjson::Value& value, +void from_json(const boost::json::value& value, olp::dataservice::read::model::VersionsResponseEntry& x); -void from_json(const rapidjson::Value& value, +void from_json(const boost::json::value& value, olp::dataservice::read::model::VersionsResponse& x); } // namespace parser diff --git a/olp-cpp-sdk-dataservice-read/src/generated/serializer/ApiSerializer.cpp b/olp-cpp-sdk-dataservice-read/src/generated/serializer/ApiSerializer.cpp index 91a3eae4a..1cd3f2756 100644 --- a/olp-cpp-sdk-dataservice-read/src/generated/serializer/ApiSerializer.cpp +++ b/olp-cpp-sdk-dataservice-read/src/generated/serializer/ApiSerializer.cpp @@ -1,5 +1,5 @@ /* - * Copyright (C) 2019 HERE Europe B.V. + * Copyright (C) 2019-2026 HERE Europe B.V. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -17,21 +17,21 @@ * License-Filename: LICENSE */ -#include +#include #include "ApiSerializer.h" -#include +#include namespace olp { namespace serializer { -void to_json(const dataservice::read::model::Api& x, rapidjson::Value& value, - rapidjson::Document::AllocatorType& allocator) { - value.SetObject(); - serialize("api", x.GetApi(), value, allocator); - serialize("version", x.GetVersion(), value, allocator); - serialize("baseURL", x.GetBaseUrl(), value, allocator); - serialize("parameters", x.GetParameters(), value, allocator); +void to_json(const dataservice::read::model::Api& x, + boost::json::value& value) { + auto& object = value.emplace_object(); + serialize("api", x.GetApi(), object); + serialize("version", x.GetVersion(), object); + serialize("baseURL", x.GetBaseUrl(), object); + serialize("parameters", x.GetParameters(), object); } } // namespace serializer } // namespace olp diff --git a/olp-cpp-sdk-dataservice-read/src/generated/serializer/ApiSerializer.h b/olp-cpp-sdk-dataservice-read/src/generated/serializer/ApiSerializer.h index 0e5b9bc06..67fea5f80 100644 --- a/olp-cpp-sdk-dataservice-read/src/generated/serializer/ApiSerializer.h +++ b/olp-cpp-sdk-dataservice-read/src/generated/serializer/ApiSerializer.h @@ -1,5 +1,5 @@ /* - * Copyright (C) 2019 HERE Europe B.V. + * Copyright (C) 2019-2026 HERE Europe B.V. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -21,14 +21,12 @@ #include -#include +#include #include "generated/model/Api.h" namespace olp { namespace serializer { -void to_json(const dataservice::read::model::Api& x, - rapidjson::Value& value, - rapidjson::Document::AllocatorType& allocator); +void to_json(const dataservice::read::model::Api& x, boost::json::value& value); } // namespace serializer } // namespace olp diff --git a/olp-cpp-sdk-dataservice-read/src/generated/serializer/CatalogSerializer.cpp b/olp-cpp-sdk-dataservice-read/src/generated/serializer/CatalogSerializer.cpp index 8ca3a88d1..3a7c6fa1b 100644 --- a/olp-cpp-sdk-dataservice-read/src/generated/serializer/CatalogSerializer.cpp +++ b/olp-cpp-sdk-dataservice-read/src/generated/serializer/CatalogSerializer.cpp @@ -1,5 +1,5 @@ /* - * Copyright (C) 2019 HERE Europe B.V. + * Copyright (C) 2019-2026 HERE Europe B.V. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -17,140 +17,129 @@ * License-Filename: LICENSE */ -#include +#include #include "CatalogSerializer.h" -#include +#include namespace olp { namespace serializer { void to_json(const dataservice::read::model::Coverage& x, - rapidjson::Value& value, - rapidjson::Document::AllocatorType& allocator) { - value.SetObject(); - serialize("adminAreas", x.GetAdminAreas(), value, allocator); + boost::json::value& value) { + auto& object = value.emplace_object(); + serialize("adminAreas", x.GetAdminAreas(), object); } void to_json(const dataservice::read::model::IndexDefinition& x, - rapidjson::Value& value, - rapidjson::Document::AllocatorType& allocator) { - value.SetObject(); - serialize("name", x.GetName(), value, allocator); - serialize("type", x.GetType(), value, allocator); - serialize("duration", x.GetDuration(), value, allocator); - serialize("zoomLevel", x.GetZoomLevel(), value, allocator); + boost::json::value& value) { + auto& object = value.emplace_object(); + serialize("name", x.GetName(), object); + serialize("type", x.GetType(), object); + serialize("duration", x.GetDuration(), object); + serialize("zoomLevel", x.GetZoomLevel(), object); } void to_json(const dataservice::read::model::IndexProperties& x, - rapidjson::Value& value, - rapidjson::Document::AllocatorType& allocator) { - value.SetObject(); - serialize("ttl", x.GetTtl(), value, allocator); - serialize("indexDefinitions", x.GetIndexDefinitions(), value, allocator); + boost::json::value& value) { + auto& object = value.emplace_object(); + serialize("ttl", x.GetTtl(), object); + serialize("indexDefinitions", x.GetIndexDefinitions(), object); } void to_json(const dataservice::read::model::Creator& x, - rapidjson::Value& value, - rapidjson::Document::AllocatorType& allocator) { - value.SetObject(); - serialize("id", x.GetId(), value, allocator); + boost::json::value& value) { + auto& object = value.emplace_object(); + serialize("id", x.GetId(), object); } -void to_json(const dataservice::read::model::Owner& x, rapidjson::Value& value, - rapidjson::Document::AllocatorType& allocator) { - value.SetObject(); - serialize("creator", x.GetCreator(), value, allocator); - serialize("organisation", x.GetOrganisation(), value, allocator); +void to_json(const dataservice::read::model::Owner& x, + boost::json::value& value) { + auto& object = value.emplace_object(); + serialize("creator", x.GetCreator(), object); + serialize("organisation", x.GetOrganisation(), object); } void to_json(const dataservice::read::model::Partitioning& x, - rapidjson::Value& value, - rapidjson::Document::AllocatorType& allocator) { - value.SetObject(); - serialize("scheme", x.GetScheme(), value, allocator); - serialize("tileLevels", x.GetTileLevels(), value, allocator); + boost::json::value& value) { + auto& object = value.emplace_object(); + serialize("scheme", x.GetScheme(), object); + serialize("tileLevels", x.GetTileLevels(), object); } -void to_json(const dataservice::read::model::Schema& x, rapidjson::Value& value, - rapidjson::Document::AllocatorType& allocator) { - value.SetObject(); - serialize("hrn", x.GetHrn(), value, allocator); +void to_json(const dataservice::read::model::Schema& x, + boost::json::value& value) { + auto& object = value.emplace_object(); + serialize("hrn", x.GetHrn(), object); } void to_json(const dataservice::read::model::StreamProperties& x, - rapidjson::Value& value, - rapidjson::Document::AllocatorType& allocator) { - value.SetObject(); - serialize("dataInThroughputMbps", x.GetDataInThroughputMbps(), value, - allocator); - serialize("dataOutThroughputMbps", x.GetDataOutThroughputMbps(), value, - allocator); + boost::json::value& value) { + auto& object = value.emplace_object(); + serialize("dataInThroughputMbps", x.GetDataInThroughputMbps(), object); + serialize("dataOutThroughputMbps", x.GetDataOutThroughputMbps(), object); } void to_json(const dataservice::read::model::Encryption& x, - rapidjson::Value& value, - rapidjson::Document::AllocatorType& allocator) { - value.SetObject(); - serialize("algorithm", x.GetAlgorithm(), value, allocator); + boost::json::value& value) { + auto& object = value.emplace_object(); + serialize("algorithm", x.GetAlgorithm(), object); } -void to_json(const dataservice::read::model::Volume& x, rapidjson::Value& value, - rapidjson::Document::AllocatorType& allocator) { - value.SetObject(); - serialize("volumeType", x.GetVolumeType(), value, allocator); - serialize("maxMemoryPolicy", x.GetMaxMemoryPolicy(), value, allocator); - serialize("packageType", x.GetPackageType(), value, allocator); - serialize("encryption", x.GetEncryption(), value, allocator); +void to_json(const dataservice::read::model::Volume& x, + boost::json::value& value) { + auto& object = value.emplace_object(); + serialize("volumeType", x.GetVolumeType(), object); + serialize("maxMemoryPolicy", x.GetMaxMemoryPolicy(), object); + serialize("packageType", x.GetPackageType(), object); + serialize("encryption", x.GetEncryption(), object); } -void to_json(const dataservice::read::model::Layer& x, rapidjson::Value& value, - rapidjson::Document::AllocatorType& allocator) { - value.SetObject(); - serialize("id", x.GetId(), value, allocator); - serialize("name", x.GetName(), value, allocator); - serialize("summary", x.GetSummary(), value, allocator); - serialize("description", x.GetDescription(), value, allocator); - serialize("owner", x.GetOwner(), value, allocator); - serialize("coverage", x.GetCoverage(), value, allocator); - serialize("schema", x.GetSchema(), value, allocator); - serialize("contentType", x.GetContentType(), value, allocator); - serialize("contentEncoding", x.GetContentEncoding(), value, allocator); - serialize("partitioning", x.GetPartitioning(), value, allocator); - serialize("layerType", x.GetLayerType(), value, allocator); - serialize("digest", x.GetDigest(), value, allocator); - serialize("tags", x.GetTags(), value, allocator); - serialize("billingTags", x.GetBillingTags(), value, allocator); - serialize("ttl", x.GetTtl(), value, allocator); - serialize("indexProperties", x.GetIndexProperties(), value, allocator); - serialize("streamProperties", x.GetStreamProperties(), value, allocator); - serialize("volume", x.GetVolume(), value, allocator); +void to_json(const dataservice::read::model::Layer& x, + boost::json::value& value) { + auto& object = value.emplace_object(); + serialize("id", x.GetId(), object); + serialize("name", x.GetName(), object); + serialize("summary", x.GetSummary(), object); + serialize("description", x.GetDescription(), object); + serialize("owner", x.GetOwner(), object); + serialize("coverage", x.GetCoverage(), object); + serialize("schema", x.GetSchema(), object); + serialize("contentType", x.GetContentType(), object); + serialize("contentEncoding", x.GetContentEncoding(), object); + serialize("partitioning", x.GetPartitioning(), object); + serialize("layerType", x.GetLayerType(), object); + serialize("digest", x.GetDigest(), object); + serialize("tags", x.GetTags(), object); + serialize("billingTags", x.GetBillingTags(), object); + serialize("ttl", x.GetTtl(), object); + serialize("indexProperties", x.GetIndexProperties(), object); + serialize("streamProperties", x.GetStreamProperties(), object); + serialize("volume", x.GetVolume(), object); } void to_json(const dataservice::read::model::Notifications& x, - rapidjson::Value& value, - rapidjson::Document::AllocatorType& allocator) { - value.SetObject(); - serialize("enabled", x.GetEnabled(), value, allocator); + boost::json::value& value) { + auto& object = value.emplace_object(); + serialize("enabled", x.GetEnabled(), object); } void to_json(const dataservice::read::model::Catalog& x, - rapidjson::Value& value, - rapidjson::Document::AllocatorType& allocator) { - value.SetObject(); - serialize("id", x.GetId(), value, allocator); - serialize("hrn", x.GetHrn(), value, allocator); - serialize("name", x.GetName(), value, allocator); - serialize("summary", x.GetSummary(), value, allocator); - serialize("description", x.GetDescription(), value, allocator); - serialize("coverage", x.GetCoverage(), value, allocator); - serialize("owner", x.GetOwner(), value, allocator); - serialize("tags", x.GetTags(), value, allocator); - serialize("billingTags", x.GetBillingTags(), value, allocator); - serialize("created", x.GetCreated(), value, allocator); - serialize("layers", x.GetLayers(), value, allocator); - serialize("version", x.GetVersion(), value, allocator); - serialize("notifications", x.GetNotifications(), value, allocator); + boost::json::value& value) { + auto& object = value.emplace_object(); + serialize("id", x.GetId(), object); + serialize("hrn", x.GetHrn(), object); + serialize("name", x.GetName(), object); + serialize("summary", x.GetSummary(), object); + serialize("description", x.GetDescription(), object); + serialize("coverage", x.GetCoverage(), object); + serialize("owner", x.GetOwner(), object); + serialize("tags", x.GetTags(), object); + serialize("billingTags", x.GetBillingTags(), object); + serialize("created", x.GetCreated(), object); + serialize("layers", x.GetLayers(), object); + serialize("version", x.GetVersion(), object); + serialize("notifications", x.GetNotifications(), object); } } // namespace serializer diff --git a/olp-cpp-sdk-dataservice-read/src/generated/serializer/CatalogSerializer.h b/olp-cpp-sdk-dataservice-read/src/generated/serializer/CatalogSerializer.h index 6d9417162..12406cb32 100644 --- a/olp-cpp-sdk-dataservice-read/src/generated/serializer/CatalogSerializer.h +++ b/olp-cpp-sdk-dataservice-read/src/generated/serializer/CatalogSerializer.h @@ -1,5 +1,5 @@ /* - * Copyright (C) 2019 HERE Europe B.V. + * Copyright (C) 2019-2026 HERE Europe B.V. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -19,63 +19,50 @@ #pragma once -#include +#include #include "olp/dataservice/read/model/Catalog.h" namespace olp { namespace serializer { void to_json(const dataservice::read::model::Coverage& x, - rapidjson::Value& value, - rapidjson::Document::AllocatorType& allocator); + boost::json::value& value); void to_json(const dataservice::read::model::IndexDefinition& x, - rapidjson::Value& value, - rapidjson::Document::AllocatorType& allocator); + boost::json::value& value); void to_json(const dataservice::read::model::IndexProperties& x, - rapidjson::Value& value, - rapidjson::Document::AllocatorType& allocator); + boost::json::value& value); void to_json(const dataservice::read::model::Creator& x, - rapidjson::Value& value, - rapidjson::Document::AllocatorType& allocator); + boost::json::value& value); void to_json(const dataservice::read::model::Owner& x, - rapidjson::Value& value, - rapidjson::Document::AllocatorType& allocator); + boost::json::value& value); void to_json(const dataservice::read::model::Partitioning& x, - rapidjson::Value& value, - rapidjson::Document::AllocatorType& allocator); + boost::json::value& value); void to_json(const dataservice::read::model::Schema& x, - rapidjson::Value& value, - rapidjson::Document::AllocatorType& allocator); + boost::json::value& value); void to_json(const dataservice::read::model::StreamProperties& x, - rapidjson::Value& value, - rapidjson::Document::AllocatorType& allocator); + boost::json::value& value); void to_json(const dataservice::read::model::Encryption& x, - rapidjson::Value& value, - rapidjson::Document::AllocatorType& allocator); + boost::json::value& value); void to_json(const dataservice::read::model::Volume& x, - rapidjson::Value& value, - rapidjson::Document::AllocatorType& allocator); + boost::json::value& value); void to_json(const dataservice::read::model::Layer& x, - rapidjson::Value& value, - rapidjson::Document::AllocatorType& allocator); + boost::json::value& value); void to_json(const dataservice::read::model::Notifications& x, - rapidjson::Value& value, - rapidjson::Document::AllocatorType& allocator); + boost::json::value& value); void to_json(const dataservice::read::model::Catalog& x, - rapidjson::Value& value, - rapidjson::Document::AllocatorType& allocator); + boost::json::value& value); } // namespace serializer } // namespace olp diff --git a/olp-cpp-sdk-dataservice-read/src/generated/serializer/CatalogVersionsSerializer.h b/olp-cpp-sdk-dataservice-read/src/generated/serializer/CatalogVersionsSerializer.h index 50bd3898e..5fbb8c77c 100644 --- a/olp-cpp-sdk-dataservice-read/src/generated/serializer/CatalogVersionsSerializer.h +++ b/olp-cpp-sdk-dataservice-read/src/generated/serializer/CatalogVersionsSerializer.h @@ -1,5 +1,5 @@ /* - * Copyright (C) 2022 HERE Europe B.V. + * Copyright (C) 2022-2026 HERE Europe B.V. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -19,35 +19,37 @@ #pragma once -#include +#include +#include + +#include #include -#include +#include namespace olp { namespace serializer { inline void to_json(const dataservice::read::model::CatalogVersion& x, - rapidjson::Value& value, - rapidjson::Document::AllocatorType& allocator) { - value.SetObject(); - serialize("hrn", x.GetHrn(), value, allocator); - serialize("version", x.GetVersion(), value, allocator); + boost::json::value& value) { + auto& object = value.emplace_object(); + serialize("hrn", x.GetHrn(), object); + serialize("version", x.GetVersion(), object); } template <> inline void to_json( const std::vector& x, - rapidjson::Value& value, rapidjson::Document::AllocatorType& allocator) { - value.SetObject(); - - rapidjson::Value array_value; - array_value.SetArray(); - for (auto itr = x.begin(); itr != x.end(); ++itr) { - rapidjson::Value item_value; - to_json(*itr, item_value, allocator); - array_value.PushBack(std::move(item_value), allocator); + boost::json::value& value) { + auto& object = value.emplace_object(); + + boost::json::array array_value; + for (const auto& version : x) { + boost::json::value item_value; + to_json(version, item_value); + array_value.emplace_back(std::move(item_value)); } - value.AddMember("dependencies", std::move(array_value), allocator); + + object.emplace("dependencies", std::move(array_value)); } } // namespace serializer diff --git a/olp-cpp-sdk-dataservice-read/src/generated/serializer/ConsumerPropertiesSerializer.h b/olp-cpp-sdk-dataservice-read/src/generated/serializer/ConsumerPropertiesSerializer.h index 1dea7c2fe..1c76810e7 100644 --- a/olp-cpp-sdk-dataservice-read/src/generated/serializer/ConsumerPropertiesSerializer.h +++ b/olp-cpp-sdk-dataservice-read/src/generated/serializer/ConsumerPropertiesSerializer.h @@ -1,5 +1,5 @@ /* - * Copyright (C) 2020 HERE Europe B.V. + * Copyright (C) 2020-2026 HERE Europe B.V. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -19,9 +19,11 @@ #pragma once -#include -#include +#include + +#include #include +#include namespace olp { namespace serializer { @@ -29,18 +31,17 @@ namespace serializer { template <> inline void to_json( const std::vector& x, - rapidjson::Value& value, rapidjson::Document::AllocatorType& allocator) { - value.SetObject(); - for (auto itr = x.begin(); itr != x.end(); ++itr) { - serialize(itr->GetKey(), itr->GetValue(), value, allocator); + boost::json::value& value) { + auto& object = value.emplace_object(); + for (const auto& option : x) { + serialize(option.GetKey(), option.GetValue(), object); } } inline void to_json(const dataservice::read::ConsumerProperties& x, - rapidjson::Value& value, - rapidjson::Document::AllocatorType& allocator) { - value.SetObject(); - serialize("kafkaConsumerProperties", x.GetProperties(), value, allocator); + boost::json::value& value) { + auto& object = value.emplace_object(); + serialize("kafkaConsumerProperties", x.GetProperties(), object); } } // namespace serializer diff --git a/olp-cpp-sdk-dataservice-read/src/generated/serializer/JsonSerializer.h b/olp-cpp-sdk-dataservice-read/src/generated/serializer/JsonSerializer.h index 399346219..f023aba1a 100644 --- a/olp-cpp-sdk-dataservice-read/src/generated/serializer/JsonSerializer.h +++ b/olp-cpp-sdk-dataservice-read/src/generated/serializer/JsonSerializer.h @@ -1,5 +1,5 @@ /* - * Copyright (C) 2019-2024 HERE Europe B.V. + * Copyright (C) 2019-2026 HERE Europe B.V. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -19,9 +19,13 @@ #pragma once -#include -#include -#include +#include +#include +#include + +#include +#include +#include #include "ByteVectorBuffer.h" @@ -29,30 +33,28 @@ namespace olp { namespace serializer { template inline std::string serialize(const T& object) { - rapidjson::Document doc; - auto& allocator = doc.GetAllocator(); - - doc.SetObject(); - to_json(object, doc, allocator); - - rapidjson::StringBuffer buffer; - rapidjson::Writer writer(buffer); - doc.Accept(writer); - return buffer.GetString(); + boost::json::value value; + to_json(object, value); + return boost::json::serialize(value); } template inline ByteVectorBuffer::Buffer serialize_bytes(const T& object) { - rapidjson::Document doc; - auto& allocator = doc.GetAllocator(); + boost::json::value value; + to_json(object, value); + + boost::json::serializer serializer; + serializer.reset(&value); + + auto buffer = std::make_shared>(); - doc.SetObject(); - to_json(object, doc, allocator); + while (!serializer.done()) { + char temp[4096]; + auto result = serializer.read(temp); + buffer->insert(buffer->end(), temp, temp + result.size()); + } - ByteVectorBuffer buffer; - rapidjson::Writer writer(buffer); - doc.Accept(writer); - return buffer.GetBuffer(); + return buffer; } } // namespace serializer diff --git a/olp-cpp-sdk-dataservice-read/src/generated/serializer/LayerVersionsSerializer.cpp b/olp-cpp-sdk-dataservice-read/src/generated/serializer/LayerVersionsSerializer.cpp index 935fab9fc..f3cc90a10 100644 --- a/olp-cpp-sdk-dataservice-read/src/generated/serializer/LayerVersionsSerializer.cpp +++ b/olp-cpp-sdk-dataservice-read/src/generated/serializer/LayerVersionsSerializer.cpp @@ -1,5 +1,5 @@ /* - * Copyright (C) 2019 HERE Europe B.V. + * Copyright (C) 2019-2026 HERE Europe B.V. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -17,28 +17,26 @@ * License-Filename: LICENSE */ -#include +#include #include "LayerVersionsSerializer.h" -#include +#include namespace olp { namespace serializer { void to_json(const dataservice::read::model::LayerVersion& x, - rapidjson::Value& value, - rapidjson::Document::AllocatorType& allocator) { - value.SetObject(); - serialize("layer", x.GetLayer(), value, allocator); - serialize("version", x.GetVersion(), value, allocator); - serialize("timestamp", x.GetTimestamp(), value, allocator); + boost::json::value& value) { + auto& object = value.emplace_object(); + serialize("layer", x.GetLayer(), object); + serialize("version", x.GetVersion(), object); + serialize("timestamp", x.GetTimestamp(), object); } void to_json(const dataservice::read::model::LayerVersions& x, - rapidjson::Value& value, - rapidjson::Document::AllocatorType& allocator) { - value.SetObject(); - serialize("layerVersions", x.GetLayerVersions(), value, allocator); - serialize("version", x.GetVersion(), value, allocator); + boost::json::value& value) { + auto& object = value.emplace_object(); + serialize("layerVersions", x.GetLayerVersions(), object); + serialize("version", x.GetVersion(), object); } } // namespace serializer } // namespace olp diff --git a/olp-cpp-sdk-dataservice-read/src/generated/serializer/LayerVersionsSerializer.h b/olp-cpp-sdk-dataservice-read/src/generated/serializer/LayerVersionsSerializer.h index bff03a181..e36df1e8f 100644 --- a/olp-cpp-sdk-dataservice-read/src/generated/serializer/LayerVersionsSerializer.h +++ b/olp-cpp-sdk-dataservice-read/src/generated/serializer/LayerVersionsSerializer.h @@ -1,5 +1,5 @@ /* - * Copyright (C) 2019 HERE Europe B.V. + * Copyright (C) 2019-2026 HERE Europe B.V. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -19,19 +19,16 @@ #pragma once -#include +#include #include "generated/model/LayerVersions.h" - namespace olp { namespace serializer { void to_json(const dataservice::read::model::LayerVersion& x, - rapidjson::Value& value, - rapidjson::Document::AllocatorType& allocator); + boost::json::value& value); void to_json(const dataservice::read::model::LayerVersions& x, - rapidjson::Value& value, - rapidjson::Document::AllocatorType& allocator); + boost::json::value& value); } // namespace serializer } // namespace olp diff --git a/olp-cpp-sdk-dataservice-read/src/generated/serializer/PartitionsSerializer.cpp b/olp-cpp-sdk-dataservice-read/src/generated/serializer/PartitionsSerializer.cpp index b7bd4009e..de817e864 100644 --- a/olp-cpp-sdk-dataservice-read/src/generated/serializer/PartitionsSerializer.cpp +++ b/olp-cpp-sdk-dataservice-read/src/generated/serializer/PartitionsSerializer.cpp @@ -1,5 +1,5 @@ /* - * Copyright (C) 2019-2021 HERE Europe B.V. + * Copyright (C) 2019-2026 HERE Europe B.V. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -17,32 +17,30 @@ * License-Filename: LICENSE */ -#include +#include #include "PartitionsSerializer.h" -#include +#include namespace olp { namespace serializer { void to_json(const dataservice::read::model::Partition& x, - rapidjson::Value& value, - rapidjson::Document::AllocatorType& allocator) { - value.SetObject(); - serialize("checksum", x.GetChecksum(), value, allocator); - serialize("compressedDataSize", x.GetCompressedDataSize(), value, allocator); - serialize("dataHandle", x.GetDataHandle(), value, allocator); - serialize("dataSize", x.GetDataSize(), value, allocator); - serialize("crc", x.GetCrc(), value, allocator); - serialize("partition", x.GetPartition(), value, allocator); - serialize("version", x.GetVersion(), value, allocator); + boost::json::value& value) { + auto& object = value.emplace_object(); + serialize("checksum", x.GetChecksum(), object); + serialize("compressedDataSize", x.GetCompressedDataSize(), object); + serialize("dataHandle", x.GetDataHandle(), object); + serialize("dataSize", x.GetDataSize(), object); + serialize("crc", x.GetCrc(), object); + serialize("partition", x.GetPartition(), object); + serialize("version", x.GetVersion(), object); } void to_json(const dataservice::read::model::Partitions& x, - rapidjson::Value& value, - rapidjson::Document::AllocatorType& allocator) { - value.SetObject(); - serialize("partitions", x.GetPartitions(), value, allocator); + boost::json::value& value) { + auto& object = value.emplace_object(); + serialize("partitions", x.GetPartitions(), object); } } // namespace serializer } // namespace olp diff --git a/olp-cpp-sdk-dataservice-read/src/generated/serializer/PartitionsSerializer.h b/olp-cpp-sdk-dataservice-read/src/generated/serializer/PartitionsSerializer.h index 0870aa75c..36ded6b6c 100644 --- a/olp-cpp-sdk-dataservice-read/src/generated/serializer/PartitionsSerializer.h +++ b/olp-cpp-sdk-dataservice-read/src/generated/serializer/PartitionsSerializer.h @@ -1,5 +1,5 @@ /* - * Copyright (C) 2019 HERE Europe B.V. + * Copyright (C) 2019-2026 HERE Europe B.V. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -19,18 +19,16 @@ #pragma once -#include +#include #include "olp/dataservice/read/model/Partitions.h" namespace olp { namespace serializer { void to_json(const dataservice::read::model::Partition& x, - rapidjson::Value& value, - rapidjson::Document::AllocatorType& allocator); + boost::json::value& value); void to_json(const dataservice::read::model::Partitions& x, - rapidjson::Value& value, - rapidjson::Document::AllocatorType& allocator); + boost::json::value& value); } // namespace serializer } // namespace olp diff --git a/olp-cpp-sdk-dataservice-read/src/generated/serializer/SerializerWrapper.h b/olp-cpp-sdk-dataservice-read/src/generated/serializer/SerializerWrapper.h new file mode 100644 index 000000000..7005b9cec --- /dev/null +++ b/olp-cpp-sdk-dataservice-read/src/generated/serializer/SerializerWrapper.h @@ -0,0 +1,102 @@ +/* + * Copyright (C) 2019-2026 HERE Europe B.V. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * SPDX-License-Identifier: Apache-2.0 + * License-Filename: LICENSE + */ + +#pragma once + +#include +#include +#include +#include +#include + +#include +#include + +namespace olp { +namespace serializer { + +inline void to_json(const std::string& x, boost::json::value& value) { + value.emplace_string() = x; +} + +inline void to_json(int32_t x, boost::json::value& value) { + value.emplace_int64() = x; +} + +inline void to_json(int64_t x, boost::json::value& value) { + value.emplace_int64() = x; +} + +inline void to_json(double x, boost::json::value& value) { + value.emplace_double() = x; +} +inline void to_json(bool x, boost::json::value& value) { + value.emplace_bool() = x; +} + +inline void to_json(const std::shared_ptr>& x, + boost::json::value& value) { + value.emplace_string().assign(x->begin(), x->end()); +} + +template +inline void to_json(const porting::optional& x, boost::json::value& value) { + if (x) { + to_json(*x, value); + } else { + value.emplace_null(); + } +} + +template +inline void to_json(const std::map& x, + boost::json::value& value) { + auto& object = value.emplace_object(); + for (auto itr = x.begin(); itr != x.end(); ++itr) { + const auto& key = itr->first; + boost::json::value item_value; + to_json(itr->second, item_value); + object.emplace(key, std::move(item_value)); + } +} + +template +inline void to_json(const std::vector& x, boost::json::value& value) { + auto& array = value.emplace_array(); + array.reserve(x.size()); + for (typename std::vector::const_iterator itr = x.begin(); itr != x.end(); + ++itr) { + boost::json::value item_value; + to_json(*itr, item_value); + array.emplace_back(std::move(item_value)); + } +} + +template +inline void serialize(const std::string& key, const T& x, + boost::json::object& value) { + boost::json::value item_value; + to_json(x, item_value); + if (!item_value.is_null()) { + value.emplace(key, std::move(item_value)); + } +} + +} // namespace serializer +} // namespace olp diff --git a/olp-cpp-sdk-dataservice-read/src/generated/serializer/StreamOffsetsSerializer.cpp b/olp-cpp-sdk-dataservice-read/src/generated/serializer/StreamOffsetsSerializer.cpp index a2e750d63..8fc4c098b 100644 --- a/olp-cpp-sdk-dataservice-read/src/generated/serializer/StreamOffsetsSerializer.cpp +++ b/olp-cpp-sdk-dataservice-read/src/generated/serializer/StreamOffsetsSerializer.cpp @@ -1,5 +1,5 @@ /* - * Copyright (C) 2020 HERE Europe B.V. + * Copyright (C) 2020-2026 HERE Europe B.V. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -19,24 +19,22 @@ #include "StreamOffsetsSerializer.h" -#include +#include namespace olp { namespace serializer { void to_json(const dataservice::read::model::StreamOffset& x, - rapidjson::Value& value, - rapidjson::Document::AllocatorType& allocator) { - value.SetObject(); - serialize("partition", x.GetPartition(), value, allocator); - serialize("offset", x.GetOffset(), value, allocator); + boost::json::value& value) { + auto& object = value.emplace_object(); + serialize("partition", x.GetPartition(), object); + serialize("offset", x.GetOffset(), object); } void to_json(const dataservice::read::model::StreamOffsets& x, - rapidjson::Value& value, - rapidjson::Document::AllocatorType& allocator) { - value.SetObject(); - serialize("offsets", x.GetOffsets(), value, allocator); + boost::json::value& value) { + auto& object = value.emplace_object(); + serialize("offsets", x.GetOffsets(), object); } } // namespace serializer diff --git a/olp-cpp-sdk-dataservice-read/src/generated/serializer/StreamOffsetsSerializer.h b/olp-cpp-sdk-dataservice-read/src/generated/serializer/StreamOffsetsSerializer.h index f301dfc33..149a8d7e5 100644 --- a/olp-cpp-sdk-dataservice-read/src/generated/serializer/StreamOffsetsSerializer.h +++ b/olp-cpp-sdk-dataservice-read/src/generated/serializer/StreamOffsetsSerializer.h @@ -1,5 +1,5 @@ /* - * Copyright (C) 2020 HERE Europe B.V. + * Copyright (C) 2020-2026 HERE Europe B.V. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -19,19 +19,17 @@ #pragma once -#include #include +#include namespace olp { namespace serializer { void to_json(const dataservice::read::model::StreamOffset& x, - rapidjson::Value& value, - rapidjson::Document::AllocatorType& allocator); + boost::json::value& value); void to_json(const dataservice::read::model::StreamOffsets& x, - rapidjson::Value& value, - rapidjson::Document::AllocatorType& allocator); + boost::json::value& value); } // namespace serializer } // namespace olp diff --git a/olp-cpp-sdk-dataservice-read/src/generated/serializer/VersionInfosSerializer.cpp b/olp-cpp-sdk-dataservice-read/src/generated/serializer/VersionInfosSerializer.cpp index d24b124da..0386cb66d 100644 --- a/olp-cpp-sdk-dataservice-read/src/generated/serializer/VersionInfosSerializer.cpp +++ b/olp-cpp-sdk-dataservice-read/src/generated/serializer/VersionInfosSerializer.cpp @@ -1,5 +1,5 @@ /* - * Copyright (C) 2020 HERE Europe B.V. + * Copyright (C) 2020-2026 HERE Europe B.V. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -19,35 +19,32 @@ #include "VersionInfosSerializer.h" -#include +#include namespace olp { namespace serializer { void to_json(const dataservice::read::model::VersionDependency& x, - rapidjson::Value& value, - rapidjson::Document::AllocatorType& allocator) { - value.SetObject(); - serialize("hrn", x.GetHrn(), value, allocator); - serialize("version", x.GetVersion(), value, allocator); - serialize("direct", x.GetDirect(), value, allocator); + boost::json::value& value) { + auto& object = value.emplace_object(); + serialize("hrn", x.GetHrn(), object); + serialize("version", x.GetVersion(), object); + serialize("direct", x.GetDirect(), object); } void to_json(const dataservice::read::model::VersionInfo& x, - rapidjson::Value& value, - rapidjson::Document::AllocatorType& allocator) { - value.SetObject(); - serialize("dependencies", x.GetDependencies(), value, allocator); - serialize("timestamp", x.GetTimestamp(), value, allocator); - serialize("version", x.GetVersion(), value, allocator); - serialize("partitionCounts", x.GetPartitionCounts(), value, allocator); + boost::json::value& value) { + auto& object = value.emplace_object(); + serialize("dependencies", x.GetDependencies(), object); + serialize("timestamp", x.GetTimestamp(), object); + serialize("version", x.GetVersion(), object); + serialize("partitionCounts", x.GetPartitionCounts(), object); } void to_json(const dataservice::read::model::VersionInfos& x, - rapidjson::Value& value, - rapidjson::Document::AllocatorType& allocator) { - value.SetObject(); - serialize("versions", x.GetVersions(), value, allocator); + boost::json::value& value) { + auto& object = value.emplace_object(); + serialize("versions", x.GetVersions(), object); } } // namespace serializer } // namespace olp diff --git a/olp-cpp-sdk-dataservice-read/src/generated/serializer/VersionInfosSerializer.h b/olp-cpp-sdk-dataservice-read/src/generated/serializer/VersionInfosSerializer.h index 2d950baf0..3775170af 100644 --- a/olp-cpp-sdk-dataservice-read/src/generated/serializer/VersionInfosSerializer.h +++ b/olp-cpp-sdk-dataservice-read/src/generated/serializer/VersionInfosSerializer.h @@ -1,5 +1,5 @@ /* - * Copyright (C) 2020 HERE Europe B.V. + * Copyright (C) 2020-2026 HERE Europe B.V. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -19,22 +19,19 @@ #pragma once -#include +#include #include "olp/dataservice/read/model/VersionInfos.h" namespace olp { namespace serializer { void to_json(const dataservice::read::model::VersionDependency& x, - rapidjson::Value& value, - rapidjson::Document::AllocatorType& allocator); + boost::json::value& value); void to_json(const dataservice::read::model::VersionInfo& x, - rapidjson::Value& value, - rapidjson::Document::AllocatorType& allocator); + boost::json::value& value); void to_json(const dataservice::read::model::VersionInfos& x, - rapidjson::Value& value, - rapidjson::Document::AllocatorType& allocator); + boost::json::value& value); } // namespace serializer } // namespace olp diff --git a/olp-cpp-sdk-dataservice-read/src/generated/serializer/VersionResponseSerializer.cpp b/olp-cpp-sdk-dataservice-read/src/generated/serializer/VersionResponseSerializer.cpp index ec4e2a4d8..ced2b121e 100644 --- a/olp-cpp-sdk-dataservice-read/src/generated/serializer/VersionResponseSerializer.cpp +++ b/olp-cpp-sdk-dataservice-read/src/generated/serializer/VersionResponseSerializer.cpp @@ -1,5 +1,5 @@ /* - * Copyright (C) 2019 HERE Europe B.V. + * Copyright (C) 2019-2026 HERE Europe B.V. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -17,19 +17,18 @@ * License-Filename: LICENSE */ -#include +#include #include "VersionResponseSerializer.h" -#include +#include namespace olp { namespace serializer { void to_json(const dataservice::read::model::VersionResponse& x, - rapidjson::Value& value, - rapidjson::Document::AllocatorType& allocator) { - value.SetObject(); - serialize("version", x.GetVersion(), value, allocator); + boost::json::value& value) { + auto& object = value.emplace_object(); + serialize("version", x.GetVersion(), object); } } // namespace serializer } // namespace olp diff --git a/olp-cpp-sdk-dataservice-read/src/generated/serializer/VersionResponseSerializer.h b/olp-cpp-sdk-dataservice-read/src/generated/serializer/VersionResponseSerializer.h index af3c4f774..e68387478 100644 --- a/olp-cpp-sdk-dataservice-read/src/generated/serializer/VersionResponseSerializer.h +++ b/olp-cpp-sdk-dataservice-read/src/generated/serializer/VersionResponseSerializer.h @@ -1,5 +1,5 @@ /* - * Copyright (C) 2019 HERE Europe B.V. + * Copyright (C) 2019-2026 HERE Europe B.V. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -19,14 +19,13 @@ #pragma once -#include +#include #include "olp/dataservice/read/model/VersionResponse.h" namespace olp { namespace serializer { void to_json(const dataservice::read::model::VersionResponse& x, - rapidjson::Value& value, - rapidjson::Document::AllocatorType& allocator); + boost::json::value& value); } // namespace serializer } // namespace olp diff --git a/olp-cpp-sdk-dataservice-read/src/repositories/AsyncJsonStream.h b/olp-cpp-sdk-dataservice-read/src/repositories/AsyncJsonStream.h index a2adad3f3..190a92a5f 100644 --- a/olp-cpp-sdk-dataservice-read/src/repositories/AsyncJsonStream.h +++ b/olp-cpp-sdk-dataservice-read/src/repositories/AsyncJsonStream.h @@ -20,6 +20,7 @@ #pragma once #include +#include #include #include @@ -32,7 +33,7 @@ namespace dataservice { namespace read { namespace repository { -/// Json byte stream class. Implements rapidjson input stream concept. +/// Json byte stream class. Implements json input stream concept. class JsonByteStream { public: typedef char Ch; diff --git a/olp-cpp-sdk-dataservice-read/src/repositories/PartitionsCacheRepository.cpp b/olp-cpp-sdk-dataservice-read/src/repositories/PartitionsCacheRepository.cpp index 55701ce85..e730f1ea3 100644 --- a/olp-cpp-sdk-dataservice-read/src/repositories/PartitionsCacheRepository.cpp +++ b/olp-cpp-sdk-dataservice-read/src/repositories/PartitionsCacheRepository.cpp @@ -1,5 +1,5 @@ /* - * Copyright (C) 2019-2025 HERE Europe B.V. + * Copyright (C) 2019-2026 HERE Europe B.V. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -32,8 +32,8 @@ #include "generated/parser/PartitionsParser.h" #include "generated/parser/LayerVersionsParser.h" #include "JsonResultParser.h" -#include -#include +#include +#include #include "generated/serializer/PartitionsSerializer.h" #include "generated/serializer/LayerVersionsSerializer.h" #include "generated/serializer/JsonSerializer.h" diff --git a/olp-cpp-sdk-dataservice-read/src/repositories/QuadTreeIndex.cpp b/olp-cpp-sdk-dataservice-read/src/repositories/QuadTreeIndex.cpp index 53dcb75bb..8a946b015 100644 --- a/olp-cpp-sdk-dataservice-read/src/repositories/QuadTreeIndex.cpp +++ b/olp-cpp-sdk-dataservice-read/src/repositories/QuadTreeIndex.cpp @@ -1,5 +1,5 @@ /* - * Copyright (C) 2020-2025 HERE Europe B.V. + * Copyright (C) 2020-2026 HERE Europe B.V. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -23,9 +23,8 @@ #include #include -#include -#include -#include +#include +#include #include "BlobDataReader.h" #include "BlobDataWriter.h" @@ -46,33 +45,37 @@ constexpr auto kCompressedDataSizeKey = "compressedDataSize"; constexpr auto kCrcKey = "crc"; constexpr auto kLogTag = "QuadTreeIndex"; -QuadTreeIndex::IndexData ParseCommonIndexData(rapidjson::Value& value) { +QuadTreeIndex::IndexData ParseCommonIndexData(boost::json::object& obj) { QuadTreeIndex::IndexData data; - const auto obj = value.GetObject(); - if (obj.HasMember(kAdditionalMetadataKey) && - obj[kAdditionalMetadataKey].IsString()) { - data.additional_metadata = obj[kAdditionalMetadataKey].GetString(); + if (obj.contains(kAdditionalMetadataKey) && + obj[kAdditionalMetadataKey].is_string()) { + data.additional_metadata = obj[kAdditionalMetadataKey].get_string().c_str(); } - if (obj.HasMember(kChecksumKey) && obj[kChecksumKey].IsString()) { - data.checksum = obj[kChecksumKey].GetString(); + if (obj.contains(kChecksumKey) && obj[kChecksumKey].is_string()) { + data.checksum = obj[kChecksumKey].get_string().c_str(); } - if (obj.HasMember(kCrcKey) && obj[kCrcKey].IsString()) { - data.crc = obj[kCrcKey].GetString(); + if (obj.contains(kCrcKey) && obj[kCrcKey].is_string()) { + data.crc = obj[kCrcKey].get_string().c_str(); } - if (obj.HasMember(kDataSizeKey) && obj[kDataSizeKey].IsInt64()) { - data.data_size = obj[kDataSizeKey].GetInt64(); + if (auto* data_size = obj.if_contains(kDataSizeKey)) { + if (data_size->is_uint64() || data_size->is_int64()) { + data.data_size = data_size->to_number(); + } } - if (obj.HasMember(kCompressedDataSizeKey) && - obj[kCompressedDataSizeKey].IsInt64()) { - data.compressed_data_size = obj[kCompressedDataSizeKey].GetInt64(); + if (auto* data_size = obj.if_contains(kCompressedDataSizeKey)) { + if (data_size->is_uint64() || data_size->is_int64()) { + data.compressed_data_size = data_size->to_number(); + } } - if (obj.HasMember(kVersionKey) && obj[kVersionKey].IsUint64()) { - data.version = obj[kVersionKey].GetUint64(); + if (auto* version = obj.if_contains(kVersionKey)) { + if (version->is_uint64() || version->is_int64()) { + data.version = version->to_number(); + } } return data; } @@ -101,58 +104,62 @@ QuadTreeIndex::QuadTreeIndex(const cache::KeyValueCache::ValueTypePtr& data) { QuadTreeIndex::QuadTreeIndex(const geo::TileKey& root, int depth, std::stringstream& json_stream) { - rapidjson::Document doc; + boost::json::error_code ec; + auto parsed_value = boost::json::parse(json_stream, ec); - rapidjson::IStreamWrapper stream(json_stream); - doc.ParseStream(stream); - - if (!doc.IsObject()) { + if (!parsed_value.is_object()) { return; } - std::vector subs; - std::vector parents; + auto& top_object = parsed_value.as_object(); - auto parent_quads_value = doc.FindMember(kParentQuadsKey); - auto sub_quads_value = doc.FindMember(kSubQuadsKey); + auto parent_quads_value = top_object.find(kParentQuadsKey); + auto sub_quads_value = top_object.find(kSubQuadsKey); - if (parent_quads_value == doc.MemberEnd() && - sub_quads_value == doc.MemberEnd()) { + if (parent_quads_value == top_object.end() && + sub_quads_value == top_object.end()) { return; } - if (parent_quads_value != doc.MemberEnd() && - parent_quads_value->value.IsArray()) { - parents.reserve(parent_quads_value->value.Size()); - for (auto& value : parent_quads_value->value.GetArray()) { - auto obj = value.GetObject(); + std::vector subs; + std::vector parents; - if (!obj.HasMember(kDataHandleKey) || !obj[kDataHandleKey].IsString() || - !obj.HasMember(kPartitionKey) || !obj[kPartitionKey].IsString()) { + if (parent_quads_value != top_object.end() && + parent_quads_value->value().is_array()) { + auto& parent_quads = parent_quads_value->value().as_array(); + parents.reserve(parent_quads.size()); + for (auto& value : parent_quads) { + auto& obj = value.as_object(); + + if (!obj.contains(kDataHandleKey) || !obj[kDataHandleKey].is_string() || + !obj.contains(kPartitionKey) || !obj[kPartitionKey].is_string()) { continue; } - IndexData data = ParseCommonIndexData(value); - data.data_handle = obj[kDataHandleKey].GetString(); + IndexData data = ParseCommonIndexData(obj); + data.data_handle = obj[kDataHandleKey].as_string().c_str(); data.tile_key = - geo::TileKey::FromHereTile(obj[kPartitionKey].GetString()); + geo::TileKey::FromHereTile(obj[kPartitionKey].as_string().c_str()); parents.push_back(std::move(data)); } } - if (sub_quads_value != doc.MemberEnd() && sub_quads_value->value.IsArray()) { - subs.reserve(sub_quads_value->value.Size()); - for (auto& value : sub_quads_value->value.GetArray()) { - auto obj = value.GetObject(); + if (sub_quads_value != top_object.end() && + sub_quads_value->value().is_array()) { + auto& sub_quads = sub_quads_value->value().as_array(); + subs.reserve(sub_quads.size()); + for (auto& value : sub_quads) { + auto obj = value.as_object(); - if (!obj.HasMember(kDataHandleKey) || !obj[kDataHandleKey].IsString() || - !obj.HasMember(kSubQuadKeyKey) || !obj[kSubQuadKeyKey].IsString()) { + if (!obj.contains(kDataHandleKey) || !obj[kDataHandleKey].is_string() || + !obj.contains(kSubQuadKeyKey) || !obj[kSubQuadKeyKey].is_string()) { continue; } - IndexData data = ParseCommonIndexData(value); - data.data_handle = obj[kDataHandleKey].GetString(); - data.tile_key = root.AddedSubHereTile(obj[kSubQuadKeyKey].GetString()); + IndexData data = ParseCommonIndexData(obj); + data.data_handle = obj[kDataHandleKey].as_string().c_str(); + data.tile_key = + root.AddedSubHereTile(obj[kSubQuadKeyKey].as_string().c_str()); subs.push_back(std::move(data)); } } diff --git a/olp-cpp-sdk-dataservice-read/tests/ParserTest.cpp b/olp-cpp-sdk-dataservice-read/tests/ParserTest.cpp index 0fffd77c3..9ef99df20 100644 --- a/olp-cpp-sdk-dataservice-read/tests/ParserTest.cpp +++ b/olp-cpp-sdk-dataservice-read/tests/ParserTest.cpp @@ -1,5 +1,5 @@ /* - * Copyright (C) 2019-2021 HERE Europe B.V. + * Copyright (C) 2019-2026 HERE Europe B.V. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -32,7 +32,7 @@ #include "generated/parser/MessagesParser.h" #include "generated/parser/SubscribeResponseParser.h" #include "generated/parser/VersionInfosParser.h" -#include +#include #include "generated/serializer/VersionInfosSerializer.h" #include "generated/serializer/JsonSerializer.h" // clang-format on diff --git a/olp-cpp-sdk-dataservice-read/tests/PartitionsCacheRepositoryTest.cpp b/olp-cpp-sdk-dataservice-read/tests/PartitionsCacheRepositoryTest.cpp index d44495111..85801359a 100644 --- a/olp-cpp-sdk-dataservice-read/tests/PartitionsCacheRepositoryTest.cpp +++ b/olp-cpp-sdk-dataservice-read/tests/PartitionsCacheRepositoryTest.cpp @@ -1,5 +1,5 @@ /* - * Copyright (C) 2020-2024 HERE Europe B.V. + * Copyright (C) 2020-2026 HERE Europe B.V. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -27,7 +27,7 @@ #include "repositories/DataCacheRepository.h" // clang-format off -#include +#include #include "generated/serializer/PartitionsSerializer.h" #include "generated/serializer/JsonSerializer.h" // clang-format on diff --git a/olp-cpp-sdk-dataservice-read/tests/PartitionsRepositoryTest.cpp b/olp-cpp-sdk-dataservice-read/tests/PartitionsRepositoryTest.cpp index 00cf97b92..7f315e339 100644 --- a/olp-cpp-sdk-dataservice-read/tests/PartitionsRepositoryTest.cpp +++ b/olp-cpp-sdk-dataservice-read/tests/PartitionsRepositoryTest.cpp @@ -39,7 +39,7 @@ // clang-format off #include "generated/parser/PartitionsParser.h" -#include +#include // clang-format on namespace { diff --git a/tests/common/ResponseGenerator.cpp b/tests/common/ResponseGenerator.cpp index 4ea6eb667..56c908841 100644 --- a/tests/common/ResponseGenerator.cpp +++ b/tests/common/ResponseGenerator.cpp @@ -1,5 +1,5 @@ /* - * Copyright (C) 2020 HERE Europe B.V. + * Copyright (C) 2020-2026 HERE Europe B.V. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -33,7 +33,7 @@ #include "generated/serializer/ApiSerializer.h" #include "generated/serializer/VersionResponseSerializer.h" #include "generated/serializer/PartitionsSerializer.h" -#include +#include "generated/serializer/SerializerWrapper.h" #include "generated/serializer/JsonSerializer.h" // clang-format on From fbf00774e8068fc9cebb0cbdaefac9defa07e027 Mon Sep 17 00:00:00 2001 From: Rustam Gamidov <108531570+rustam-gamidov-here@users.noreply.github.com> Date: Mon, 23 Mar 2026 08:15:41 +0200 Subject: [PATCH 10/12] Use Boost::json in olp-cpp-sdk-core (#1685) Migrating from RapidJSON Json wrappers has been moved and not exposed anymore Use Boost::json in mock-server-client Use boost::json in HarCaptureAdapter Relates-To: OCMAM-446 Signed-off-by: Rustam Gamidov --- olp-cpp-sdk-core/CMakeLists.txt | 17 +- .../olp/core/generated/parser/ParserWrapper.h | 98 ----- .../generated/serializer/SerializerWrapper.h | 114 ------ .../src/client/api/JsonResultParser.h | 4 +- .../src/client/parser/ApiParser.cpp | 9 +- .../src/client/parser/ApiParser.h | 6 +- .../generated/parser/JsonParser.h | 33 +- .../src/generated/parser/ParserWrapper.h | 102 ++++++ .../generated/serializer/SerializerWrapper.h | 102 ++++++ .../src/http/adapters/HarCaptureAdapter.cpp | 340 ++++++++++-------- tests/common/ReadDefaultResponses.cpp | 98 +++-- tests/common/WriteDefaultResponses.h | 10 +- tests/utils/mock-server-client/Client.h | 38 +- tests/utils/mock-server-client/Expectation.h | 113 +++--- tests/utils/mock-server-client/JsonHelpers.h | 124 +++---- tests/utils/mock-server-client/Status.h | 6 +- 16 files changed, 595 insertions(+), 619 deletions(-) delete mode 100644 olp-cpp-sdk-core/include/olp/core/generated/parser/ParserWrapper.h delete mode 100644 olp-cpp-sdk-core/include/olp/core/generated/serializer/SerializerWrapper.h rename olp-cpp-sdk-core/{include/olp/core => src}/generated/parser/JsonParser.h (66%) create mode 100644 olp-cpp-sdk-core/src/generated/parser/ParserWrapper.h create mode 100644 olp-cpp-sdk-core/src/generated/serializer/SerializerWrapper.h diff --git a/olp-cpp-sdk-core/CMakeLists.txt b/olp-cpp-sdk-core/CMakeLists.txt index e694436ad..9bab6cedf 100644 --- a/olp-cpp-sdk-core/CMakeLists.txt +++ b/olp-cpp-sdk-core/CMakeLists.txt @@ -19,7 +19,6 @@ project(olp-cpp-sdk-core VERSION 1.24.0) set(DESCRIPTION "Core network and utility library for the HERE OLP SDK C++") -find_package(RapidJSON 1.1.0 REQUIRED) find_package(Boost REQUIRED) find_package(Threads REQUIRED) @@ -97,12 +96,6 @@ set(OLP_SDK_CLIENT_HEADERS ./include/olp/core/client/TaskContext.h ) -set(OLP_SDK_GENERATED_HEADERS - ./include/olp/core/generated/parser/JsonParser.h - ./include/olp/core/generated/parser/ParserWrapper.h - ./include/olp/core/generated/serializer/SerializerWrapper.h -) - set(OLP_SDK_HTTP_HEADERS ./include/olp/core/http/adapters/HarCaptureAdapter.h ./include/olp/core/http/CertificateSettings.h @@ -229,6 +222,12 @@ set(OLP_SDK_COREAPI_HEADERS ./include/olp/core/CoreApi.h ) +set(OLP_SDK_GENERATED_HEADERS + ./src/generated/parser/JsonParser.h + ./src/generated/parser/ParserWrapper.h + ./src/generated/serializer/SerializerWrapper.h +) + set(OLP_SDK_GEO_SOURCES ./src/geo/coordinates/GeoCoordinates.cpp ./src/geo/coordinates/GeoCoordinates3d.cpp @@ -390,7 +389,6 @@ set(OLP_SDK_THREAD_SOURCES set(OLP_SDK_CORE_HEADERS ${OLP_SDK_CACHE_HEADERS} ${OLP_SDK_CLIENT_HEADERS} - ${OLP_SDK_GENERATED_HEADERS} ${OLP_SDK_HTTP_HEADERS} ${OLP_SDK_MODEL_HEADERS} ${OLP_SDK_PLATFORM_HEADERS} @@ -408,6 +406,7 @@ set(OLP_SDK_CORE_HEADERS ) set(OLP_SDK_CORE_SOURCES + ${OLP_SDK_GENERATED_HEADERS} ${OLP_SDK_CLIENT_SOURCES} ${OLP_SDK_HTTP_SOURCES} ${OLP_SDK_PLATFORM_SOURCES} @@ -466,8 +465,6 @@ target_include_directories(${PROJECT_NAME} PUBLIC $ $ - $ - $) if (ANDROID) diff --git a/olp-cpp-sdk-core/include/olp/core/generated/parser/ParserWrapper.h b/olp-cpp-sdk-core/include/olp/core/generated/parser/ParserWrapper.h deleted file mode 100644 index 3cdd5e1bd..000000000 --- a/olp-cpp-sdk-core/include/olp/core/generated/parser/ParserWrapper.h +++ /dev/null @@ -1,98 +0,0 @@ -/* - * Copyright (C) 2019-2023 HERE Europe B.V. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * SPDX-License-Identifier: Apache-2.0 - * License-Filename: LICENSE - */ - -#pragma once - -#include -#include -#include -#include - -#include -#include - -namespace olp { -namespace parser { - -inline void from_json(const rapidjson::Value& value, std::string& x) { - x = value.GetString(); -} - -inline void from_json(const rapidjson::Value& value, int32_t& x) { - x = value.GetInt(); -} - -inline void from_json(const rapidjson::Value& value, int64_t& x) { - x = value.GetInt64(); -} - -inline void from_json(const rapidjson::Value& value, double& x) { - x = value.GetDouble(); -} - -inline void from_json(const rapidjson::Value& value, bool& x) { - x = value.GetBool(); -} - -inline void from_json(const rapidjson::Value& value, - std::shared_ptr>& x) { - std::string s = value.GetString(); - x = std::make_shared>(s.begin(), s.end()); -} - -template -inline void from_json(const rapidjson::Value& value, porting::optional& x) { - T result = T(); - from_json(value, result); - x = result; -} - -template -inline void from_json(const rapidjson::Value& value, - std::map& results) { - for (rapidjson::Value::ConstMemberIterator itr = value.MemberBegin(); - itr != value.MemberEnd(); ++itr) { - std::string key; - from_json(itr->name, key); - from_json(itr->value, results[key]); - } -} - -template -inline void from_json(const rapidjson::Value& value, std::vector& results) { - for (rapidjson::Value::ConstValueIterator itr = value.Begin(); - itr != value.End(); ++itr) { - T result; - from_json(*itr, result); - results.emplace_back(std::move(result)); - } -} - -template -inline T parse(const rapidjson::Value& value, const std::string& name) { - T result = T(); - rapidjson::Value::ConstMemberIterator itr = value.FindMember(name.c_str()); - if (itr != value.MemberEnd()) { - from_json(itr->value, result); - } - return result; -} - -} // namespace parser -} // namespace olp diff --git a/olp-cpp-sdk-core/include/olp/core/generated/serializer/SerializerWrapper.h b/olp-cpp-sdk-core/include/olp/core/generated/serializer/SerializerWrapper.h deleted file mode 100644 index 62250586d..000000000 --- a/olp-cpp-sdk-core/include/olp/core/generated/serializer/SerializerWrapper.h +++ /dev/null @@ -1,114 +0,0 @@ -/* - * Copyright (C) 2019-2021 HERE Europe B.V. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * SPDX-License-Identifier: Apache-2.0 - * License-Filename: LICENSE - */ - -#pragma once - -#include -#include -#include -#include -#include - -#include -#include - -namespace olp { -namespace serializer { - -inline void to_json(const std::string& x, rapidjson::Value& value, - rapidjson::Document::AllocatorType& allocator) { - value.SetString(rapidjson::StringRef(x.c_str(), x.size()), allocator); -} - -inline void to_json(int32_t x, rapidjson::Value& value, - rapidjson::Document::AllocatorType&) { - value.SetInt(x); -} - -inline void to_json(int64_t x, rapidjson::Value& value, - rapidjson::Document::AllocatorType&) { - value.SetInt64(x); -} - -inline void to_json(double x, rapidjson::Value& value, - rapidjson::Document::AllocatorType&) { - value.SetDouble(x); -} -inline void to_json(bool x, rapidjson::Value& value, - rapidjson::Document::AllocatorType&) { - value.SetBool(x); -} - -inline void to_json(const std::shared_ptr>& x, - rapidjson::Value& value, - rapidjson::Document::AllocatorType& allocator) { - value.SetString(reinterpret_cast(x->data()), - static_cast(x->size()), allocator); -} - -template -inline void to_json(const porting::optional& x, rapidjson::Value& value, - rapidjson::Document::AllocatorType& allocator) { - if (x) { - to_json(*x, value, allocator); - } else { - value.SetNull(); - } -} - -template -inline void to_json(const std::map& x, rapidjson::Value& value, - rapidjson::Document::AllocatorType& allocator) { - value.SetObject(); - for (auto itr = x.begin(); itr != x.end(); ++itr) { - const auto& key = itr->first; - rapidjson::Value item_value; - to_json(itr->second, item_value, allocator); - value.AddMember(rapidjson::StringRef(key.c_str(), key.size()), - std::move(item_value), allocator); - } -} - -template -inline void to_json(const std::vector& x, rapidjson::Value& value, - rapidjson::Document::AllocatorType& allocator) { - value.SetArray(); - for (typename std::vector::const_iterator itr = x.begin(); itr != x.end(); - ++itr) { - rapidjson::Value item_value; - to_json(*itr, item_value, allocator); - value.PushBack(std::move(item_value), allocator); - } -} - -template -inline void serialize(const std::string& key, const T& x, - rapidjson::Value& value, - rapidjson::Document::AllocatorType& allocator) { - rapidjson::Value key_value; - to_json(key, key_value, allocator); - rapidjson::Value item_value; - to_json(x, item_value, allocator); - if (!item_value.IsNull()) { - value.AddMember(std::move(key_value), std::move(item_value), allocator); - } -} - -} // namespace serializer -} // namespace olp diff --git a/olp-cpp-sdk-core/src/client/api/JsonResultParser.h b/olp-cpp-sdk-core/src/client/api/JsonResultParser.h index c60c812f5..296c3fa7a 100644 --- a/olp-cpp-sdk-core/src/client/api/JsonResultParser.h +++ b/olp-cpp-sdk-core/src/client/api/JsonResultParser.h @@ -1,5 +1,5 @@ /* - * Copyright (C) 2020 HERE Europe B.V. + * Copyright (C) 2020-2026 HERE Europe B.V. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -23,8 +23,8 @@ #include #include +#include #include -#include #include namespace olp { diff --git a/olp-cpp-sdk-core/src/client/parser/ApiParser.cpp b/olp-cpp-sdk-core/src/client/parser/ApiParser.cpp index 2942198b4..2c62f960e 100644 --- a/olp-cpp-sdk-core/src/client/parser/ApiParser.cpp +++ b/olp-cpp-sdk-core/src/client/parser/ApiParser.cpp @@ -1,5 +1,5 @@ /* - * Copyright (C) 2020 HERE Europe B.V. + * Copyright (C) 2020-2026 HERE Europe B.V. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -19,11 +19,14 @@ #include "ApiParser.h" -#include +#include +#include + +#include namespace olp { namespace parser { -void from_json(const rapidjson::Value& value, olp::client::Api& x) { +void from_json(const boost::json::value& value, olp::client::Api& x) { x.SetApi(parse(value, "api")); x.SetVersion(parse(value, "version")); x.SetBaseUrl(parse(value, "baseURL")); diff --git a/olp-cpp-sdk-core/src/client/parser/ApiParser.h b/olp-cpp-sdk-core/src/client/parser/ApiParser.h index bbed3eac7..ab61f3c2f 100644 --- a/olp-cpp-sdk-core/src/client/parser/ApiParser.h +++ b/olp-cpp-sdk-core/src/client/parser/ApiParser.h @@ -1,5 +1,5 @@ /* - * Copyright (C) 2020 HERE Europe B.V. + * Copyright (C) 2020-2026 HERE Europe B.V. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -20,11 +20,11 @@ #pragma once #include -#include +#include namespace olp { namespace parser { -void from_json(const rapidjson::Value& value, olp::client::Api& x); +void from_json(const boost::json::value& value, olp::client::Api& x); } // namespace parser } // namespace olp diff --git a/olp-cpp-sdk-core/include/olp/core/generated/parser/JsonParser.h b/olp-cpp-sdk-core/src/generated/parser/JsonParser.h similarity index 66% rename from olp-cpp-sdk-core/include/olp/core/generated/parser/JsonParser.h rename to olp-cpp-sdk-core/src/generated/parser/JsonParser.h index d5127e61e..48f30401e 100644 --- a/olp-cpp-sdk-core/include/olp/core/generated/parser/JsonParser.h +++ b/olp-cpp-sdk-core/src/generated/parser/JsonParser.h @@ -1,5 +1,5 @@ /* - * Copyright (C) 2019-2024 HERE Europe B.V. + * Copyright (C) 2019-2026 HERE Europe B.V. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -24,20 +24,20 @@ #include #include -#include -#include +#include #include "ParserWrapper.h" namespace olp { namespace parser { + template inline T parse(const std::string& json) { - rapidjson::Document doc; - doc.Parse(json.c_str()); + boost::json::error_code ec; + auto value = boost::json::parse(json, ec); T result{}; - if (doc.IsObject() || doc.IsArray()) { - from_json(doc, result); + if (value.is_object() || value.is_array()) { + from_json(value, result); } return result; } @@ -45,12 +45,11 @@ inline T parse(const std::string& json) { template inline T parse(std::stringstream& json_stream, bool& res) { res = false; - rapidjson::Document doc; - rapidjson::IStreamWrapper stream(json_stream); - doc.ParseStream(stream); + boost::json::error_code ec; + auto value = boost::json::parse(json_stream, ec); T result{}; - if (doc.IsObject() || doc.IsArray()) { - from_json(doc, result); + if (value.is_object() || value.is_array()) { + from_json(value, result); res = true; } return result; @@ -64,11 +63,13 @@ inline T parse(std::stringstream& json_stream) { template inline T parse(const std::shared_ptr>& json_bytes) { - rapidjson::Document doc; - doc.Parse(reinterpret_cast(json_bytes->data()), json_bytes->size()); + boost::json::string_view json(reinterpret_cast(json_bytes->data()), + json_bytes->size()); + boost::json::error_code ec; + auto value = boost::json::parse(json, ec); T result{}; - if (doc.IsObject() || doc.IsArray()) { - from_json(doc, result); + if (value.is_object() || value.is_array()) { + from_json(value, result); } return result; } diff --git a/olp-cpp-sdk-core/src/generated/parser/ParserWrapper.h b/olp-cpp-sdk-core/src/generated/parser/ParserWrapper.h new file mode 100644 index 000000000..284238474 --- /dev/null +++ b/olp-cpp-sdk-core/src/generated/parser/ParserWrapper.h @@ -0,0 +1,102 @@ +/* + * Copyright (C) 2019-2026 HERE Europe B.V. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * SPDX-License-Identifier: Apache-2.0 + * License-Filename: LICENSE + */ + +#pragma once + +#include +#include +#include +#include +#include + +#include +#include + +namespace olp { +namespace parser { + +inline void from_json(const boost::json::value& value, std::string& x) { + const auto& str = value.get_string(); + x.assign(str.begin(), str.end()); +} + +inline void from_json(const boost::json::value& value, int32_t& x) { + x = static_cast(value.to_number()); +} + +inline void from_json(const boost::json::value& value, int64_t& x) { + x = value.to_number(); +} + +inline void from_json(const boost::json::value& value, double& x) { + x = value.to_number(); +} + +inline void from_json(const boost::json::value& value, bool& x) { + x = value.get_bool(); +} + +inline void from_json(const boost::json::value& value, + std::shared_ptr>& x) { + const auto& s = value.get_string(); + x = std::make_shared>(s.begin(), s.end()); +} + +template +inline void from_json(const boost::json::value& value, + porting::optional& x) { + T result = T(); + from_json(value, result); + x = result; +} + +template +inline void from_json(const boost::json::value& value, + std::map& results) { + const auto& object = value.get_object(); + for (const auto& object_value : object) { + std::string key = object_value.key(); + from_json(object_value.value(), results[key]); + } +} + +template +inline void from_json(const boost::json::value& value, + std::vector& results) { + const auto& array = value.get_array(); + for (const auto& array_value : array) { + T result; + from_json(array_value, result); + results.emplace_back(std::move(result)); + } +} + +template +inline T parse(const boost::json::value& value, const std::string& name) { + T result = T(); + const auto& object = value.get_object(); + auto itr = object.find(name); + if (itr != object.end()) { + from_json(itr->value(), result); + } + return result; +} + +} // namespace parser +} // namespace olp diff --git a/olp-cpp-sdk-core/src/generated/serializer/SerializerWrapper.h b/olp-cpp-sdk-core/src/generated/serializer/SerializerWrapper.h new file mode 100644 index 000000000..7005b9cec --- /dev/null +++ b/olp-cpp-sdk-core/src/generated/serializer/SerializerWrapper.h @@ -0,0 +1,102 @@ +/* + * Copyright (C) 2019-2026 HERE Europe B.V. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * SPDX-License-Identifier: Apache-2.0 + * License-Filename: LICENSE + */ + +#pragma once + +#include +#include +#include +#include +#include + +#include +#include + +namespace olp { +namespace serializer { + +inline void to_json(const std::string& x, boost::json::value& value) { + value.emplace_string() = x; +} + +inline void to_json(int32_t x, boost::json::value& value) { + value.emplace_int64() = x; +} + +inline void to_json(int64_t x, boost::json::value& value) { + value.emplace_int64() = x; +} + +inline void to_json(double x, boost::json::value& value) { + value.emplace_double() = x; +} +inline void to_json(bool x, boost::json::value& value) { + value.emplace_bool() = x; +} + +inline void to_json(const std::shared_ptr>& x, + boost::json::value& value) { + value.emplace_string().assign(x->begin(), x->end()); +} + +template +inline void to_json(const porting::optional& x, boost::json::value& value) { + if (x) { + to_json(*x, value); + } else { + value.emplace_null(); + } +} + +template +inline void to_json(const std::map& x, + boost::json::value& value) { + auto& object = value.emplace_object(); + for (auto itr = x.begin(); itr != x.end(); ++itr) { + const auto& key = itr->first; + boost::json::value item_value; + to_json(itr->second, item_value); + object.emplace(key, std::move(item_value)); + } +} + +template +inline void to_json(const std::vector& x, boost::json::value& value) { + auto& array = value.emplace_array(); + array.reserve(x.size()); + for (typename std::vector::const_iterator itr = x.begin(); itr != x.end(); + ++itr) { + boost::json::value item_value; + to_json(*itr, item_value); + array.emplace_back(std::move(item_value)); + } +} + +template +inline void serialize(const std::string& key, const T& x, + boost::json::object& value) { + boost::json::value item_value; + to_json(x, item_value); + if (!item_value.is_null()) { + value.emplace(key, std::move(item_value)); + } +} + +} // namespace serializer +} // namespace olp diff --git a/olp-cpp-sdk-core/src/http/adapters/HarCaptureAdapter.cpp b/olp-cpp-sdk-core/src/http/adapters/HarCaptureAdapter.cpp index fe1939e9c..7df4d7439 100644 --- a/olp-cpp-sdk-core/src/http/adapters/HarCaptureAdapter.cpp +++ b/olp-cpp-sdk-core/src/http/adapters/HarCaptureAdapter.cpp @@ -1,5 +1,5 @@ /* - * Copyright (C) 2025 HERE Europe B.V. + * Copyright (C) 2025-2026 HERE Europe B.V. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -19,8 +19,10 @@ #include -#include -#include +#include +#include + +#include #include #include @@ -68,56 +70,96 @@ std::string FormatTime(const std::chrono::system_clock::time_point timestamp) { return ss.str(); } -class JsonFileSerializer { - public: - explicit JsonFileSerializer(std::ofstream& file) - : out_stream_(file), writer_(out_stream_) {} +// In addition to making result easier to read formats floating point numbers +// from `1.00281E2` to `100.281` and from `0` to `0.000` +void PrettyPrint(std::ostream& os, boost::json::value const& jv, + std::string* indent = nullptr) { + const auto initial_precision{os.precision()}; + const auto initial_floatfield{os.floatfield}; + os.precision(3); + os.setf(std::ios_base::fixed, std::ios_base::floatfield); + + std::string indent_; + if (!indent) + indent = &indent_; + switch (jv.kind()) { + case boost::json::kind::object: { + os << "{\n"; + indent->append(4, ' '); + auto const& obj = jv.get_object(); + if (!obj.empty()) { + auto it = obj.begin(); + for (;;) { + os << *indent << boost::json::serialize(it->key()) << ": "; + PrettyPrint(os, it->value(), indent); + if (++it == obj.end()) + break; + os << ",\n"; + } + } + os << "\n"; + indent->resize(indent->size() - 4); + os << *indent << "}"; + break; + } - void Object(const std::function& body) { - writer_.StartObject(); - body(); - writer_.EndObject(); - } + case boost::json::kind::array: { + auto const& arr = jv.get_array(); + if (arr.empty()) { + os << "[]"; + } else { + os << "[\n"; + indent->append(4, ' '); + auto it = arr.begin(); + for (;;) { + os << *indent; + PrettyPrint(os, *it, indent); + if (++it == arr.end()) + break; + os << ",\n"; + } + os << "\n"; + indent->resize(indent->size() - 4); + os << *indent << "]"; + } + break; + } - void Object(const char* key, const std::function& body) { - writer_.Key(key); - writer_.StartObject(); - body(); - writer_.EndObject(); - } + case boost::json::kind::string: { + os << boost::json::serialize(jv.get_string()); + break; + } - void Array(const char* key, const std::function& body) { - writer_.Key(key); - writer_.StartArray(); - body(); - writer_.EndArray(); - } + case boost::json::kind::uint64: + os << jv.get_uint64(); + break; - void String(const char* key, const std::string& value) { - writer_.Key(key); - writer_.String(value.c_str(), value.size()); - } + case boost::json::kind::int64: + os << jv.get_int64(); + break; - void Int(const char* key, const int value) { - writer_.Key(key); - writer_.Int(value); - } + case boost::json::kind::double_: + os << jv.get_double(); + break; - void Double(const char* key, const double value) { - writer_.Key(key); - writer_.Double(value); - } + case boost::json::kind::bool_: + if (jv.get_bool()) + os << "true"; + else + os << "false"; + break; - void EmptyArray(const char* key) { - writer_.Key(key); - writer_.StartArray(); - writer_.EndArray(); + case boost::json::kind::null: + os << "null"; + break; } - private: - rapidjson::OStreamWrapper out_stream_; - rapidjson::PrettyWriter writer_{}; -}; + if (indent->empty()) + os << "\n"; + + os.precision(initial_precision); + os.setf(std::ios_base::fixed, initial_floatfield); +} } // namespace @@ -229,6 +271,110 @@ class HarCaptureAdapter::HarCaptureAdapterImpl final : public Network { } void SaveSessionToFile() const { + boost::json::object log; + log["version"] = "1.2"; + log["creator"] = boost::json::object( + {{"name", "DataSDK"}, {"version", OLP_SDK_VERSION_STRING}}); + + log["entries"] = [&]() { + boost::json::array entries; + entries.reserve(requests_.size()); + for (auto request_index = 0u; request_index < requests_.size(); + ++request_index) { + const auto& request = requests_[request_index]; + const auto diagnostics = diagnostics_.size() > request_index + ? diagnostics_[request_index] + : Diagnostics{}; + + // return duration in milliseconds as float + auto duration = [&](const Diagnostics::Timings timing, + const double default_value = -1.0) { + return diagnostics.available_timings[timing] + ? diagnostics.timings[timing].count() / 1000.0 + : default_value; + }; + + const double total_time = + duration(Diagnostics::Total, + static_cast( + std::chrono::duration_cast( + request.end_time - request.start_time) + .count()) / + 1000.0); + + auto output_headers = [&](const uint16_t headers_offset, + const uint16_t headers_count) { + boost::json::array headers; + headers.reserve(headers_count); + for (auto i = 0u; i < headers_count; ++i) { + const auto& header = headers_[headers_offset + i]; + headers.emplace_back( + boost::json::object({{"name", cache_.at(header.first)}, + {"value", cache_.at(header.second)}})); + } + return headers; + }; + + boost::json::object entry; + entry["startedDateTime"] = FormatTime(request.start_time); + entry["time"] = total_time; + + entry.emplace("request", [&]() { + boost::json::object value; + + value["method"] = VerbToString( + static_cast(request.method)); + value["url"] = cache_.at(request.url); + value["httpVersion"] = "UNSPECIFIED"; + value["cookies"] = boost::json::array{}; + value["headers"] = output_headers(request.request_headers_offset, + request.request_headers_count); + value["queryString"] = boost::json::array{}; + value["headersSize"] = -1; + value["bodySize"] = -1; + + return value; + }()); + + entry.emplace("response", [&]() { + boost::json::object value; + value["status"] = request.status_code; + value["statusText"] = ""; + value["httpVersion"] = "UNSPECIFIED"; + value["cookies"] = boost::json::array{}; + value["headers"] = output_headers(request.response_headers_offset, + request.response_headers_count); + value["content"] = + boost::json::object({{"size", 0}, {"mimeType", ""}}); + value["redirectURL"] = ""; + value["headersSize"] = -1; + value["bodySize"] = -1; + value["_transferSize"] = static_cast(request.transfer_size); + return value; + }()); + + entry.emplace("timings", [&]() { + using Timings = Diagnostics::Timings; + boost::json::object value; + value["blocked"] = duration(Timings::Queue); + value["dns"] = duration(Timings::NameLookup); + value["connect"] = duration(Timings::Connect); + value["ssl"] = duration(Timings::SSL_Handshake); + value["send"] = duration(Timings::Send, 0.0); + value["wait"] = duration(Timings::Wait, 0.0); + value["receive"] = duration(Timings::Receive, total_time); + return value; + }()); + + entries.emplace_back(std::move(entry)); + } + + return entries; + }(); + + boost::json::object doc; + doc.emplace("log", std::move(log)); + std::ofstream file(har_out_path_); if (!file.is_open()) { OLP_SDK_LOG_ERROR("HarCaptureAdapter::SaveSession", @@ -236,111 +382,7 @@ class HarCaptureAdapter::HarCaptureAdapterImpl final : public Network { return; } - JsonFileSerializer serializer{file}; - - serializer.Object([&] { - serializer.Object("log", [&] { - serializer.String("version", "1.2"); - - serializer.Object("creator", [&] { - serializer.String("name", "DataSDK"); - serializer.String("version", OLP_SDK_VERSION_STRING); - }); - - serializer.Array("entries", [&] { - for (auto request_index = 0u; request_index < requests_.size(); - ++request_index) { - const auto& request = requests_[request_index]; - const auto diagnostics = diagnostics_.size() > request_index - ? diagnostics_[request_index] - : Diagnostics{}; - - // return duration in milliseconds as float - auto duration = [&](const Diagnostics::Timings timing, - const double default_value = -1.0) { - return diagnostics.available_timings[timing] - ? diagnostics.timings[timing].count() / 1000.0 - : default_value; - }; - - const double total_time = duration( - Diagnostics::Total, - static_cast( - std::chrono::duration_cast( - request.end_time - request.start_time) - .count()) / - 1000.0); - - auto output_headers = [&](const uint16_t headers_offset, - const uint16_t headers_count) { - serializer.Array("headers", [&] { - for (auto i = 0u; i < headers_count; ++i) { - serializer.Object([&] { - auto header = headers_[headers_offset + i]; - serializer.String("name", cache_.at(header.first)); - serializer.String("value", cache_.at(header.second)); - }); - } - }); - }; - - serializer.Object([&] { - serializer.String("startedDateTime", - FormatTime(request.start_time)); - serializer.Double("time", total_time); - - serializer.Object("request", [&] { - serializer.String( - "method", - VerbToString( - static_cast(request.method))); - serializer.String("url", cache_.at(request.url)); - serializer.String("httpVersion", "UNSPECIFIED"); - serializer.EmptyArray("cookies"); - output_headers(request.request_headers_offset, - request.request_headers_count); - serializer.EmptyArray("queryString"); - serializer.Int("headersSize", -1); - serializer.Int("bodySize", -1); - }); - - // response - serializer.Object("response", [&] { - serializer.Int("status", request.status_code); - serializer.String("statusText", ""); - serializer.String("httpVersion", "UNSPECIFIED"); - serializer.EmptyArray("cookies"); - output_headers(request.response_headers_offset, - request.response_headers_count); - serializer.Object("content", [&] { - serializer.Int("size", 0); - serializer.String("mimeType", ""); - }); - serializer.String("redirectURL", ""); - serializer.Int("headersSize", -1); - serializer.Int("bodySize", -1); - serializer.Int("_transferSize", - static_cast(request.transfer_size)); - }); - - // timings - serializer.Object("timings", [&] { - using Timings = Diagnostics::Timings; - serializer.Double("blocked", duration(Timings::Queue)); - serializer.Double("dns", duration(Timings::NameLookup)); - serializer.Double("connect", duration(Timings::Connect)); - serializer.Double("ssl", duration(Timings::SSL_Handshake)); - serializer.Double("send", duration(Timings::Send, 0.0)); - serializer.Double("wait", duration(Timings::Wait, 0.0)); - serializer.Double("receive", - duration(Timings::Receive, total_time)); - }); - }); - } - }); - }); - }); - + PrettyPrint(file, doc); file.close(); OLP_SDK_LOG_INFO("HarCaptureAdapter::SaveSession", diff --git a/tests/common/ReadDefaultResponses.cpp b/tests/common/ReadDefaultResponses.cpp index 39b664a09..9c6330148 100644 --- a/tests/common/ReadDefaultResponses.cpp +++ b/tests/common/ReadDefaultResponses.cpp @@ -1,5 +1,5 @@ /* - * Copyright (C) 2020-2024 HERE Europe B.V. + * Copyright (C) 2020-2026 HERE Europe B.V. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -24,66 +24,58 @@ #include #include -#include -#include -#include +#include + +#include +#include namespace { void WriteSubquadsToJson( - rapidjson::Document& doc, const olp::geo::TileKey& root_tile, - const std::map& sub_quads, - rapidjson::Document::AllocatorType& allocator) { - rapidjson::Value sub_quads_value; - sub_quads_value.SetArray(); + boost::json::object& doc, const olp::geo::TileKey& root_tile, + const std::map& sub_quads) { + boost::json::array sub_quads_value; for (const auto& quad : sub_quads) { const mockserver::TileMetadata& metadata = quad.second; const auto partition = root_tile.AddedSubkey64(quad.first).ToHereTile(); - rapidjson::Value item; - item.SetObject(); - olp::serializer::serialize("subQuadKey", std::to_string(quad.first), item, - allocator); - olp::serializer::serialize("version", metadata.version, item, allocator); - olp::serializer::serialize("dataHandle", metadata.data_handle, item, - allocator); - olp::serializer::serialize("crc", metadata.crc, item, allocator); - olp::serializer::serialize("checksum", metadata.checksum, item, allocator); - olp::serializer::serialize("dataSize", metadata.data_size, item, allocator); + boost::json::object item; + olp::serializer::serialize("subQuadKey", std::to_string(quad.first), item); + olp::serializer::serialize("version", metadata.version, item); + olp::serializer::serialize("dataHandle", metadata.data_handle, item); + olp::serializer::serialize("crc", metadata.crc, item); + olp::serializer::serialize("checksum", metadata.checksum, item); + olp::serializer::serialize("dataSize", metadata.data_size, item); olp::serializer::serialize("compressedDataSize", - metadata.compressed_data_size, item, allocator); + metadata.compressed_data_size, item); - sub_quads_value.PushBack(std::move(item), allocator); + sub_quads_value.emplace_back(std::move(item)); } - doc.AddMember("subQuads", std::move(sub_quads_value), allocator); + doc.emplace("subQuads", std::move(sub_quads_value)); } void WriteParentquadsToJson( - rapidjson::Document& doc, - const std::map& parent_quads, - rapidjson::Document::AllocatorType& allocator) { - rapidjson::Value parent_quads_value; - parent_quads_value.SetArray(); + boost::json::object& doc, + const std::map& parent_quads) { + boost::json::array parent_quads_value; for (const auto& parent : parent_quads) { const auto partition = std::to_string(parent.first); const mockserver::TileMetadata& metadata = parent.second; - rapidjson::Value item; - item.SetObject(); - olp::serializer::serialize("partition", partition, item, allocator); - olp::serializer::serialize("version", metadata.version, item, allocator); - olp::serializer::serialize("dataHandle", metadata.data_handle, item, - allocator); - olp::serializer::serialize("crc", metadata.crc, item, allocator); - olp::serializer::serialize("checksum", metadata.checksum, item, allocator); - olp::serializer::serialize("dataSize", metadata.data_size, item, allocator); + boost::json::object item; + olp::serializer::serialize("partition", partition, item); + olp::serializer::serialize("version", metadata.version, item); + olp::serializer::serialize("dataHandle", metadata.data_handle, item); + olp::serializer::serialize("crc", metadata.crc, item); + olp::serializer::serialize("checksum", metadata.checksum, item); + olp::serializer::serialize("dataSize", metadata.data_size, item); olp::serializer::serialize("compressedDataSize", - metadata.compressed_data_size, item, allocator); - parent_quads_value.PushBack(std::move(item), allocator); + metadata.compressed_data_size, item); + parent_quads_value.emplace_back(std::move(item)); } - doc.AddMember("parentQuads", std::move(parent_quads_value), allocator); + doc.emplace("parentQuads", std::move(parent_quads_value)); } std::string GenerateRandomString(size_t length) { @@ -160,16 +152,11 @@ std::string ReadDefaultResponses::GenerateQuadTreeResponse( } } - rapidjson::Document doc; - auto& allocator = doc.GetAllocator(); - doc.SetObject(); - WriteSubquadsToJson(doc, root_tile, sub_quads, allocator); - WriteParentquadsToJson(doc, parent_quads, allocator); + boost::json::object doc; + WriteSubquadsToJson(doc, root_tile, sub_quads); + WriteParentquadsToJson(doc, parent_quads); - rapidjson::StringBuffer buffer; - rapidjson::Writer writer(buffer); - doc.Accept(writer); - return buffer.GetString(); + return boost::json::serialize(doc); } QuadTreeBuilder::QuadTreeBuilder(olp::geo::TileKey root_tile, @@ -228,16 +215,11 @@ QuadTreeBuilder& QuadTreeBuilder::WithSubQuad( } std::string QuadTreeBuilder::BuildJson() const { - rapidjson::Document doc; - auto& allocator = doc.GetAllocator(); - doc.SetObject(); - WriteSubquadsToJson(doc, root_tile_, sub_quads_, allocator); - WriteParentquadsToJson(doc, parent_quads_, allocator); - - rapidjson::StringBuffer buffer; - rapidjson::Writer writer(buffer); - doc.Accept(writer); - return buffer.GetString(); + boost::json::object doc; + WriteSubquadsToJson(doc, root_tile_, sub_quads_); + WriteParentquadsToJson(doc, parent_quads_); + + return boost::json::serialize(doc); } olp::geo::TileKey QuadTreeBuilder::Root() const { return root_tile_; } diff --git a/tests/common/WriteDefaultResponses.h b/tests/common/WriteDefaultResponses.h index 93d151389..a3bfc1b35 100644 --- a/tests/common/WriteDefaultResponses.h +++ b/tests/common/WriteDefaultResponses.h @@ -1,5 +1,5 @@ /* - * Copyright (C) 2020 HERE Europe B.V. + * Copyright (C) 2020-2026 HERE Europe B.V. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -24,11 +24,8 @@ #include #include +#include #include -#include -#include -#include -#include #include "generated/model/Api.h" @@ -87,7 +84,8 @@ class DefaultResponses { static olp::dataservice::write::model::Publication GeneratePublicationResponse( const std::vector& layer_ids, - const std::vector dependencies) { + const std::vector + dependencies) { olp::dataservice::write::model::Publication publication; std::string id = "abcdefghijklmnopqrstuvwxyz0123456789-"; diff --git a/tests/utils/mock-server-client/Client.h b/tests/utils/mock-server-client/Client.h index 1787e5da1..97dae914d 100644 --- a/tests/utils/mock-server-client/Client.h +++ b/tests/utils/mock-server-client/Client.h @@ -1,5 +1,5 @@ /* - * Copyright (C) 2020-2024 HERE Europe B.V. + * Copyright (C) 2020-2026 HERE Europe B.V. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -21,6 +21,7 @@ #include #include +#include #include #include @@ -150,17 +151,11 @@ inline void Client::Reset() { inline bool Client::RemoveMockResponse(const std::string& method_matcher, const std::string& path_matcher) { - rapidjson::StringBuffer buffer; - rapidjson::Writer writer(buffer); + boost::json::object object; + object.emplace("method", method_matcher); + object.emplace("path", path_matcher); - writer.StartObject(); - writer.Key("method"); - writer.String(method_matcher.c_str()); - writer.Key("path"); - writer.String(path_matcher.c_str()); - writer.EndObject(); - - const auto data = std::string{buffer.GetString()}; + const auto data = boost::json::serialize(object); const auto request_body = std::make_shared>(data.begin(), data.end()); @@ -187,21 +182,16 @@ inline void Client::CreateExpectation(const Expectation& expectation) { inline bool Client::VerifySequence( const std::vector& pathes) const { - rapidjson::StringBuffer buffer; - rapidjson::Writer writer(buffer); - - writer.StartObject(); - writer.Key("httpRequests"); - writer.StartArray(); + boost::json::array array; for (const auto& str : pathes) { - writer.StartObject(); - writer.Key("path"); - writer.String(str.c_str()); - writer.EndObject(); + boost::json::object array_value; + array_value.emplace("path", str); + array.emplace_back(std::move(array_value)); } - writer.EndArray(); - writer.EndObject(); - const auto data = std::string{buffer.GetString()}; + boost::json::object object; + object.emplace("httpRequests", std::move(array)); + + const auto data = boost::json::serialize(object); const auto request_body = std::make_shared>(data.begin(), data.end()); diff --git a/tests/utils/mock-server-client/Expectation.h b/tests/utils/mock-server-client/Expectation.h index 1df46e12e..a6f30b739 100644 --- a/tests/utils/mock-server-client/Expectation.h +++ b/tests/utils/mock-server-client/Expectation.h @@ -1,5 +1,5 @@ /* - * Copyright (C) 2020-2024 HERE Europe B.V. + * Copyright (C) 2020-2026 HERE Europe B.V. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -20,9 +20,13 @@ #pragma once #include +#include #include #include +#include +#include + #include "JsonHelpers.h" namespace mockserver { @@ -67,110 +71,89 @@ struct Expectation { olp::porting::optional times = olp::porting::none; }; -void to_json(const Expectation& x, rapidjson::Value& value, - rapidjson::Document::AllocatorType& allocator); +void to_json(const Expectation& x, boost::json::value& value); void to_json(const Expectation::QueryStringParameter& x, - rapidjson::Value& value, - rapidjson::Document::AllocatorType& allocator); -void to_json(const Expectation::RequestMatcher& x, rapidjson::Value& value, - rapidjson::Document::AllocatorType& allocator); -void to_json(const Expectation::BinaryResponse& x, rapidjson::Value& value, - rapidjson::Document::AllocatorType& allocator); -void to_json(const Expectation::ResponseDelay& x, rapidjson::Value& value, - rapidjson::Document::AllocatorType& allocator); -void to_json(const Expectation::ResponseAction& x, rapidjson::Value& value, - rapidjson::Document::AllocatorType& allocator); -void to_json(const Expectation::ResponseTimes& x, rapidjson::Value& value, - rapidjson::Document::AllocatorType& allocator); + boost::json::value& value); +void to_json(const Expectation::RequestMatcher& x, boost::json::value& value); +void to_json(const Expectation::BinaryResponse& x, boost::json::value& value); +void to_json(const Expectation::ResponseDelay& x, boost::json::value& value); +void to_json(const Expectation::ResponseAction& x, boost::json::value& value); +void to_json(const Expectation::ResponseTimes& x, boost::json::value& value); std::string serialize(const Expectation& object); -inline void to_json(const Expectation& x, rapidjson::Value& value, - rapidjson::Document::AllocatorType& allocator) { - value.SetObject(); - serialize("httpRequest", x.request, value, allocator); +inline void to_json(const Expectation& x, boost::json::value& value) { + auto& object = value.emplace_object(); + serialize("httpRequest", x.request, object); if (x.action != olp::porting::none) { - serialize("httpResponse", x.action, value, allocator); + serialize("httpResponse", x.action, object); } if (x.times != olp::porting::none) { - serialize("times", x.times, value, allocator); + serialize("times", x.times, object); } } inline void to_json(const Expectation::QueryStringParameter& x, - rapidjson::Value& value, - rapidjson::Document::AllocatorType& allocator) { - value.SetObject(); - serialize("name", x.name, value, allocator); - serialize("values", x.values, value, allocator); + boost::json::value& value) { + auto& object = value.emplace_object(); + serialize("name", x.name, object); + serialize("values", x.values, object); } inline void to_json(const Expectation::RequestMatcher& x, - rapidjson::Value& value, - rapidjson::Document::AllocatorType& allocator) { - value.SetObject(); - serialize("path", x.path, value, allocator); - serialize("method", x.method, value, allocator); - serialize("queryStringParameters", x.query_string_parameters, value, - allocator); + boost::json::value& value) { + auto& object = value.emplace_object(); + serialize("path", x.path, object); + serialize("method", x.method, object); + serialize("queryStringParameters", x.query_string_parameters, object); } inline void to_json(const Expectation::BinaryResponse& x, - rapidjson::Value& value, - rapidjson::Document::AllocatorType& allocator) { - value.SetObject(); - serialize("type", x.type, value, allocator); - serialize("base64Bytes", x.base64_string, value, allocator); + boost::json::value& value) { + auto& object = value.emplace_object(); + serialize("type", x.type, object); + serialize("base64Bytes", x.base64_string, object); } inline void to_json(const Expectation::ResponseDelay& x, - rapidjson::Value& value, - rapidjson::Document::AllocatorType& allocator) { - value.SetObject(); - serialize("timeUnit", x.time_unit, value, allocator); - serialize("value", x.value, value, allocator); + boost::json::value& value) { + auto& object = value.emplace_object(); + serialize("timeUnit", x.time_unit, object); + serialize("value", x.value, object); } inline void to_json(const Expectation::ResponseAction& x, - rapidjson::Value& value, - rapidjson::Document::AllocatorType& allocator) { - value.SetObject(); - serialize("statusCode", x.status_code, value, allocator); + boost::json::value& value) { + auto& object = value.emplace_object(); + serialize("statusCode", x.status_code, object); if (x.body.type() == typeid(std::string)) { - serialize("body", olp::porting::any_cast(x.body), value, - allocator); + serialize("body", olp::porting::any_cast(x.body), object); } else if (x.body.type() == typeid(Expectation::BinaryResponse)) { serialize("body", olp::porting::any_cast(x.body), - value, allocator); + object); } if (x.delay) { - serialize("delay", *x.delay, value, allocator); + serialize("delay", *x.delay, object); } } inline void to_json(const Expectation::ResponseTimes& x, - rapidjson::Value& value, - rapidjson::Document::AllocatorType& allocator) { - value.SetObject(); - serialize("remainingTimes", x.remaining_times, value, allocator); - serialize("unlimited", x.unlimited, value, allocator); + boost::json::value& value) { + auto& object = value.emplace_object(); + serialize("remainingTimes", x.remaining_times, object); + serialize("unlimited", x.unlimited, object); } inline std::string serialize(const Expectation& object) { - rapidjson::Document doc; - auto& allocator = doc.GetAllocator(); - - doc.SetObject(); - to_json(object, doc, allocator); + boost::json::value doc; + doc.emplace_object(); + to_json(object, doc); - rapidjson::StringBuffer buffer; - rapidjson::Writer writer(buffer); - doc.Accept(writer); - return buffer.GetString(); + return boost::json::serialize(doc); }; } // namespace mockserver diff --git a/tests/utils/mock-server-client/JsonHelpers.h b/tests/utils/mock-server-client/JsonHelpers.h index fe529f536..386174845 100644 --- a/tests/utils/mock-server-client/JsonHelpers.h +++ b/tests/utils/mock-server-client/JsonHelpers.h @@ -1,5 +1,5 @@ /* - * Copyright (C) 2020 HERE Europe B.V. + * Copyright (C) 2020-2026 HERE Europe B.V. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -19,126 +19,114 @@ #pragma once +#include +#include #include +#include +#include -#include -#include -#include -#include +#include +#include namespace mockserver { -inline void to_json(const std::string& x, rapidjson::Value& value, - rapidjson::Document::AllocatorType& allocator) { - value.SetString(rapidjson::StringRef(x.c_str(), x.size()), allocator); +inline void to_json(const std::string& x, boost::json::value& value) { + value.emplace_string() = x; } -inline void to_json(int32_t x, rapidjson::Value& value, - rapidjson::Document::AllocatorType&) { - value.SetInt(x); +inline void to_json(int32_t x, boost::json::value& value) { + value.emplace_int64() = x; } -inline void to_json(int64_t x, rapidjson::Value& value, - rapidjson::Document::AllocatorType&) { - value.SetInt64(x); +inline void to_json(int64_t x, boost::json::value& value) { + value.emplace_int64() = x; } -inline void to_json(double x, rapidjson::Value& value, - rapidjson::Document::AllocatorType&) { - value.SetDouble(x); +inline void to_json(double x, boost::json::value& value) { + value.emplace_double() = x; } -inline void to_json(bool x, rapidjson::Value& value, - rapidjson::Document::AllocatorType&) { - value.SetBool(x); +inline void to_json(bool x, boost::json::value& value) { + value.emplace_bool() = x; } inline void to_json(const std::shared_ptr>& x, - rapidjson::Value& value, - rapidjson::Document::AllocatorType& allocator) { - value.SetString(reinterpret_cast(x->data()), - static_cast(x->size()), allocator); + boost::json::value& value) { + value.emplace_string() = + boost::json::string_view{reinterpret_cast(x->data()), x->size()}; } template -inline void to_json(const olp::porting::optional& x, rapidjson::Value& value, - rapidjson::Document::AllocatorType& allocator) { +inline void to_json(const olp::porting::optional& x, + boost::json::value& value) { if (x) { - to_json(*x, value, allocator); + to_json(*x, value); } else { - value.SetNull(); + value.emplace_null(); } } template -inline void to_json(const std::map& x, rapidjson::Value& value, - rapidjson::Document::AllocatorType& allocator) { - value.SetObject(); - for (auto itr = x.begin(); itr != x.end(); ++itr) { - const auto& key = itr->first; - rapidjson::Value item_value; - to_json(itr->second, item_value, allocator); - value.AddMember(rapidjson::StringRef(key.c_str(), key.size()), - std::move(item_value), allocator); +inline void to_json(const std::map& x, + boost::json::value& value) { + auto& object = value.emplace_object(); + for (const auto& entry : x) { + boost::json::value item_value; + to_json(entry.second, item_value); + object.emplace(entry.first, std::move(item_value)); } } template -inline void to_json(const std::vector& x, rapidjson::Value& value, - rapidjson::Document::AllocatorType& allocator) { - value.SetArray(); - for (typename std::vector::const_iterator itr = x.begin(); itr != x.end(); - ++itr) { - rapidjson::Value item_value; - to_json(*itr, item_value, allocator); - value.PushBack(std::move(item_value), allocator); +inline void to_json(const std::vector& x, boost::json::value& value) { + auto& array = value.emplace_array(); + for (const auto& entry : x) { + boost::json::value item_value; + to_json(entry, item_value); + array.emplace_back(std::move(item_value)); } } template inline void serialize(const std::string& key, const T& x, - rapidjson::Value& value, - rapidjson::Document::AllocatorType& allocator) { - rapidjson::Value key_value; - to_json(key, key_value, allocator); - rapidjson::Value item_value; - to_json(x, item_value, allocator); - if (!item_value.IsNull()) { - value.AddMember(std::move(key_value), std::move(item_value), allocator); + boost::json::object& value) { + boost::json::value item_value; + to_json(x, item_value); + if (!item_value.is_null()) { + value.emplace(key, std::move(item_value)); } } -inline void from_json(const rapidjson::Value& value, int32_t& x) { - x = value.GetInt(); +inline void from_json(const boost::json::value& value, int32_t& x) { + x = static_cast(value.to_number()); } template -inline void from_json(const rapidjson::Value& value, std::vector& results) { - for (rapidjson::Value::ConstValueIterator itr = value.Begin(); - itr != value.End(); ++itr) { +inline void from_json(const boost::json::value& value, + std::vector& results) { + const auto& array = value.get_array(); + for (const auto& array_value : array) { T result; - from_json(*itr, result); - results.push_back(result); + from_json(array_value, result); + results.emplace_back(std::move(result)); } } template -inline T parse(const rapidjson::Value& value, const std::string& name) { +inline T parse(const boost::json::value& value, const std::string& name) { T result = T(); - rapidjson::Value::ConstMemberIterator itr = value.FindMember(name.c_str()); - if (itr != value.MemberEnd()) { - from_json(itr->value, result); + if (auto* found_value = value.as_object().if_contains(name)) { + from_json(*found_value, result); } return result; } template inline T parse(std::stringstream& json_stream) { - rapidjson::Document doc; - rapidjson::IStreamWrapper stream(json_stream); - doc.ParseStream(stream); + boost::json::error_code ec; + auto doc = boost::json::parse(json_stream, ec); T result{}; - if (doc.IsObject() || doc.IsArray()) { + if (doc.is_object() || doc.is_array()) { from_json(doc, result); } return result; diff --git a/tests/utils/mock-server-client/Status.h b/tests/utils/mock-server-client/Status.h index 9ed0a0cf4..1715969e7 100644 --- a/tests/utils/mock-server-client/Status.h +++ b/tests/utils/mock-server-client/Status.h @@ -1,5 +1,5 @@ /* - * Copyright (C) 2020 HERE Europe B.V. + * Copyright (C) 2020-2026 HERE Europe B.V. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -31,9 +31,9 @@ struct Status { Ports ports; }; -void from_json(const rapidjson::Value& value, Status& x); +void from_json(const boost::json::value& value, Status& x); -inline void from_json(const rapidjson::Value& value, Status& x) { +inline void from_json(const boost::json::value& value, Status& x) { x.ports = parse(value, "ports"); } From 95c61b8691d05a884428e49b1e36da54ba3052cb Mon Sep 17 00:00:00 2001 From: Rustam Gamidov Date: Tue, 31 Mar 2026 10:35:45 +0300 Subject: [PATCH 11/12] Exclude RapidJSON from build Migrating to boost::json Relates-To: OCMAM-447 Signed-off-by: Rustam Gamidov --- README.md | 1 - docs/get-started.md | 2 +- docs/work-with-data-apis.md | 2 +- external/CMakeLists.txt | 9 ----- external/rapidjson/CMakeLists.txt | 35 ----------------- .../rapidjson/CMakeLists.txt.rapidjson.in | 38 ------------------- .../src/generated/parser/CatalogParser.cpp | 3 -- .../generated/serializer/ByteVectorBuffer.h | 3 +- .../src/generated/parser/CatalogParser.cpp | 3 -- .../tests/ParserTest.cpp | 4 +- 10 files changed, 5 insertions(+), 95 deletions(-) delete mode 100644 external/rapidjson/CMakeLists.txt delete mode 100644 external/rapidjson/CMakeLists.txt.rapidjson.in diff --git a/README.md b/README.md index 8910973b3..719ab6ec1 100644 --- a/README.md +++ b/README.md @@ -64,7 +64,6 @@ The table below lists the dependencies of the Data SDK. | Boost (headers only) | 1.82.0 | | LevelDB | 1.21 | | Snappy | 1.1.7 | -| RapidJSON | latest | | Zlib | 1.3.1 | ### Linux dependencies diff --git a/docs/get-started.md b/docs/get-started.md index c26f716c7..a05e9f746 100644 --- a/docs/get-started.md +++ b/docs/get-started.md @@ -71,7 +71,7 @@ cmake --build . --target install CMake is the main build system. The minimal required version of CMake is 3.9. -CMake downloads LevelDB, Snappy, RapidJSON, and Boost. To disable downloading, set `OLP_SDK_BUILD_EXTERNAL_DEPS` to `OFF`. For details on CMake flags, see the [related](#cmake-flags) section. +CMake downloads LevelDB, Snappy, and Boost. To disable downloading, set `OLP_SDK_BUILD_EXTERNAL_DEPS` to `OFF`. For details on CMake flags, see the [related](#cmake-flags) section. **To build the Data SDK:** diff --git a/docs/work-with-data-apis.md b/docs/work-with-data-apis.md index 9ce4de074..4d727a4b9 100644 --- a/docs/work-with-data-apis.md +++ b/docs/work-with-data-apis.md @@ -59,7 +59,7 @@ The example below demonstrates how to use the `olp::client::OlpClient` class fro } ``` -5. If the check passed and the status of the received `olp::client::HttpResponse` is `olp::http::HttpStatusCode::OK` (that is 200 OK), extract the encoded JSON from the response and parse it using RapidJSON or any other JSON parsing library. +5. If the check passed and the status of the received `olp::client::HttpResponse` is `olp::http::HttpStatusCode::OK` (that is 200 OK), extract the encoded JSON from the response and parse it using JSON parsing library. ```cpp std::string response_json; diff --git a/external/CMakeLists.txt b/external/CMakeLists.txt index b81b81125..3a0c8bcd5 100644 --- a/external/CMakeLists.txt +++ b/external/CMakeLists.txt @@ -48,10 +48,6 @@ set(OLP_SDK_CPP_SNAPPY_TAG "1.1.7") set(OLP_SDK_CPP_LEVELDB_URL "https://github.com/google/leveldb.git") set(OLP_SDK_CPP_LEVELDB_TAG "1.21") -set(OLP_SDK_CPP_RAPIDJSON_URL "https://github.com/Tencent/rapidjson.git") -# Next commit after that breaks our build -set(OLP_SDK_CPP_RAPIDJSON_TAG "d621dc9e9c77f81e5c8a35b8dcc16dcd63351321") - set(OLP_SDK_CPP_BOOST_URL "https://github.com/boostorg/boost.git") set(OLP_SDK_CPP_BOOST_TAG "boost-1.82.0") @@ -73,11 +69,6 @@ if(NOT TARGET GTest AND NOT GTest_FOUND) add_subdirectory(googletest) endif() -find_package(RapidJSON 1.1.0 QUIET) -if(NOT TARGET RapidJSON AND NOT RapidJSON_FOUND) - add_subdirectory(rapidjson) -endif() - if(OLP_SDK_ENABLE_DEFAULT_CACHE) find_package(leveldb QUIET) if(NOT TARGET leveldb AND NOT leveldb_FOUND) diff --git a/external/rapidjson/CMakeLists.txt b/external/rapidjson/CMakeLists.txt deleted file mode 100644 index b3f504c04..000000000 --- a/external/rapidjson/CMakeLists.txt +++ /dev/null @@ -1,35 +0,0 @@ -# Copyright (C) 2019-2021 HERE Europe B.V. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# -# SPDX-License-Identifier: Apache-2.0 -# License-Filename: LICENSE - -# RapidJSON -# Download and unpack rapidjson at configure time - -configure_file(CMakeLists.txt.rapidjson.in download/CMakeLists.txt) - -execute_process(COMMAND ${CMAKE_COMMAND} -G "${CMAKE_GENERATOR}" . ${COMMON_GENERATE_FLAGS} - RESULT_VARIABLE result - WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/download) -if(result) - message(FATAL_ERROR "CMake step for rapidjson failed: ${result}") -endif() - -execute_process(COMMAND ${CMAKE_COMMAND} --build . - RESULT_VARIABLE result - WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/download) -if(result) - message(FATAL_ERROR "Build step for rapidjson failed: ${result}") -endif() diff --git a/external/rapidjson/CMakeLists.txt.rapidjson.in b/external/rapidjson/CMakeLists.txt.rapidjson.in deleted file mode 100644 index e8a3fc727..000000000 --- a/external/rapidjson/CMakeLists.txt.rapidjson.in +++ /dev/null @@ -1,38 +0,0 @@ -# Copyright (C) 2019 HERE Europe B.V. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# -# SPDX-License-Identifier: Apache-2.0 -# License-Filename: LICENSE - -cmake_minimum_required(VERSION 3.9) - -project(rapidjson-download NONE) - -include(ExternalProject) -ExternalProject_Add(rapidjson - GIT_REPOSITORY @OLP_SDK_CPP_RAPIDJSON_URL@ - GIT_TAG @OLP_SDK_CPP_RAPIDJSON_TAG@ - GIT_SHALLOW 0 - INSTALL_DIR "@EXTERNAL_BINARY_INSTALL_DIR@" - CMAKE_ARGS @COMMON_PLATFORM_FLAGS@ - -DCMAKE_INSTALL_PREFIX= - -DCMAKE_BUILD_TYPE=@CMAKE_BUILD_TYPE@ - -DRAPIDJSON_BUILD_DOC=OFF - -DRAPIDJSON_BUILD_EXAMPLES=OFF - -DRAPIDJSON_BUILD_TESTS=OFF - -DRAPIDJSON_BUILD_THIRDPARTY_GTEST=OFF - -DRAPIDJSON_ENABLE_INSTRUMENTATION_OPT=OFF - -DCMAKE_EXPORT_NO_PACKAGE_REGISTRY=ON - TEST_COMMAND "" -) diff --git a/olp-cpp-sdk-dataservice-read/src/generated/parser/CatalogParser.cpp b/olp-cpp-sdk-dataservice-read/src/generated/parser/CatalogParser.cpp index 03d05238f..8adc032a1 100644 --- a/olp-cpp-sdk-dataservice-read/src/generated/parser/CatalogParser.cpp +++ b/olp-cpp-sdk-dataservice-read/src/generated/parser/CatalogParser.cpp @@ -63,9 +63,6 @@ void from_json(const boost::json::value& value, model::Schema& x) { } void from_json(const boost::json::value& value, model::StreamProperties& x) { - // Parsing these as double even though OepnAPI sepcs says int64 because - // Backend returns the value in decimal format (e.g. 1.0) and this triggers an - // assert in RapidJSON when parsing. x.SetDataInThroughputMbps( static_cast(parse(value, "dataInThroughputMbps"))); x.SetDataOutThroughputMbps( diff --git a/olp-cpp-sdk-dataservice-read/src/generated/serializer/ByteVectorBuffer.h b/olp-cpp-sdk-dataservice-read/src/generated/serializer/ByteVectorBuffer.h index 5fb64f477..165ae7280 100644 --- a/olp-cpp-sdk-dataservice-read/src/generated/serializer/ByteVectorBuffer.h +++ b/olp-cpp-sdk-dataservice-read/src/generated/serializer/ByteVectorBuffer.h @@ -1,5 +1,5 @@ /* - * Copyright (C) 2024 HERE Europe B.V. + * Copyright (C) 2024-2026 HERE Europe B.V. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -55,7 +55,6 @@ class ByteVectorBuffer { Buffer GetBuffer() { return buffer_; } private: - // Using the same value as rapidjson static constexpr auto kDefaultCapacity = 256u; Buffer buffer_; }; diff --git a/olp-cpp-sdk-dataservice-write/src/generated/parser/CatalogParser.cpp b/olp-cpp-sdk-dataservice-write/src/generated/parser/CatalogParser.cpp index 1d6f7ba96..fce79d7fa 100644 --- a/olp-cpp-sdk-dataservice-write/src/generated/parser/CatalogParser.cpp +++ b/olp-cpp-sdk-dataservice-write/src/generated/parser/CatalogParser.cpp @@ -63,9 +63,6 @@ void from_json(const boost::json::value& value, model::Schema& x) { } void from_json(const boost::json::value& value, model::StreamProperties& x) { - // Parsing these as double even though OepnAPI sepcs says int64 because - // Backend returns the value in decimal format (e.g. 1.0) and this triggers an - // assert in RapidJSON when parsing. x.SetDataInThroughputMbps( static_cast(parse(value, "dataInThroughputMbps"))); x.SetDataOutThroughputMbps( diff --git a/olp-cpp-sdk-dataservice-write/tests/ParserTest.cpp b/olp-cpp-sdk-dataservice-write/tests/ParserTest.cpp index 60c7bf37d..45a1679a5 100644 --- a/olp-cpp-sdk-dataservice-write/tests/ParserTest.cpp +++ b/olp-cpp-sdk-dataservice-write/tests/ParserTest.cpp @@ -333,8 +333,8 @@ TEST(ParserTest, Catalog) { // TODO Test specfically for handling of OLP Backend bug: // Parse dataOutThroughputMbps, dataInThroughputMbps as double even though -// OepnAPI sepcs says int64 because OLP Backend returns the value in decimal -// format (e.g. 1.0) and this triggers an assert in RapidJSON when parsing. +// OpenAPI sepcs says int64 because OLP Backend returns the value in decimal +// format (e.g. 1.0). TEST(ParserTest, CatalogCrash) { std::string json_input = "{\"id\":\"olp-cpp-sdk-ingestion-test-catalog\",\"hrn\":\"hrn:here:data::" From e7eef11d7b6876ab6dbbd921347aea66ba83f1d2 Mon Sep 17 00:00:00 2001 From: Rustam Gamidov Date: Tue, 31 Mar 2026 11:08:47 +0300 Subject: [PATCH 12/12] Skip clang no exception build Boost date_time has no 'no_exception' setup and clang is compiling that code even if it's not used. GCC is OK Relates-To: OCMAM-447 Signed-off-by: Rustam Gamidov --- .github/workflows/psv_pipelines.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/psv_pipelines.yml b/.github/workflows/psv_pipelines.yml index 16cb1deed..be86659d2 100644 --- a/.github/workflows/psv_pipelines.yml +++ b/.github/workflows/psv_pipelines.yml @@ -197,14 +197,14 @@ jobs: shell: bash psv-linux-22-04-clang-hidden-build: - name: PSV.Linux.22.04.clang.hidden.OLP_SDK_NO_EXCEPTION=ON + name: PSV.Linux.22.04.clang.hidden runs-on: ubuntu-22.04 env: BUILD_TYPE: RelWithDebInfo CC: clang-11 CXX: clang++-11 CXXFLAGS: -Wno-deprecated-copy - EXTRA_CMAKE_OPTIONS: -DCMAKE_CXX_VISIBILITY_PRESET=hidden -DOLP_SDK_ENABLE_TESTING=OFF -DOLP_SDK_NO_EXCEPTION=ON + EXTRA_CMAKE_OPTIONS: -DCMAKE_CXX_VISIBILITY_PRESET=hidden -DOLP_SDK_ENABLE_TESTING=OFF steps: - name: Check out repository uses: actions/checkout@v4