JBoss Data Grid HotRod C++ Client  7.0.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
BasicMarshaller.h
Go to the documentation of this file.
1 #ifndef ISPN_HOTROD_BASICMARSHALLER_H
2 #define ISPN_HOTROD_BASICMARSHALLER_H
3 
4 
5 #include <string>
6 #include <iostream>
8 
9 namespace infinispan {
10 namespace hotrod {
11 
12 /*
13  * A Marshaller for a few simple types.
14  */
15 
16 
17 template <class T> class BasicMarshaller : public infinispan::hotrod::Marshaller<T>
18 {};
19 
21 public:
22  static void noRelease(std::vector<char>*) { /* nothing allocated, nothing to release */ }
23  static void release(std::vector<char> *buf) {
24  delete buf->data();
25  }
26 };
27 
28 
29 // Specialization for std::string:
30 
31 template <>
32 class BasicMarshaller<std::string> : public infinispan::hotrod::Marshaller<std::string> {
33  public:
34  void marshall(const std::string& s, std::vector<char>& b) {
35  b.assign(s.data(), s.data()+s.size());
36  }
37  std::string* unmarshall(const std::vector<char>& b) {
38  std::string* s = new std::string(b.data(), b.size());
39  return s;
40  }
41 };
42 
43 template <>
45  public:
46  void marshall(const int& s, std::vector<char>& b) {
47  char *buf = new char[4];
48  for (int i = 0 ; i < 4 ; i++) {
49  buf[3-i] = (char) ((s) >> (8*i));
50  }
51  b.assign(buf, buf+4);
52  }
53  int* unmarshall(const std::vector<char>& b) {
54  int result = 0;
55  for (int i = 0; i < 4 ; i++) {
56  result <<= 8;
57  result ^= (int) *(b.data()+i) & 0xFF;
58  }
59  int* s = new int(result);
60  return s;
61  }
62 };
63 
64 }} // namespace
65 
66 #endif /* ISPN_HOTROD_BASICMARSHALLER_H */
int * unmarshall(const std::vector< char > &b)
Definition: BasicMarshaller.h:53
static void release(std::vector< char > *buf)
Definition: BasicMarshaller.h:23
std::string * unmarshall(const std::vector< char > &b)
Definition: BasicMarshaller.h:37
void marshall(const int &s, std::vector< char > &b)
Definition: BasicMarshaller.h:46
void marshall(const std::string &s, std::vector< char > &b)
Definition: BasicMarshaller.h:34
Definition: BasicMarshaller.h:17
Definition: BasicMarshaller.h:20
static void noRelease(std::vector< char > *)
Definition: BasicMarshaller.h:22
Definition: Marshaller.h:13