View on GitHub

Vistle

Distributed Data-parallel Scientific Visualization in VR

messagepayloadtemplates.h
Go to the documentation of this file.
1#ifndef VISTLE_MESSAGE_PAYLOAD_TEMPLATES_H
2#define VISTLE_MESSAGE_PAYLOAD_TEMPLATES_H
3#include "archives.h"
4namespace vistle {
5namespace message {
6
7
8template<class Payload>
9buffer addPayload(Message &message, const Payload &payload)
10{
12 oarchive ar(buf);
13 ar &const_cast<Payload &>(payload);
14 auto vec = buf.get_vector();
15 message.setPayloadSize(vec.size());
16 return vec;
17}
18
19template<class Payload>
20void getFromPayload(const buffer &data, Payload &payload)
21{
22 vecistreambuf<buffer> buf(data);
23 try {
24 iarchive ar(buf);
25 ar &payload;
26#ifdef USE_YAS
27 } catch (::yas::io_exception &ex) {
28 std::cerr << "ERROR: failed to get message payload from " << data.size() << " bytes: " << ex.what()
29 << std::endl;
30 std::cerr << vistle::backtrace() << std::endl;
31#endif
32 } catch (...) {
33 throw;
34 }
35}
36
37template<class Payload>
38Payload getPayload(const buffer &data)
39{
40 Payload payload;
41 getFromPayload(data, payload);
42 return payload;
43}
44
45} // namespace message
46
47} // namespace vistle
48
49
50#endif // VISTLE_MESSAGE_PAYLOAD_TEMPLATES_H
Definition: message.h:157
void setPayloadSize(size_t size)
set payload size
Definition: message.cpp:261
Definition: vecstreambuf.h:52
Definition: vecstreambuf.h:12
const Vector & get_vector() const
Definition: vecstreambuf.h:42
Definition: archives.h:342
Definition: archives.h:197
buffer addPayload(Message &message, const Payload &payload)
Definition: messagepayloadtemplates.h:9
Payload getPayload(const buffer &data)
Definition: messagepayloadtemplates.h:38
void getFromPayload(const buffer &data, Payload &payload)
Definition: messagepayloadtemplates.h:20
Definition: allobjects.cpp:30
std::vector< char, allocator< char > > buffer
Definition: buffer.h:9
std::string backtrace()
Definition: tools.cpp:20