File: serial.h

package info (click to toggle)
gemmi 0.7.4%2Bds-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 6,644 kB
  • sloc: cpp: 64,445; python: 5,425; ansic: 4,545; sh: 374; makefile: 112; javascript: 86; f90: 42
file content (22 lines) | stat: -rw-r--r-- 668 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
// Copyright 2024 Global Phasing Ltd.

#pragma once
#include "common.h"
#include "gemmi/serialize.hpp"
#include "../third_party/serializer.h"

template<typename T>
nb::bytes getstate(const T& self) {
  std::vector<unsigned char> data;
  zpp::serializer::memory_output_archive out(data);
  // awkward zpp design: calling zpp::serializer::*_archive::operator()()
  out(self);
  return nb::bytes(data.data(), data.size());
}

template<typename T>
void setstate(T& self, const nb::bytes& state) {
  new(&self) T();  // probably not needed
  const unsigned char* ptr = (unsigned char*) state.data();
  zpp::serializer::memory_view_input_archive(ptr, state.size())(self);
}