X-Git-Url: http://xvm.mit.edu/gitweb/invirt/third/libt4.git/blobdiff_plain/5a5c578e2e358a121cdb9234a6cb11c4ecfbf323..46fb2b4bbe3a0a8516ab04cfafa895a882c70f86:/rpc/marshall.h?ds=inline diff --git a/rpc/marshall.h b/rpc/marshall.h index 20b9c07..98856e4 100644 --- a/rpc/marshall.h +++ b/rpc/marshall.h @@ -52,6 +52,8 @@ typedef int rpc_sz_t; #define DEFAULT_RPC_SZ 1024 #define RPC_HEADER_SZ (max(sizeof(request_header), sizeof(reply_header)) + sizeof(rpc_sz_t)) +struct pass { template inline pass(Args&&...) {} }; + class marshall { private: char *buf_; // Base of the raw bytes buffer (dynamically readjusted) @@ -67,10 +69,7 @@ class marshall { } } public: - struct pass { template inline pass(Args&&...) {} }; - template - marshall(const Args&... args) { buf_ = (char *) malloc(sizeof(char)*DEFAULT_RPC_SZ); VERIFY(buf_); @@ -407,4 +406,33 @@ template struct marshalled_func> : public marshalled_func_imp {}; +template unmarshall & +tuple_unmarshall_imp(unmarshall & u, tuple t, tuple_indices) { + (void)pass{(u >> get(t))...}; + return u; +} + +template unmarshall & +operator>>(unmarshall & u, tuple && t) { + using Indices = typename make_tuple_indices::type; + return tuple_unmarshall_imp(u, t, Indices()); +} + +template marshall & +tuple_marshall_imp(marshall & m, tuple & t, tuple_indices) { + (void)pass{(m << get(t))...}; + return m; +} + +template marshall & +operator<<(marshall & m, tuple && t) { + using Indices = typename make_tuple_indices::type; + return tuple_marshall_imp(m, t, Indices()); +} + +// for structs or classes containing a MEMBERS declaration +#define MARSHALLABLE(_c_) \ +inline unmarshall & operator>>(unmarshall &u, _c_ &a) { return u >> a._tuple_(); } \ +inline marshall & operator<<(marshall &m, _c_ a) { return m << a._tuple_(); } + #endif