Derecho  0.9
Distributed systems toolkit for RDMA
serialization-demo.cpp
Go to the documentation of this file.
3 #include <cstdlib>
4 
5 using namespace mutils;
6 using namespace std;
7 
9  const int a;
10  const long b;
11 
12  TestSerialization(int a, long b):a(a),b(b){}
13 
15 };
16 
17 int main(){
18  DeserializationManager dsm{{}};
19  {
20  int i = 3;
21  auto size = bytes_size(i);
22  TestSerialization ts{1,1};
23  char *c = (char*) malloc(ts.bytes_size());
24  to_bytes(ts,c);
25  auto ts2 = from_bytes<TestSerialization>(&dsm,c);
26  free(c);
27  assert(ts.a == ts2->a);
28  assert(ts.b == ts2->b);
29  }
30 
31  {
32  int foo;
33  char* c = (char*) malloc(bytes_size(foo));
34  to_bytes(foo,c);
35  auto foo2 = from_bytes<int>(&dsm,c);
36  free(c);
37  assert(foo == *foo2);
38  }
39 
40 }
int main()
STL namespace.
#define DEFAULT_SERIALIZATION_SUPPORT(CLASS_NAME, CLASS_MEMBERS...)
THIS (below) is the only user-facing macro in this file.
A non-POD type which wishes to mark itself byte representable should extend this class.
auto bytes_size(const T &)
Just calls sizeof(T)
The manager for any RemoteDeserializationContexts.
TestSerialization(int a, long b)
Definition: Bytes.hpp:5
std::size_t to_bytes(const ByteRepresentable &b, char *v)
calls b.to_bytes(v) when b is a ByteRepresentable; calls std::memcpy() when b is POD.