Derecho  0.9
Distributed systems toolkit for RDMA
SerializationSupport.cpp
Go to the documentation of this file.
2 #include <string.h>
3 using namespace std;
4 
5 namespace mutils {
6 
7 std::size_t to_bytes(const ByteRepresentable& b, char* v) {
8  return b.to_bytes(v);
9 }
10 
11 std::size_t bytes_size(const ByteRepresentable& b) {
12  return b.bytes_size();
13 }
14 
15 std::size_t to_bytes(const std::string& b, char* v) {
16  strcpy(v, b.c_str());
17  return b.length() + 1;
18 }
19 
20 std::size_t bytes_size(const std::string& b) {
21  return b.length() + 1;
22 }
23 
24 #ifdef MUTILS_DEBUG
25 void ensure_registered(ByteRepresentable& b, DeserializationManager& dm) {
26  b.ensure_registered(dm);
27 }
28 #endif
29 
33 }
34 
35 std::function<void(char const* const, std::size_t)> post_to_buffer(std::size_t& index, char* dest_buf) {
36  return [&index, dest_buf](char const* const read_buf, std::size_t size) {
37  memcpy(dest_buf + index, read_buf, size);
38  index += size;
39  };
40 }
41 
42 void post_object(const std::function<void(char const* const, std::size_t)>& f, const ByteRepresentable& br) {
43  br.post_object(f);
44 }
45 
46 void post_object(const std::function<void(char const* const, std::size_t)>& f, const std::string& str) {
47  f(str.c_str(), str.length() + 1);
48 }
49 
50 std::size_t to_bytes_v(char*) {
51  return 0;
52 }
53 
54 std::size_t from_bytes_v(DeserializationManager*, char const* const) {
55  return 0;
56 }
57 
58 std::size_t from_bytes_noalloc_v(DeserializationManager*, char const* const) {
59  return 0;
60 }
61 
62 } // namespace mutils
std::size_t from_bytes_noalloc_v(DeserializationManager *, char const *const)
std::enable_if_t< std::is_base_of< ByteRepresentable CMA std::decay_t< T > >::value, context_ptr< T > > from_bytes_noalloc(DeserializationManager *ctx, const char *v, context_ptr< std::decay_t< T >>=context_ptr< std::decay_t< T >>{})
Calls T::from_bytes_noalloc(ctx,v) when T is a ByteRepresentable.
std::size_t from_bytes_v(DeserializationManager *, char const *const)
STL namespace.
std::size_t to_bytes_v(char *)
For Serializing and Deserializing many objects at once.
std::function< void(char const *const, std::size_t)> post_to_buffer(std::size_t &index, char *dest_buf)
virtual void post_object(const std::function< void(char const *const, std::size_t)> &) const =0
Pass a pointer to a buffer containing this class&#39;s marshalled representation into the function f...
A non-POD type which wishes to mark itself byte representable should extend this class.
virtual std::size_t to_bytes(char *v) const =0
Write this class&#39;s marshalled representation into the array found at v.
auto bytes_size(const T &)
Just calls sizeof(T)
virtual std::size_t bytes_size() const =0
the size of the marshalled representation of this object.
std::unique_ptr< T, ContextDeleter< T > > context_ptr
Definition: context_ptr.hpp:20
The manager for any RemoteDeserializationContexts.
Definition: Bytes.hpp:5
The "marshalled" type is a wrapper for already-serialized types;.
std::enable_if_t< std::is_pod< BR >::value > post_object(const F &f, const BR &br, Args &&... args)
In-place serialization is also sometimes possible.
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.