Skip to content

Commit 75597e1

Browse files
committed
Added zpp serialization library.
1 parent 4ed2bdb commit 75597e1

File tree

3 files changed

+117
-5
lines changed

3 files changed

+117
-5
lines changed

CMakeLists.txt

+17-5
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,9 @@ include(ExternalProject)
1313

1414
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
1515

16-
CHECK_CXX_COMPILER_FLAG("-std=c++11" CXX11)
17-
if (NOT CXX11)
18-
message(FATAL_ERROR "C++ compiler doesn't support C++11")
16+
CHECK_CXX_COMPILER_FLAG("-std=c++14" CXX14)
17+
if (NOT CXX14)
18+
message(FATAL_ERROR "C++ compiler doesn't support C++14")
1919
endif()
2020

2121
CHECK_INCLUDE_FILES("inttypes.h" HAVE_INTTYPES_H)
@@ -157,6 +157,18 @@ ExternalProject_Add(
157157
)
158158
include_directories(${cereal_PREFIX}/include)
159159

160+
set(zpp_PREFIX ${CMAKE_CURRENT_BINARY_DIR}/external/zpp)
161+
ExternalProject_Add(
162+
zpp
163+
PREFIX ${zpp_PREFIX}
164+
URL "https://github.com/eyalz800/serializer/archive/v0.1.tar.gz"
165+
URL_MD5 "96f1db7d8f80917d730cbb1a8d7f2fbe"
166+
CONFIGURE_COMMAND ""
167+
BUILD_COMMAND ""
168+
INSTALL_COMMAND mkdir -p ${zpp_PREFIX}/include/ && cp -r ${zpp_PREFIX}/src/zpp ${zpp_PREFIX}/include/
169+
)
170+
include_directories(${zpp_PREFIX}/include)
171+
160172
set(avro_PREFIX ${CMAKE_CURRENT_BINARY_DIR}/external/avro)
161173
ExternalProject_Add(
162174
avro
@@ -305,6 +317,6 @@ add_executable(
305317
${FLATBUFFERS_SERIALIZATION_SOURCES}
306318
${YAS_SERIALIZATION_SOURCES}
307319
)
308-
add_dependencies(benchmark thrift msgpack protobuf capnproto boost cereal avro flatbuffers yas)
320+
add_dependencies(benchmark thrift msgpack protobuf capnproto boost cereal avro flatbuffers yas zpp)
309321
target_link_libraries(benchmark ${LINKLIBS})
310-
set_target_properties(benchmark PROPERTIES COMPILE_FLAGS "-std=c++11")
322+
set_target_properties(benchmark PROPERTIES COMPILE_FLAGS "-std=c++14")

benchmark.cpp

+49
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
#include "avro/record.hpp"
2828
#include "flatbuffers/test_generated.h"
2929
#include "yas/record.hpp"
30+
#include "zpp/record.hpp"
3031

3132
#include "data.hpp"
3233

@@ -518,6 +519,50 @@ yas_serialization_test(size_t iterations)
518519
}
519520
}
520521

522+
void
523+
zpp_serialization_test(size_t iterations)
524+
{
525+
using namespace zpp_test;
526+
527+
Record r1, r2;
528+
529+
for (size_t i = 0; i < kIntegers.size(); i++) {
530+
r1.ids.push_back(kIntegers[i]);
531+
}
532+
533+
for (size_t i = 0; i < kStringsCount; i++) {
534+
r1.strings.push_back(kStringValue);
535+
}
536+
537+
std::string serialized;
538+
539+
to_string(r1, serialized);
540+
from_string(r2, serialized);
541+
542+
if (r1 != r2) {
543+
throw std::logic_error("zpp' case: deserialization failed");
544+
}
545+
546+
std::vector<unsigned char> data;
547+
data.reserve(serialized.size());
548+
549+
std::cout << "zpp: version = " << "v0.1" << std::endl;
550+
std::cout << "zpp: size = " << serialized.size() << " bytes" << std::endl;
551+
552+
auto start = std::chrono::high_resolution_clock::now();
553+
for (size_t i = 0; i < iterations; i++) {
554+
zpp::serializer::memory_output_archive out(data);
555+
out(r1);
556+
557+
zpp::serializer::memory_input_archive in(data);
558+
in(r1);
559+
}
560+
auto finish = std::chrono::high_resolution_clock::now();
561+
auto duration = std::chrono::duration_cast<std::chrono::milliseconds>(finish - start).count();
562+
563+
std::cout << "zpp: time = " << duration << " milliseconds" << std::endl << std::endl;
564+
}
565+
521566
int
522567
main(int argc, char** argv)
523568
{
@@ -598,6 +643,10 @@ main(int argc, char** argv)
598643
if (names.empty() || names.find("yas-compact") != names.end()) {
599644
yas_serialization_test<yas::binary | yas::no_header | yas::compacted>(iterations);
600645
}
646+
647+
if (names.empty() || names.find("zpp") != names.end()) {
648+
zpp_serialization_test(iterations);
649+
}
601650
} catch (std::exception& exc) {
602651
std::cerr << "Error: " << exc.what() << std::endl;
603652
return EXIT_FAILURE;

zpp/record.hpp

+51
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
2+
#ifndef __ZPP_RECORD_HPP_INCLUDED__
3+
#define __ZPP_RECORD_HPP_INCLUDED__
4+
5+
#include <vector>
6+
#include <string>
7+
8+
#include <stdint.h>
9+
10+
#include "zpp/serializer.h"
11+
12+
namespace zpp_test {
13+
14+
typedef std::vector<int64_t> Integers;
15+
typedef std::vector<std::string> Strings;
16+
17+
struct Record {
18+
19+
Integers ids;
20+
Strings strings;
21+
22+
bool operator==(const Record &other) {
23+
return (ids == other.ids && strings == other.strings);
24+
}
25+
26+
bool operator!=(const Record &other) {
27+
return !(*this == other);
28+
}
29+
30+
template <typename Archive, typename Self>
31+
static void serialize(Archive & archive, Self & self)
32+
{
33+
archive(self.ids, self.strings);
34+
}
35+
};
36+
37+
inline void to_string(const Record &record, std::string &string_data) {
38+
std::vector<unsigned char> data;
39+
zpp::serializer::memory_output_archive archive(data);
40+
archive(record);
41+
string_data.assign(reinterpret_cast<const char *>(data.data()), data.size());
42+
}
43+
44+
inline void from_string(Record &record, const std::string &data) {
45+
zpp::serializer::memory_view_input_archive archive(data.data(), data.size());
46+
archive(record);
47+
}
48+
49+
} // namespace
50+
51+
#endif

0 commit comments

Comments
 (0)