JBoss Data Grid HotRod C++ Client  6.6.1
 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(ScopedBuffer*) { /* nothing allocated, nothing to release */ }
23  static void release(ScopedBuffer *buf) {
24  delete buf->getBytes();
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, ScopedBuffer& b) {
35  b.set(const_cast<char *> (s.data()), s.size(), &BasicMarshallerHelper::noRelease);
36  }
37  std::string* unmarshall(const ScopedBuffer& b) {
38  std::string* s = new std::string(b.getBytes(), b.getLength());
39  return s;
40  }
41 };
42 
43 template <>
45  public:
46  void marshall(const int& s, ScopedBuffer& b) {
47  char *buf = new char[4];
48  for (int i = 0 ; i < 4 ; i++) {
49  buf[3-i] = (char) ((s) >> (8*i));
50  }
52  }
53  int* unmarshall(const ScopedBuffer& b) {
54  int result = 0;
55  for (int i = 0; i < 4 ; i++) {
56  result <<= 4;
57  result ^= (int) *(b.getBytes()+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 ScopedBuffer &b)
Definition: BasicMarshaller.h:53
size_t getLength() const
Definition: ScopedBuffer.h:36
std::string * unmarshall(const ScopedBuffer &b)
Definition: BasicMarshaller.h:37
static void noRelease(ScopedBuffer *)
Definition: BasicMarshaller.h:22
static void release(ScopedBuffer *buf)
Definition: BasicMarshaller.h:23
char * getBytes() const
Definition: ScopedBuffer.h:35
Definition: ScopedBuffer.h:20
Definition: BasicMarshaller.h:17
Definition: BasicMarshaller.h:20
void set(char *b, size_t l, ReleaseFunc m=0)
Definition: ScopedBuffer.h:31
Definition: Marshaller.h:14
void marshall(const int &s, ScopedBuffer &b)
Definition: BasicMarshaller.h:46
void marshall(const std::string &s, ScopedBuffer &b)
Definition: BasicMarshaller.h:34