Page Menu
Home
Phorge
Search
Configure Global Search
Log In
Files
F140218
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Award Token
Flag For Later
Size
18 KB
Referenced Files
None
Subscribers
None
View Options
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 024bfb9..941edc9 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -1,151 +1,151 @@
# Do not let the option()s override variables here
cmake_minimum_required(VERSION 3.13)
if(NOT DEFINED PROJECT_NAME)
if(NOT DEFINED libkazv_INSTALL_HEADERS)
set(libkazv_INSTALL_HEADERS ON)
endif()
endif()
project(libkazv)
set(libkazvSourceRoot ${CMAKE_CURRENT_SOURCE_DIR})
set(libkazv_VERSION_MAJOR 0)
set(libkazv_VERSION_MINOR 1)
set(libkazv_VERSION_PATCH 0)
set(libkazv_VERSION_STRING ${libkazv_VERSION_MAJOR}.${libkazv_VERSION_MINOR}.${libkazv_VERSION_PATCH})
set(libkazv_SOVERSION 1)
set(CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake" ${CMAKE_MODULE_PATH})
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wextra")
option(libkazv_BUILD_TESTS "Build tests" ON)
option(libkazv_BUILD_EXAMPLES "Build examples" ON)
option(libkazv_BUILD_KAZVJOB "Build libkazvjob the async and networking library" ON)
option(libkazv_OUTPUT_LEVEL "Output level: Debug>=90, Info>=70, Quiet>=20, no output=1" 0)
option(libkazv_ENABLE_COVERAGE "Enable code coverage information" OFF)
if(libkazv_ENABLE_COVERAGE)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fprofile-arcs -ftest-coverage -fPIC -O0")
endif()
if((libkazv_BUILD_TESTS OR libkazv_BUILD_EXAMPLES) AND NOT libkazv_BUILD_KAZVJOB)
message(FATAL_ERROR
"You asked kazvjob not to be built, but asked to build tests or examples. Tests and examples both depend on kazvjob. This is not possible.")
endif()
# Build shared libraries by default
if(NOT DEFINED BUILD_SHARED_LIBS)
set(BUILD_SHARED_LIBS ON)
endif()
-find_package(Boost REQUIRED)
+find_package(Boost REQUIRED COMPONENTS serialization)
include(FetchContent)
if(libkazv_BUILD_KAZVJOB)
find_package(cpr)
if (NOT cpr_FOUND)
message( STATUS "Using cpr from FetchContent")
set(USE_SYSTEM_CURL ON)
set(BUILD_CPR_TESTS OFF)
FetchContent_Declare(cpr GIT_REPOSITORY https://github.com/whoshuu/cpr.git GIT_TAG c34ddb9b3de2a22fdbd5d318d8b7d1997e6ca0bf)
FetchContent_MakeAvailable(cpr)
endif()
set(THREADS_PREFER_PTHREAD_FLAG ON)
find_package(Threads REQUIRED)
endif()
if(libkazv_BUILD_TESTS)
find_package(Catch2)
if (NOT Catch2_FOUND)
message(STATUS "Using Catch2 from FetchContent")
FetchContent_Declare(Catch2 GIT_REPOSITORY https://github.com/catchorg/Catch2 GIT_TAG v2.13.0)
FetchContent_MakeAvailable(Catch2)
endif()
endif()
find_package(nlohmann_json)
if (NOT nlohmann_json_FOUND)
message(STATUS "Using nlohmann_json from FetchContent")
set(JSON_BuildTests OFF)
FetchContent_Declare(nlohmann_json GIT_REPOSITORY https://github.com/nlohmann/json GIT_TAG v3.9.1)
FetchContent_MakeAvailable(nlohmann_json)
endif()
find_package(Immer)
if(NOT Immer_FOUND)
message(STATUS "Using Immer from FetchContent")
set(immer_BUILD_TESTS OFF)
set(immer_BUILD_EXAMPLES OFF)
set(immer_BUILD_DOCS OFF)
set(immer_BUILD_EXTRAS OFF)
FetchContent_Declare(immer GIT_REPOSITORY https://github.com/arximboldi/immer GIT_TAG
800ddb04e528a3e83e69e8021d7e872e7c34cbcd)
FetchContent_MakeAvailable(immer)
endif()
find_package(Zug)
if(NOT Zug_FOUND)
message(STATUS "Using zug from FetchContent")
set(zug_BUILD_TESTS OFF)
set(zug_BUILD_EXAMPLES OFF)
set(zug_BUILD_DOCS OFF)
FetchContent_Declare(zug GIT_REPOSITORY https://github.com/arximboldi/zug GIT_TAG
266cc7fcc01f546c4fd0dabf3a26c71ddc7f3e7d)
FetchContent_MakeAvailable(zug)
endif()
find_package(Lager)
if(NOT Lager_FOUND)
message(STATUS "Using lager from FetchContent")
set(lager_BUILD_TESTS OFF)
set(lager_BUILD_EXAMPLES OFF)
set(lager_BUILD_DOCS OFF)
set(lager_EMBED_RESOURCES_PATH OFF)
FetchContent_Declare(lager GIT_REPOSITORY https://github.com/arximboldi/lager GIT_TAG
71eca6b0ebbccf3e0e54324b6967f047e49ba92d)
FetchContent_MakeAvailable(lager)
endif()
find_package(cereal)
if(NOT cereal_FOUND)
set(JUST_INSTALL_CEREAL ON)
FetchContent_Declare(cereal GIT_REPOSITORY https://github.com/USCiLab/cereal GIT_TAG v1.3.0)
FetchContent_MakeAvailable(cereal)
endif()
find_package(Olm REQUIRED)
if(libkazv_BUILD_EXAMPLES)
find_package(PkgConfig REQUIRED)
pkg_check_modules(LIBHTTPSERVER REQUIRED libhttpserver)
endif()
if(libkazv_OUTPUT_LEVEL)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DLIBKAZV_OUTPUT_LEVEL=${libkazv_OUTPUT_LEVEL}")
endif()
set(ConfigPackageLocation lib/cmake/libkazv)
add_subdirectory(src)
install(EXPORT libkazvTargets
NAMESPACE
libkazv::
DESTINATION
${ConfigPackageLocation}
)
install(
FILES cmake/libkazvConfig.cmake
DESTINATION ${ConfigPackageLocation})
# cpr does not install a good config file.
# We use the find module instead.
install(
FILES cmake/Findcpr.cmake
DESTINATION ${ConfigPackageLocation})
diff --git a/src/base/CMakeLists.txt b/src/base/CMakeLists.txt
index c838f69..c09668f 100644
--- a/src/base/CMakeLists.txt
+++ b/src/base/CMakeLists.txt
@@ -1,27 +1,28 @@
include(linklibsys)
set(kazvbase_SRCS
debug.cpp
event.cpp
basejob.cpp
file-desc.cpp
)
add_library(kazvbase ${kazvbase_SRCS})
add_library(libkazv::kazvbase ALIAS kazvbase)
set_target_properties(kazvbase PROPERTIES VERSION ${libkazv_VERSION_STRING} SOVERSION ${libkazv_SOVERSION})
target_link_libraries_system(kazvbase
PUBLIC nlohmann_json::nlohmann_json
immer
zug
lager
- cereal)
+ cereal
+ Boost::serialization)
target_include_directories(kazvbase
INTERFACE
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}>
$<INSTALL_INTERFACE:include/kazv/base>
)
install(TARGETS kazvbase EXPORT libkazvTargets LIBRARY)
diff --git a/src/base/serialization/immer-array.hpp b/src/base/serialization/immer-array.hpp
new file mode 100644
index 0000000..ba13f8a
--- /dev/null
+++ b/src/base/serialization/immer-array.hpp
@@ -0,0 +1,74 @@
+/*
+ * Copyright (C) 2021 Tusooa Zhu <tusooa@kazv.moe>
+ *
+ * This file is part of libkazv.
+ *
+ * libkazv is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * libkazv is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with libkazv. If not, see <https://www.gnu.org/licenses/>.
+ */
+
+#pragma once
+
+#include <libkazv-config.hpp>
+
+#include <boost/serialization/nvp.hpp>
+
+#include <immer/array.hpp>
+#include <immer/array_transient.hpp>
+
+namespace boost::serialization
+{
+ template<class Archive,
+ class T,
+ class MP>
+ void save(Archive &ar, const immer::array<T, MP> &v, const unsigned int /* version */)
+ {
+ auto size = v.size();
+ ar << BOOST_SERIALIZATION_NVP(size);
+
+ for (const auto &i : v) {
+ ar << i;
+ }
+ }
+
+ template<class Archive,
+ class T,
+ class MP>
+ void load(Archive &ar, immer::array<T, MP> &v, const unsigned int /* version */)
+ {
+ using VecT = immer::array<T, MP>;
+ using TransientT = decltype(v.transient());
+ using SizeT = decltype(v.size());
+ using ValueT = typename VecT::value_type;
+
+ SizeT size{};
+ ar >> BOOST_SERIALIZATION_NVP(size);
+ TransientT transient = VecT(size).transient();
+
+ for (auto i = SizeT{}; i != size; ++i) {
+ ValueT val;
+ ar >> val;
+ transient.set(i, std::move(val));
+ }
+
+ v = transient.persistent();
+ }
+
+ template<class Archive,
+ class T,
+ class MP>
+ inline void serialize(Archive &ar, immer::array<T, MP> &v, const unsigned int version)
+ {
+ boost::serialization::split_free(ar, v, version);
+ }
+}
diff --git a/src/base/serialization/immer-box.hpp b/src/base/serialization/immer-box.hpp
new file mode 100644
index 0000000..08ef479
--- /dev/null
+++ b/src/base/serialization/immer-box.hpp
@@ -0,0 +1,53 @@
+/*
+ * Copyright (C) 2021 Tusooa Zhu <tusooa@kazv.moe>
+ *
+ * This file is part of libkazv.
+ *
+ * libkazv is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * libkazv is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with libkazv. If not, see <https://www.gnu.org/licenses/>.
+ */
+
+
+#pragma once
+
+#include <libkazv-config.hpp>
+
+#include <boost/serialization/nvp.hpp>
+
+#include <immer/box.hpp>
+
+namespace boost::serialization
+{
+
+ template <class Archive, class T, class MP>
+ void save(Archive &ar, const immer::box<T, MP> &box, const unsigned int /* version */)
+ {
+ ar << box.get();
+ }
+
+ template <class Archive, class T, class MP>
+ void load(Archive &ar, immer::box<T, MP> &box, const unsigned int /* version */)
+ {
+ T val;
+ ar >> val;
+
+ box = val;
+ }
+
+ template<class Archive, class T, class MP>
+ inline void serialize(Archive &ar, immer::box<T, MP> &box, const unsigned int version)
+ {
+ boost::serialization::split_free(ar, box, version);
+ }
+
+}
diff --git a/src/base/serialization/immer-flex-vector.hpp b/src/base/serialization/immer-flex-vector.hpp
new file mode 100644
index 0000000..b82af72
--- /dev/null
+++ b/src/base/serialization/immer-flex-vector.hpp
@@ -0,0 +1,80 @@
+/*
+ * Copyright (C) 2021 Tusooa Zhu <tusooa@kazv.moe>
+ *
+ * This file is part of libkazv.
+ *
+ * libkazv is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * libkazv is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with libkazv. If not, see <https://www.gnu.org/licenses/>.
+ */
+
+#pragma once
+
+#include <libkazv-config.hpp>
+
+#include <boost/serialization/nvp.hpp>
+
+#include <immer/flex_vector.hpp>
+#include <immer/flex_vector_transient.hpp>
+
+namespace boost::serialization
+{
+ template<class Archive,
+ class T,
+ class MP,
+ std::uint32_t B,
+ std::uint32_t BL>
+ void save(Archive &ar, const immer::flex_vector<T, MP, B, BL> &v, const unsigned int /* version */)
+ {
+ auto size = v.size();
+ ar << BOOST_SERIALIZATION_NVP(size);
+
+ for (const auto &i : v) {
+ ar << i;
+ }
+ }
+
+ template<class Archive,
+ class T,
+ class MP,
+ std::uint32_t B,
+ std::uint32_t BL>
+ void load(Archive &ar, immer::flex_vector<T, MP, B, BL> &v, const unsigned int /* version */)
+ {
+ using VecT = immer::flex_vector<T, MP, B, BL>;
+ using TransientT = decltype(v.transient());
+ using SizeT = decltype(v.size());
+ using ValueT = typename VecT::value_type;
+
+ SizeT size{};
+ ar >> BOOST_SERIALIZATION_NVP(size);
+ TransientT transient = VecT(size).transient();
+
+ for (auto i = SizeT{}; i != size; ++i) {
+ ValueT val;
+ ar >> val;
+ transient.set(i, std::move(val));
+ }
+
+ v = transient.persistent();
+ }
+
+ template<class Archive,
+ class T,
+ class MP,
+ std::uint32_t B,
+ std::uint32_t BL>
+ inline void serialize(Archive &ar, immer::flex_vector<T, MP, B, BL> &v, const unsigned int version)
+ {
+ boost::serialization::split_free(ar, v, version);
+ }
+}
diff --git a/src/base/serialization/immer-map.hpp b/src/base/serialization/immer-map.hpp
new file mode 100644
index 0000000..0542bba
--- /dev/null
+++ b/src/base/serialization/immer-map.hpp
@@ -0,0 +1,70 @@
+/*
+ * Copyright (C) 2021 Tusooa Zhu <tusooa@kazv.moe>
+ *
+ * This file is part of libkazv.
+ *
+ * libkazv is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * libkazv is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with libkazv. If not, see <https://www.gnu.org/licenses/>.
+ */
+
+
+#pragma once
+
+#include <libkazv-config.hpp>
+
+#include <boost/serialization/nvp.hpp>
+
+#include <immer/map.hpp>
+
+namespace boost::serialization
+{
+
+ template <class Archive, class K, class T, class H, class E, class MP>
+ void save(Archive &ar, const immer::map<K, T, H, E, MP> &map, const unsigned int /* version */)
+ {
+ auto size = map.size();
+ ar << BOOST_SERIALIZATION_NVP(size);
+ for (const auto &[k, v] : map) {
+ ar << k << v;
+ }
+ }
+
+ template <class Archive, class K, class T, class H, class E, class MP>
+ void load(Archive &ar, immer::map<K, T, H, E, MP> &map, const unsigned int /* version */)
+ {
+ // map transient is not yet implemented
+ // using TransientT = decltype(v.transient());
+ using SizeT = decltype(map.size());
+
+ map = {};
+
+ SizeT size{};
+ ar >> BOOST_SERIALIZATION_NVP(size);
+
+ for (auto i = SizeT{}; i < size; ++i) {
+ K k;
+ T v;
+ ar >> k >> v;
+ map = std::move(map).set(std::move(k), std::move(v));
+ }
+
+ assert(size == map.size());
+ }
+
+ template<class Archive, class K, class T, class H, class E, class MP>
+ inline void serialize(Archive &ar, immer::map<K, T, H, E, MP> &m, const unsigned int version)
+ {
+ boost::serialization::split_free(ar, m, version);
+ }
+
+}
diff --git a/src/tests/CMakeLists.txt b/src/tests/CMakeLists.txt
index 00f5067..fa4b1a6 100644
--- a/src/tests/CMakeLists.txt
+++ b/src/tests/CMakeLists.txt
@@ -1,40 +1,41 @@
include(CTest)
set(KAZVTEST_RESPATH ${CMAKE_CURRENT_SOURCE_DIR}/resources)
configure_file(kazvtest-respath.hpp.in kazvtest-respath.hpp)
add_executable(kazvtest
testmain.cpp
basejobtest.cpp
event-test.cpp
cursorutiltest.cpp
client/client-test-util.cpp
client/sync-test.cpp
client/content-test.cpp
client/paginate-test.cpp
client/util-test.cpp
+ base/serialization-test.cpp
kazvjobtest.cpp
event-emitter-test.cpp
crypto-test.cpp
promise-test.cpp
store-test.cpp
file-desc-test.cpp
)
target_include_directories(
kazvtest
PRIVATE ${CMAKE_CURRENT_BINARY_DIR})
target_link_libraries(kazvtest
PRIVATE Catch2::Catch2
PRIVATE kazv
PRIVATE kazveventemitter
PRIVATE kazvjob
PRIVATE nlohmann_json::nlohmann_json
PRIVATE immer
PRIVATE lager
PRIVATE zug)
diff --git a/src/tests/base/serialization-test.cpp b/src/tests/base/serialization-test.cpp
new file mode 100644
index 0000000..9d1fb7a
--- /dev/null
+++ b/src/tests/base/serialization-test.cpp
@@ -0,0 +1,122 @@
+/*
+ * Copyright (C) 2021 Tusooa Zhu <tusooa@kazv.moe>
+ *
+ * This file is part of libkazv.
+ *
+ * libkazv is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * libkazv is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with libkazv. If not, see <https://www.gnu.org/licenses/>.
+ */
+
+#include <libkazv-config.hpp>
+
+#include <catch2/catch.hpp>
+
+#include <sstream>
+#include <boost/archive/text_iarchive.hpp>
+#include <boost/archive/text_oarchive.hpp>
+
+#include <serialization/immer-flex-vector.hpp>
+#include <serialization/immer-map.hpp>
+#include <serialization/immer-box.hpp>
+#include <serialization/immer-array.hpp>
+
+//using namespace Kazv;
+using IAr = boost::archive::text_iarchive;
+using OAr = boost::archive::text_oarchive;
+
+TEST_CASE("Serialize immer::array", "[base][serialization]")
+{
+ immer::array<int> v{1, 2, 3, 4, 5};
+ immer::array<int> v2{50};
+
+ std::stringstream stream;
+
+ {
+ auto ar = OAr(stream);
+ ar << v;
+ }
+
+ {
+ auto ar = IAr(stream);
+ ar >> v2;
+ }
+
+ REQUIRE(v == v2);
+}
+
+
+TEST_CASE("Serialize immer::flex_vector", "[base][serialization]")
+{
+ immer::flex_vector<int> v{1, 2, 3, 4, 5};
+ immer::flex_vector<int> v2{50};
+
+ std::stringstream stream;
+
+ {
+ auto ar = OAr(stream);
+ ar << v;
+ }
+
+ {
+ auto ar = IAr(stream);
+ ar >> v2;
+ }
+
+ REQUIRE(v == v2);
+}
+
+TEST_CASE("Serialize immer::map", "[base][serialization]")
+{
+ auto v = immer::map<int, int>{}
+ .set(1, 6)
+ .set(2, 7)
+ .set(3, 8)
+ .set(4, 9)
+ .set(5, 10);
+ auto v2 = immer::map<int, int>{}.set(10, 7);
+
+ std::stringstream stream;
+
+ {
+ auto ar = OAr(stream);
+ ar << v;
+ }
+
+ {
+ auto ar = IAr(stream);
+ ar >> v2;
+ }
+
+ REQUIRE(v == v2);
+}
+
+TEST_CASE("Serialize immer::box", "[base][serialization]")
+{
+
+ auto v = immer::box<int>{42};
+ immer::box<int> v2;
+
+ std::stringstream stream;
+
+ {
+ auto ar = OAr(stream);
+ ar << v;
+ }
+
+ {
+ auto ar = IAr(stream);
+ ar >> v2;
+ }
+
+ REQUIRE(v == v2);
+}
File Metadata
Details
Attached
Mime Type
text/x-diff
Expires
Sun, Jan 19, 3:29 PM (1 d, 3 h)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
55270
Default Alt Text
(18 KB)
Attached To
Mode
rL libkazv
Attached
Detach File
Event Timeline
Log In to Comment