JBoss Data Grid HotRod C++ Client  7.0.0
 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 #include "message-wrapping.pb.h"
10 
11 using namespace org::infinispan::protostream;
12 
13 namespace infinispan {
14 namespace hotrod {
15 
16 /*
17  * A Marshaller for a few simple types that pretends to be compatible with JBoss Marshaller.
18  * See below the Helper class for a list of the managed types.
19  */
20 template <class T> class ProtoStreamMarshaller : public infinispan::hotrod::Marshaller<T> {
21  void marshall(const T& obj, std::vector<char>& b) {
22  std::vector<char> msg(obj.ByteSize());
23  obj.SerializeToArray(msg.data(),obj.ByteSize());
24  WrappedMessage wm;
25  wm.set_wrappedmessagebytes(msg.data(), msg.size());
26  wm.set_wrappeddescriptorid(42);
27  b.resize(wm.ByteSize());
28  wm.SerializeToArray(b.data(),wm.ByteSize());
29  }
30 
31  T* unmarshall(const std::vector<char>& b) {
32  auto *bt = new T();
33  bt->ParseFromArray(b.data(),b.size());
34  return bt;
35  }
36 
37 };
38 
39 template <class T> class ProtoStreamMarshallerHelper {
40 public:
41  static void noRelease(std::vector<char>*) { /* nothing allocated, nothing to release */ }
42 
43  static void release(std::vector<char> *buf) {
44  delete buf->data();
45  }
46  static T unmarshall(char *b, size_t size) {
47  T bt;
48  bt.ParseFromArray(b,size);
49  return bt;
50  }};
51 
52 }} // namespace
53 
54 #endif /* ISPN_HOTROD_ProtoStreamMarshaller_H */
static void noRelease(std::vector< char > *)
Definition: ProtoStreamMarshaller.h:41
Definition: ProtoStreamMarshaller.h:20
static T unmarshall(char *b, size_t size)
Definition: ProtoStreamMarshaller.h:46
Definition: ProtoStreamMarshaller.h:39
Definition: Marshaller.h:13
static void release(std::vector< char > *buf)
Definition: ProtoStreamMarshaller.h:43