InfinispanHotRodC++Client  8.2.0.Alpha1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
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 "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 
23 /*
24  * A Marshaller for a few simple types that pretends to be compatible with JBoss Marshaller.
25  * See below the Helper class for a list of the managed types.
26  */
27 template <class T, unsigned int TypeId = 42> class ProtoStreamMarshaller : public infinispan::hotrod::Marshaller<T> {
28  void marshall(const T& obj, std::vector<char>& b) {
29  std::vector<char> msg(obj.ByteSize());
30  obj.SerializeToArray(msg.data(),obj.ByteSize());
31  WrappedMessage wm;
32  wm.set_wrappedmessagebytes(msg.data(), msg.size());
33  wm.set_wrappeddescriptorid(TypeId);
34  b.resize(wm.ByteSize());
35  wm.SerializeToArray(b.data(),wm.ByteSize());
36  }
37 
38  T* unmarshall(const std::vector<char>& b) {
39  WrappedMessage wm;
40  wm.ParseFromArray(b.data(),b.size());
41  const std::string &wmb=wm.wrappedmessagebytes();
42  auto *bt = new T();
43  bt->ParseFromArray(wmb.data(),wmb.size());
44  return bt;
45  }
46 
47 };
48 
49 template <class T> class ProtoStreamMarshallerHelper {
50 public:
51  static void noRelease(std::vector<char>*) { /* nothing allocated, nothing to release */ }
52 
53  static void release(std::vector<char> *buf) {
54  delete buf->data();
55  }
56  static T unmarshall(char *b, size_t size) {
57  WrappedMessage wm;
58  wm.ParseFromArray(b, size);
59  const std::string &wmb=wm.wrappedmessagebytes();
60  T bt;
61  bt.ParseFromArray(wmb.data(),wmb.size());
62  return bt;
63  }};
64 
65 }} // namespace
66 
67 #endif /* ISPN_HOTROD_ProtoStreamMarshaller_H */
static void noRelease(std::vector< char > *)
Definition: ProtoStreamMarshaller.h:51
Definition: ProtoStreamMarshaller.h:27
static T unmarshall(char *b, size_t size)
Definition: ProtoStreamMarshaller.h:56
Definition: ProtoStreamMarshaller.h:49
Definition: Marshaller.h:9
static void release(std::vector< char > *buf)
Definition: ProtoStreamMarshaller.h:53