Infinispan HotRod C++ Client 9.2.0.Final
Loading...
Searching...
No Matches
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
18using namespace org::infinispan::protostream;
19
20namespace infinispan {
21namespace hotrod {
22
26template <class T, unsigned int TypeId = 1000042> class ProtoStreamMarshaller : public infinispan::hotrod::Marshaller<T> {
27 void marshall(const T& obj, std::vector<char>& b) {
28#if GOOGLE_PROTOBUF_VERSION < 3004001
29 std::vector<char> msg(obj.ByteSize());
30 obj.SerializeToArray(msg.data(),obj.ByteSize());
31#else
32 std::vector<char> msg(obj.ByteSizeLong());
33 obj.SerializeToArray(msg.data(),obj.ByteSizeLong());
34#endif
35 WrappedMessage wm;
36 wm.set_wrappedmessagebytes(msg.data(), msg.size());
37 wm.set_wrappeddescriptorid(TypeId);
38#if GOOGLE_PROTOBUF_VERSION < 3004001
39 b.resize(wm.ByteSize());
40 wm.SerializeToArray(b.data(),wm.ByteSize());
41#else
42 b.resize(wm.ByteSizeLong());
43 wm.SerializeToArray(b.data(),wm.ByteSizeLong());
44#endif
45 }
46
47 T* unmarshall(const std::vector<char>& b) {
48 WrappedMessage wm;
49 wm.ParseFromArray(b.data(),b.size());
50 const std::string &wmb=wm.wrappedmessagebytes();
51 auto *bt = new T();
52 bt->ParseFromArray(wmb.data(),wmb.size());
53 return bt;
54 }
55
56};
57
58template <class T> class ProtoStreamMarshallerHelper {
59public:
60 static void noRelease(std::vector<char>*) { /* nothing allocated, nothing to release */ }
61
62 static void release(std::vector<char> *buf) {
63 delete buf->data();
64 }
65 static T unmarshall(char *b, size_t size) {
66 WrappedMessage wm;
67 wm.ParseFromArray(b, size);
68 const std::string &wmb=wm.wrappedmessagebytes();
69 T bt;
70 bt.ParseFromArray(wmb.data(),wmb.size());
71 return bt;
72 }};
73
74}} // namespace
75
76#endif /* ISPN_HOTROD_ProtoStreamMarshaller_H */
Definition: Marshaller.h:13
Definition: ProtoStreamMarshaller.h:26
Definition: AuthenticationConfiguration.h:10