1 #ifndef ISPN_HOTROD_JBASICMARSHALLER_H
2 #define ISPN_HOTROD_JBASICMARSHALLER_H
10 namespace infinispan {
25 static void release(std::vector<char> *buf) {
28 template <
class T>
static T
unmarshall(
char *);
33 throw Exception(
"JBasicMarshallerHelper: bad version");
35 throw Exception(
"JBasicMarshallerHelper: not a string");
36 return std::string(b+3,b[2]);
41 throw Exception(
"JBasicMarshallerHelper: bad version");
43 throw Exception(
"JBasicMarshallerHelper: not a integer");
45 for (
int i = 0; i < 4 ; i++) {
47 result ^= (int) *(b+i+2) & 0xFF;
59 void marshall(
const std::string& s, std::vector<char>& b) {
60 if (s.size() <= 0x100) {
68 std::string* s =
new std::string(b.data()+3, b.size()-3);
76 res = addPreambleSmall(s);
80 res = addPreambleMedium(s);
86 static std::string addPreambleSmall(std::string& s) {
87 std::string res(
"\x03\x3e");
88 res.append(1, (
char)s.size());
92 static std::string addPreambleMedium(std::string& s) {
93 std::string res(
"\x03\x3f");
94 res.append(1, (
char)(s.size()>>8));
95 res.append(1, (
char)(s.size()&& 0xff));
100 void marshallSmall(
const std::string& s, std::vector<char>& b) {
101 b.resize(s.size() + 3);
102 char* buf = b.data();
106 buf[2] = (char)s.size();
107 memcpy(buf + 3, s.data(), s.size());
110 void marshallMedium(
const std::string& s, std::vector<char>& b) {
111 b.resize(s.size() + 4);
112 char* buf = b.data();
116 buf[2] = (char)(s.size() >> 8);
117 buf[3] = s.size() & 0xff;
119 memcpy(buf + 4, s.data(), s.size());
126 void marshall(
const int& s, std::vector<char>& b) {
131 for (
int i = 0 ; i < 4 ; i++) {
132 buf[5-i] = (char) ((s) >> (8*i));
134 b.assign(buf, buf+6);
138 for (
int i = 0; i < 4 ; i++) {
140 result ^= (int) *(b.data()+i+2) & 0xFF;
142 int* s =
new int(result);
void marshall(const std::string &s, std::vector< char > &b)
Definition: JBasicMarshaller.h:59
Definition: JBasicMarshaller.h:17
void marshall(const int &s, std::vector< char > &b)
Definition: JBasicMarshaller.h:126
Definition: JBasicMarshaller.h:23
static void noRelease(std::vector< char > *)
Definition: JBasicMarshaller.h:24
Definition: JBasicMarshaller.h:23
static std::string addPreamble(std::string &s)
Definition: JBasicMarshaller.h:72
Definition: JBasicMarshaller.h:20
Definition: JBasicMarshaller.h:23
Definition: JBasicMarshaller.h:23
static void release(std::vector< char > *buf)
Definition: JBasicMarshaller.h:25
std::string * unmarshall(const std::vector< char > &b)
Definition: JBasicMarshaller.h:67
Definition: exceptions.h:13
static T unmarshall(char *)
int * unmarshall(const std::vector< char > &b)
Definition: JBasicMarshaller.h:136
Definition: Marshaller.h:9