17 #ifndef AMEFDECODER_H_
18 #define AMEFDECODER_H_
20 #include "AMEFObject.h"
29 static char* longTocharArray(
long l,
int ind)
31 char* result =
new char[ind];
32 for (
int i = 0; i<ind; i++)
34 int offset = (ind - 1 - i) * 8;
35 result[i] = (char) ((l >> offset) & 0xFF);
40 static string longTocharArrayS(
long l,
int ind)
42 char* result =
new char[ind];
43 for (
int i = 0; i<ind; i++)
45 int offset = (ind - 1 - i) * 8;
46 result[i] = (char) ((l >> offset) & 0xFF);
52 static char* intTocharArray(
int l,
int ind)
54 char* result =
new char[ind];
55 for (
int i = 0; i<ind; i++)
57 int offset = (ind - 1 - i) * 8;
58 result[i] = (char) ((l >> offset) & 0xFF);
63 static char* intTocharArrayWI(
int l)
74 char* result =
new char[ind];
75 for (
int i = 0; i<ind; i++)
77 int offset = (ind - 1 - i) * 8;
78 result[i] = (char) ((l >> offset) & 0xFF);
83 static int charArrayToInt(
char l[])
87 for (
int i = 0; i < ind; i++)
89 int offset = (ind -1 - i) * 8;
90 t += (l[i] & 0x000000FF) << offset;
95 static int charArrayToInt(
string l,
int off,
int ind)
98 for (
int i = 0; i < ind; i++)
100 int offset = (ind -1 - i) * 8;
101 t += (l[off+i] & 0x000000FF) << offset;
106 static long charArrayToLong(
char l[])
110 for (
int i = 0; i < ind; i++)
112 int offset = (ind -1 - i) * 8;
113 t += (l[i] & 0x000000FF) << offset;
117 static long charArrayToLong(
char* l,
int off,
int ind)
120 for (
int i = 0; i < ind; i++)
122 int offset = (ind -1 - i) * 8;
123 t += (l[off+i] & 0x000000FF) << offset;
127 static long charArrayToLong(
char* l,
int ind)
130 for (
int i = 0; i < ind; i++)
132 int offset = (ind -1 - i) * 8;
133 t += (l[i] & 0x000000FF) << offset;
138 static string intTocharArrayS(
int l,
int ind)
140 char* result =
new char[ind];
141 for (
int i = 0; i<ind; i++)
143 int offset = (ind - 1 - i) * 8;
144 result[i] = (char) ((l >> offset) & 0xFF);
150 AMEFObject* decodeB(
string buffer,
bool considerLength,
bool ignoreName)
156 strdata = buffer.substr(4);
933 AMEFObject* decodeSinglePacketB(
string buffer,
bool ignoreName)
938 if(type==AMEFObject::NULL_STRING || type==AMEFObject::NULL_DATE || type==AMEFObject::NULL_NUMBER
939 || type==AMEFObject::NULL_BOOL || type==AMEFObject::NULL_CHAR)
942 jDBObject->setType(type);
951 jDBObject->setName(buffer.substr(st,en-st));}
956 else if(type==AMEFObject::STRING_TYPE)
959 jDBObject->setType(type);
968 jDBObject->setName(buffer.substr(st,en-st));}
972 int lengthm = charArrayToInt(buffer,
position,4);
973 jDBObject->setLength(lengthm);
975 string value = buffer.substr(
position,lengthm);
976 jDBObject->setValue(value);
979 else if(type==AMEFObject::STRING_65536_TYPE)
982 jDBObject->setType(type);
991 jDBObject->setName(buffer.substr(st,en-st));}
995 int lengthm = charArrayToInt(buffer,
position,2);
996 jDBObject->setLength(lengthm);
998 string value = buffer.substr(
position,lengthm);
999 jDBObject->setValue(value);
1002 else if(type==AMEFObject::STRING_16777216_TYPE)
1005 jDBObject->setType(type);
1014 jDBObject->setName(buffer.substr(st,en-st));}
1018 int lengthm = charArrayToInt(buffer,
position,3);
1019 jDBObject->setLength(lengthm);
1021 string value = buffer.substr(
position,lengthm);
1022 jDBObject->setValue(value);
1025 else if(type==AMEFObject::DATE_TYPE || type==AMEFObject::STRING_256_TYPE || type==AMEFObject::DOUBLE_FLOAT_TYPE)
1028 jDBObject->setType(type);
1037 jDBObject->setName(buffer.substr(st,en-st));}
1041 int lengthm = charArrayToInt(buffer,
position,1);
1042 jDBObject->setLength(lengthm);
1044 string value = buffer.substr(
position,lengthm);
1045 jDBObject->setValue(value);
1048 else if(type==AMEFObject::VERY_SMALL_INT_TYPE)
1051 jDBObject->setType(type);
1060 jDBObject->setName(buffer.substr(st,en-st));}
1064 jDBObject->setLength(1);
1065 jDBObject->pushChar(buffer[
position]);
1068 else if(type==AMEFObject::SMALL_INT_TYPE)
1071 jDBObject->setType(type);
1080 jDBObject->setName(buffer.substr(st,en-st));}
1084 jDBObject->setLength(2);
1085 jDBObject->pushChar(buffer[
position]);
1086 jDBObject->pushChar(buffer[position+1]);
1089 else if(type==AMEFObject::BIG_INT_TYPE)
1092 jDBObject->setType(type);
1101 jDBObject->setName(buffer.substr(st,en-st));}
1105 jDBObject->setLength(3);
1106 jDBObject->pushChar(buffer[
position]);
1107 jDBObject->pushChar(buffer[position+1]);
1108 jDBObject->pushChar(buffer[position+2]);
1111 else if(type==AMEFObject::INT_TYPE)
1114 jDBObject->setType(type);
1123 jDBObject->setName(buffer.substr(st,en-st));}
1127 jDBObject->setLength(4);
1128 jDBObject->pushChar(buffer[
position]);
1129 jDBObject->pushChar(buffer[position+1]);
1130 jDBObject->pushChar(buffer[position+2]);
1131 jDBObject->pushChar(buffer[position+3]);
1134 else if(type==AMEFObject::VS_LONG_INT_TYPE)
1137 jDBObject->setType(type);
1146 jDBObject->setName(buffer.substr(st,en-st));}
1150 jDBObject->setLength(5);
1151 jDBObject->pushChar(buffer[
position]);
1152 jDBObject->pushChar(buffer[position+1]);
1153 jDBObject->pushChar(buffer[position+2]);
1154 jDBObject->pushChar(buffer[position+3]);
1155 jDBObject->pushChar(buffer[position+4]);
1158 else if(type==AMEFObject::S_LONG_INT_TYPE)
1161 jDBObject->setType(type);
1170 jDBObject->setName(buffer.substr(st,en-st));}
1174 jDBObject->setLength(6);
1175 jDBObject->pushChar(buffer[
position]);
1176 jDBObject->pushChar(buffer[position+1]);
1177 jDBObject->pushChar(buffer[position+2]);
1178 jDBObject->pushChar(buffer[position+3]);
1179 jDBObject->pushChar(buffer[position+4]);
1180 jDBObject->pushChar(buffer[position+5]);
1183 else if(type==AMEFObject::B_LONG_INT_TYPE)
1186 jDBObject->setType(type);
1195 jDBObject->setName(buffer.substr(st,en-st));}
1199 jDBObject->setLength(7);
1200 jDBObject->pushChar(buffer[
position]);
1201 jDBObject->pushChar(buffer[position+1]);
1202 jDBObject->pushChar(buffer[position+2]);
1203 jDBObject->pushChar(buffer[position+3]);
1204 jDBObject->pushChar(buffer[position+4]);
1205 jDBObject->pushChar(buffer[position+5]);
1206 jDBObject->pushChar(buffer[position+6]);
1209 else if(type==AMEFObject::LONG_INT_TYPE)
1212 jDBObject->setType(type);
1221 jDBObject->setName(buffer.substr(st,en-st));}
1225 jDBObject->setLength(8);
1226 jDBObject->pushChar(buffer[
position]);
1227 jDBObject->pushChar(buffer[position+1]);
1228 jDBObject->pushChar(buffer[position+2]);
1229 jDBObject->pushChar(buffer[position+3]);
1230 jDBObject->pushChar(buffer[position+4]);
1231 jDBObject->pushChar(buffer[position+5]);
1232 jDBObject->pushChar(buffer[position+6]);
1233 jDBObject->pushChar(buffer[position+7]);
1236 else if(type==AMEFObject::BOOLEAN_TYPE || type==AMEFObject::CHAR_TYPE)
1239 jDBObject->setType(type);
1248 jDBObject->setName(buffer.substr(st,en-st));}
1252 jDBObject->setLength(1);
1253 jDBObject->pushChar(buffer[
position]);
1256 else if(type==AMEFObject::VS_OBJECT_TYPE)
1259 jDBObject->setType(type);
1268 jDBObject->setName(buffer.substr(st,en-st));}
1272 int lengthm = charArrayToInt(buffer,
position,1);
1273 jDBObject->setLength(lengthm);
1275 while(
position<(
int)buffer.length())
1277 AMEFObject *obj = decodeSinglePacketB(buffer,ignoreName);
1281 else if(type==AMEFObject::S_OBJECT_TYPE)
1284 jDBObject->setType(type);
1293 jDBObject->setName(buffer.substr(st,en-st));}
1297 int lengthm = charArrayToInt(buffer,
position,2);
1298 jDBObject->setLength(lengthm);
1302 while(
position<(
int)buffer.length())
1304 AMEFObject* obj = decodeSinglePacketB(buffer,ignoreName);
1308 else if(type==AMEFObject::B_OBJECT_TYPE)
1311 jDBObject->setType(type);
1320 jDBObject->setName(buffer.substr(st,en-st));}
1324 int lengthm = charArrayToInt(buffer,
position,3);
1325 jDBObject->setLength(lengthm);
1327 while(
position<(
int)buffer.length())
1329 AMEFObject* obj = decodeSinglePacketB(buffer,ignoreName);
1333 else if(type==AMEFObject::OBJECT_TYPE)
1336 jDBObject->setType(type);
1345 jDBObject->setName(buffer.substr(st,en-st));}
1349 int lengthm = charArrayToInt(buffer,
position,4);
1350 jDBObject->setLength(lengthm);
1352 while(
position<(
int)buffer.length())
1354 AMEFObject* obj = decodeSinglePacketB(buffer,ignoreName);