Infinispan HotRod C++ Client 9.2.0.Final
Loading...
Searching...
No Matches
JBossMarshaller.h
Go to the documentation of this file.
1/*
2 * JBossMarshaller.h
3 *
4 * Created on: Dec 4, 2017
5 * Author: rigazilla
6 */
7
8#ifndef INCLUDE_INFINISPAN_HOTROD_JBOSSMARSHALLER_H_
9#define INCLUDE_INFINISPAN_HOTROD_JBOSSMARSHALLER_H_
10
12
13namespace infinispan {
14namespace hotrod {
15
17public:
18 template<typename R> static R unmarshall(const std::vector<char>& b);
19 template<typename A> static std::vector<char> marshall(A a);
20 virtual ~JBossMarshaller() = 0;
21
22 static void marshallSmall(const std::string& s, std::vector<char>& b) {
23 b.resize(s.size() + 3);
24 char* buf = b.data();
25 // JBoss preamble
26 buf[0] = JBasicMarshallerHelper::MARSHALL_VERSION;
27 buf[1] = JBasicMarshallerHelper::SMALL_STRING;
28 buf[2] = (char) s.size();
29 memcpy(buf + 3, s.data(), s.size());
30 }
31 static void marshallMedium(const std::string& s, std::vector<char>& b) {
32 b.resize(s.size() + 4);
33 char* buf = b.data();
34 // JBoss preamble
35 buf[0] = JBasicMarshallerHelper::MARSHALL_VERSION;
36 buf[1] = JBasicMarshallerHelper::MEDIUM_STRING;
37 buf[2] = (char) (s.size() >> 8);
38 buf[3] = s.size() & 0xff;
39
40 memcpy(buf + 4, s.data(), s.size());
41 }
42
43};
44
45template<> inline int* JBossMarshaller::unmarshall(const std::vector<char>& b) {
46 if (b.begin()==b.end())
47 return nullptr;
48 int result = 0;
49 for (int i = 0; i < 4; i++) {
50 result <<= 8;
51 result ^= (int) *(b.data() + i + 2) & 0xFF;
52 }
53 int* s = new int(result);
54 return s;
55}
56
57template<> inline std::string* JBossMarshaller::unmarshall(const std::vector<char>& b) {
58 // TODO: this works only for SMALL_STRING
59 if (b.begin()==b.end())
60 return nullptr;
61 std::string* s = new std::string(b.begin() + 3, b.end());
62 return s;
63}
64
65template<> inline std::vector<char> JBossMarshaller::marshall(std::string s) {
66 std::vector<char> b;
67 if (s.size() <= 0x100) {
69 } else {
71 }
72 return b;
73}
74
75template<> inline std::vector<char> JBossMarshaller::marshall(int a) {
76 char buf[6];
77 std::vector<char> res;
78 // JBoss preamble
79 buf[0] = JBasicMarshallerHelper::MARSHALL_VERSION;
80 buf[1] = JBasicMarshallerHelper::INTEGER;
81 for (int i = 0; i < 4; i++) {
82 buf[5 - i] = (char) ((a) >> (8 * i));
83 }
84 res.assign(buf, buf + 6);
85 return res;
86}
87
88}
89}
90
91#endif /* INCLUDE_INFINISPAN_HOTROD_JBOSSMARSHALLER_H_ */
Definition: JBossMarshaller.h:16
static std::vector< char > marshall(A a)
static R unmarshall(const std::vector< char > &b)
static void marshallSmall(const std::string &s, std::vector< char > &b)
Definition: JBossMarshaller.h:22
static void marshallMedium(const std::string &s, std::vector< char > &b)
Definition: JBossMarshaller.h:31
Definition: AuthenticationConfiguration.h:10