let azure core provide json interface (#1004)
* let azure core provide json interface
This commit is contained in:
parent
847e769576
commit
c9c12e27aa
27
cmake-modules/add_nlohmann_json.cmake
Normal file
27
cmake-modules/add_nlohmann_json.cmake
Normal file
@ -0,0 +1,27 @@
|
||||
# Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
# SPDX-License-Identifier: MIT
|
||||
#
|
||||
# Azure Core can expose the Nlohmann Json header by fetching a release version and including the header to the include path.
|
||||
#
|
||||
# Azure Core will try to find the json header first. This is for an application that is already using Nlohmann header.
|
||||
# When it is not found it, Azure Core will fetch it.
|
||||
|
||||
# Storage requires 3.6.0 version for using `contains` feature
|
||||
# Using QUIET to avoid warning message if lib is not found
|
||||
find_package(nlohmann_json 3.6.0 EXACT QUIET)
|
||||
if (NOT nlohmann_json_FOUND)
|
||||
|
||||
include(FetchContent)
|
||||
|
||||
# release code only. This save us from getting the entire nlohmann source code.
|
||||
FetchContent_Declare(json
|
||||
GIT_REPOSITORY https://github.com/ArthurSonzogni/nlohmann_json_cmake_fetchcontent
|
||||
GIT_TAG v3.8.0)
|
||||
|
||||
FetchContent_GetProperties(json)
|
||||
if (NOT json_POPULATED)
|
||||
FetchContent_Populate(json)
|
||||
add_subdirectory(${json_SOURCE_DIR} ${json_BINARY_DIR} EXCLUDE_FROM_ALL)
|
||||
endif()
|
||||
|
||||
endif()
|
||||
@ -31,6 +31,9 @@ endif()
|
||||
# CodeCoverage will validate requirements
|
||||
include(CodeCoverage)
|
||||
|
||||
# nlohmann JSON
|
||||
include(add_nlohmann_json)
|
||||
|
||||
add_library (
|
||||
${TARGET_NAME}
|
||||
src/context.cpp
|
||||
@ -63,6 +66,7 @@ create_code_coverage(core ${TARGET_NAME} "${TARGET_NAME}-test")
|
||||
|
||||
target_include_directories(${TARGET_NAME} PUBLIC ${CURL_INCLUDE_DIRS})
|
||||
target_link_libraries(${TARGET_NAME} PRIVATE CURL::libcurl Threads::Threads)
|
||||
target_link_libraries(${TARGET_NAME} INTERFACE nlohmann_json::nlohmann_json)
|
||||
|
||||
get_az_version("${CMAKE_CURRENT_SOURCE_DIR}/inc/azure/core/version.hpp")
|
||||
generate_documentation(azure-core ${AZ_LIBRARY_VERSION})
|
||||
|
||||
@ -32,6 +32,7 @@ add_executable (
|
||||
curl_session_test.cpp
|
||||
datetime.cpp
|
||||
http.cpp
|
||||
json.cpp
|
||||
logging.cpp
|
||||
main.cpp
|
||||
nullable.cpp
|
||||
|
||||
17
sdk/core/azure-core/test/ut/json.cpp
Normal file
17
sdk/core/azure-core/test/ut/json.cpp
Normal file
@ -0,0 +1,17 @@
|
||||
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
// SPDX-License-Identifier: MIT
|
||||
|
||||
#include "gtest/gtest.h"
|
||||
#include <nlohmann/json.hpp>
|
||||
|
||||
using json = nlohmann::json;
|
||||
|
||||
// Just a simple test to ensure that Azure Core is bringing nlohmann header
|
||||
TEST(Json, create)
|
||||
{
|
||||
json j;
|
||||
j["pi"] = 3.141;
|
||||
std::string expected("{\"pi\":3.141}");
|
||||
|
||||
EXPECT_EQ(expected, j.dump());
|
||||
}
|
||||
@ -40,11 +40,13 @@ namespace Azure { namespace Core { namespace Test {
|
||||
Azure::Core::Http::CurlConnectionPool::ClearIndex();
|
||||
|
||||
auto threadRoutine = [&]() {
|
||||
using namespace std::chrono_literals;
|
||||
auto request = Azure::Core::Http::Request(Azure::Core::Http::HttpMethod::Get, host);
|
||||
auto response = m_pipeline->Send(Azure::Core::GetApplicationContext(), request);
|
||||
checkResponseCode(response->GetStatusCode());
|
||||
auto expectedResponseBodySize = std::stoull(response->GetHeaders().at("content-length"));
|
||||
CheckBodyFromBuffer(*response, expectedResponseBodySize);
|
||||
std::this_thread::sleep_for(1s);
|
||||
};
|
||||
|
||||
std::thread t1(threadRoutine);
|
||||
|
||||
@ -10,7 +10,6 @@ set(AZURE_STORAGE_COMMON_HEADER
|
||||
inc/azure/storage/common/constants.hpp
|
||||
inc/azure/storage/common/crypt.hpp
|
||||
inc/azure/storage/common/file_io.hpp
|
||||
inc/azure/storage/common/json.hpp
|
||||
inc/azure/storage/common/reliable_stream.hpp
|
||||
inc/azure/storage/common/shared_key_policy.hpp
|
||||
inc/azure/storage/common/storage_common.hpp
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@ -5,10 +5,10 @@
|
||||
|
||||
#include "azure/core/http/policy.hpp"
|
||||
#include "azure/storage/common/constants.hpp"
|
||||
#include "azure/storage/common/json.hpp"
|
||||
#include "azure/storage/common/storage_common.hpp"
|
||||
#include "azure/storage/common/xml_wrapper.hpp"
|
||||
|
||||
#include <nlohmann/json.hpp>
|
||||
#include <type_traits>
|
||||
|
||||
namespace Azure { namespace Storage {
|
||||
|
||||
@ -9,7 +9,6 @@
|
||||
#include "azure/core/nullable.hpp"
|
||||
#include "azure/core/response.hpp"
|
||||
#include "azure/storage/common/crypt.hpp"
|
||||
#include "azure/storage/common/json.hpp"
|
||||
#include "azure/storage/common/storage_common.hpp"
|
||||
#include "azure/storage/common/storage_exception.hpp"
|
||||
|
||||
@ -17,6 +16,7 @@
|
||||
#include <iostream>
|
||||
#include <map>
|
||||
#include <memory>
|
||||
#include <nlohmann/json.hpp>
|
||||
#include <stdexcept>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
@ -10,11 +10,11 @@
|
||||
#include "azure/core/response.hpp"
|
||||
#include "azure/core/strings.hpp"
|
||||
#include "azure/storage/common/crypt.hpp"
|
||||
#include "azure/storage/common/json.hpp"
|
||||
#include "azure/storage/common/storage_common.hpp"
|
||||
#include "azure/storage/common/storage_exception.hpp"
|
||||
#include "azure/storage/common/xml_wrapper.hpp"
|
||||
|
||||
#include <nlohmann/json.hpp>
|
||||
#include <functional>
|
||||
#include <iostream>
|
||||
#include <map>
|
||||
|
||||
Loading…
Reference in New Issue
Block a user