-
Notifications
You must be signed in to change notification settings - Fork 112
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
118 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
|
||
#ifndef __ZPP_RECORD_HPP_INCLUDED__ | ||
#define __ZPP_RECORD_HPP_INCLUDED__ | ||
|
||
#include <vector> | ||
#include <string> | ||
|
||
#include <stdint.h> | ||
|
||
#include "zpp/serializer.h" | ||
|
||
namespace zpp_test { | ||
|
||
typedef std::vector<int64_t> Integers; | ||
typedef std::vector<std::string> Strings; | ||
|
||
struct Record { | ||
|
||
Integers ids; | ||
Strings strings; | ||
|
||
bool operator==(const Record &other) { | ||
return (ids == other.ids && strings == other.strings); | ||
} | ||
|
||
bool operator!=(const Record &other) { | ||
return !(*this == other); | ||
} | ||
|
||
template <typename Archive, typename Self> | ||
static void serialize(Archive & archive, Self & self) | ||
{ | ||
archive(self.ids, self.strings); | ||
} | ||
}; | ||
|
||
void to_string(const Record &record, std::string &string_data) { | ||
std::vector<unsigned char> data; | ||
zpp::serializer::memory_output_archive archive(data); | ||
archive(record); | ||
string_data.assign(reinterpret_cast<const char *>(data.data()), data.size()); | ||
} | ||
|
||
void from_string(Record &record, const std::string &data) { | ||
zpp::serializer::memory_view_input_archive archive(data.data(), data.size()); | ||
archive(record); | ||
} | ||
|
||
} // namespace | ||
|
||
#endif |