Red Hat Data Grid HotRod C++ Client  7.2.0
ProtoStreamMarshaller.h
Go to the documentation of this file.
1 #ifndef ISPN_HOTROD_PROTOSTREAMMARSHALLER_H
2 #define ISPN_HOTROD_PROTOSTREAMMARSHALLER_H
3 
4 
5 #include <string>
6 #include <iostream>
9 #if _MSC_VER
10 #pragma warning(push)
11 #pragma warning(disable:4267 4244)
12 #endif
13 #include "infinispan/hotrod/message-wrapping.pb.h"
14 #if _MSC_VER
15 #pragma warning(pop)
16 #endif
17 
18 using namespace org::infinispan::protostream;
19 
20 namespace infinispan {
21 namespace hotrod {
22 
26 template <class T, unsigned int TypeId = 42> class ProtoStreamMarshaller : public infinispan::hotrod::Marshaller<T> {
27  void marshall(const T& obj, std::vector<char>& b) {
28  std::vector<char> msg(obj.ByteSize());
29  obj.SerializeToArray(msg.data(),obj.ByteSize());
30  WrappedMessage wm;
31  wm.set_wrappedmessagebytes(msg.data(), msg.size());
32  wm.set_wrappeddescriptorid(TypeId);
33  b.resize(wm.ByteSize());
34  wm.SerializeToArray(b.data(),wm.ByteSize());
35  }
36 
37  T* unmarshall(const std::vector<char>& b) {
38  WrappedMessage wm;
39  wm.ParseFromArray(b.data(),b.size());
40  const std::string &wmb=wm.wrappedmessagebytes();
41  auto *bt = new T();
42  bt->ParseFromArray(wmb.data(),wmb.size());
43  return bt;
44  }
45 
46 };
47 
48 template <class T> class ProtoStreamMarshallerHelper {
49 public:
50  static void noRelease(std::vector<char>*) { /* nothing allocated, nothing to release */ }
51 
52  static void release(std::vector<char> *buf) {
53  delete buf->data();
54  }
55  static T unmarshall(char *b, size_t size) {
56  WrappedMessage wm;
57  wm.ParseFromArray(b, size);
58  const std::string &wmb=wm.wrappedmessagebytes();
59  T bt;
60  bt.ParseFromArray(wmb.data(),wmb.size());
61  return bt;
62  }};
63 
64 }} // namespace
65 
66 #endif /* ISPN_HOTROD_ProtoStreamMarshaller_H */
Definition: ProtoStreamMarshaller.h:26
Definition: AuthenticationConfiguration.h:10
Definition: Marshaller.h:12