Derecho  0.9
Distributed systems toolkit for RDMA
test_new_deserialization.cpp
Go to the documentation of this file.
2 
3 using namespace mutils;
4 
5 int main() {
6  std::vector<int> v{1,2,3,4};
7  auto size = bytes_size(v);
8  char c[size];
9  bzero(c,size);
10  to_bytes(v,c);
11  deserialize_and_run<std::vector<int> >(nullptr,c,[&](std::vector<int>& v2){
12  assert(v2 == v);
13  });
14 
15  deserialize_and_run<int >(nullptr,c,[&](int& v2){
16  assert(v2 == v.size());
17  });
18 
19  deserialize_and_run(nullptr,c,[&](int& size, int& v0, int& v1, int &v2, int &v3){
20  assert(size == v.size());
21  assert(v0 == v.at(0));
22  assert(v1 == v.at(1));
23  assert(v2 == v.at(2));
24  assert(v3 == v.at(3));
25  });
26 }
auto bytes_size(const T &)
Just calls sizeof(T)
Definition: Bytes.hpp:5
auto deserialize_and_run(DeserializationManager *dsm, char *v, const F &fun)
Calls mutils::from_bytes_noalloc<T>(ctx,v), dereferences the result, and passes it to fun...
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.