Skip to content
Permalink
Browse files

utils: memcpy_archive: Work around some odd types in boost.serialization

  • Loading branch information...
fweik committed Nov 4, 2019
1 parent 9aec365 commit 8ee16865a808a15e6e829baacf249eb6aa26d9c9
Showing with 18 additions and 9 deletions.
  1. +18 −9 src/utils/include/utils/serialization/memcpy_archive.hpp
@@ -76,21 +76,30 @@ template <class Derived> class BasicMemcpyArchive {
insert += bytes;
}

template <typename T>
auto operator>>(T &value) -> std::enable_if_t<use_memcpy<T>::value> {
private:
void read(void *data, size_t bytes) {
/* check that there is enough space left in the buffer */
assert((insert + sizeof(T)) <= buf.end());
assert((insert + bytes) <= buf.end());
std::memcpy(data, insert, bytes);
insert += bytes;
}

std::memcpy(&value, insert, sizeof(T));
insert += sizeof(T);
void write(const void *data, size_t bytes) {
/* check that there is enough space left in the buffer */
assert((insert + bytes) <= buf.end());
std::memcpy(insert, data, bytes);
insert += bytes;
}

public:
template <typename T>
auto operator>>(T &value) -> std::enable_if_t<use_memcpy<T>::value> {
read(&value, sizeof(T));
}

template <typename T>
auto operator<<(T const &value) -> std::enable_if_t<use_memcpy<T>::value> {
/* check that there is enough space left in the buffer */
assert((insert + sizeof(T)) <= buf.end());
std::memcpy(insert, &value, sizeof(T));
insert += sizeof(T);
write(&value, sizeof(T));
}

private:

0 comments on commit 8ee1686

Please sign in to comment.
You can’t perform that action at this time.