24 #include "Constants.h"
45 vector<AMEFObject*> packets;
47 static string longTocharArray(
long l,
int ind)
50 for (
int i = 0; i<ind; i++)
52 int offset = (ind - 1 - i) * 8;
53 result.push_back((
char) ((l >> offset) & 0xFF));
58 static string intTocharArray(
int l,
int ind)
61 for (
int i = 0; i<ind; i++)
63 int offset = (ind - 1 - i) * 8;
64 result.push_back((
char) ((l >> offset) & 0xFF));
69 static char* intTocharArrayWI(
int l)
80 char* result =
new char[ind];
81 for (
int i = 0; i<ind; i++)
83 int offset = (ind - 1 - i) * 8;
84 result[i] = (char) ((l >> offset) & 0xFF);
89 static int charArrayToInt(
string l)
93 for (
int i = 0; i < ind; i++)
95 int offset = (ind -1 - i) * 8;
96 t += (l[i] & 0x000000FF) << offset;
101 static int charArrayToInt(
string l,
int off,
int ind)
104 for (
int i = 0; i < ind; i++)
106 int offset = (ind -1 - i) * 8;
107 t += (l[off+i] & 0x000000FF) << offset;
112 static long charArrayToLong(
string l)
115 int ind = l.length();
116 for (
int i = 0; i < ind; i++)
118 int offset = (ind -1 - i) * 8;
119 t += (l[i] & 0x000000FF) << offset;
123 static long charArrayToLong(
string l,
int off,
int ind)
126 for (
int i = 0; i < ind; i++)
128 int offset = (ind -1 - i) * 8;
129 t += (l[off+i] & 0x000000FF) << offset;
133 static long charArrayToLong(
string l,
int ind)
136 for (
int i = 0; i < ind; i++)
138 int offset = (ind -1 - i) * 8;
139 t += (l[i] & 0x000000FF) << offset;
144 static string intTocharArrayS(
int l,
int ind)
146 char* result =
new char[ind];
147 for (
int i = 0; i<ind; i++)
149 int offset = (ind - 1 - i) * 8;
150 result[i] = (char) ((l >> offset) & 0xFF);
157 static const char NULL_STRING =
'a';
159 static const char NULL_NUMBER =
'g';
161 static const char NULL_DATE =
'j';
163 static const char NULL_FPN =
'k';
165 static const char NULL_BOOL =
'v';
167 static const char NULL_CHAR =
'z';
170 static const char DATE_TYPE =
'd';
173 static const char STRING_TYPE =
's';
176 static const char STRING_256_TYPE =
't';
179 static const char STRING_65536_TYPE =
'h';
181 static const char STRING_16777216_TYPE =
'y';
184 static const char BOOLEAN_TYPE =
'b';
187 static const char CHAR_TYPE =
'c';
190 static const char VERY_SMALL_INT_TYPE =
'n';
192 static const char SMALL_INT_TYPE =
'w';
194 static const char BIG_INT_TYPE =
'r';
196 static const char INT_TYPE =
'i';
198 static const char VS_LONG_INT_TYPE =
'f';
200 static const char S_LONG_INT_TYPE =
'x';
202 static const char B_LONG_INT_TYPE =
'e';
204 static const char LONG_INT_TYPE =
'l';
206 static const char DOUBLE_FLOAT_TYPE =
'u';
209 static const char VS_OBJECT_TYPE =
'm';
212 static const char S_OBJECT_TYPE =
'q';
215 static const char B_OBJECT_TYPE =
'p';
218 static const char OBJECT_TYPE =
'o';
222 if(type==
'a' || type==
'g' || type==
'j' || type==
'k' || type==
'v' || type==
'z')
233 static char getEqvNullType(
char type)
235 if(type==
's' || type==
't' || type==
'h' || type==
'y')
237 else if(type==
'n' || type==
'w' || type==
'r' || type==
'q'
238 || type==
'f' || type==
'x' || type==
'e' || type==
'l')
253 this->packets.clear();
267 void addNullPacket(
char type)
270 JDBObjectNew->namedLength += 1;
273 JDBObjectNew->type = type;
274 packets.push_back(JDBObjectNew);
277 void addNullPacket(
char type,
string name)
280 JDBObjectNew->name = name;
281 namedLength += name.length();
282 JDBObjectNew->namedLength += name.length() + 1;
285 JDBObjectNew->type = type;
286 packets.push_back(JDBObjectNew);
294 void addPacket(
const string& stringa,
const string& name)
296 AMEFObject* JDBObjectNew = addPacket(stringa);
297 JDBObjectNew->name = name;
299 namedLength += name.length();
300 JDBObjectNew->namedLength += name.length();
309 JDBObjectNew->name =
"";
311 if(stringa.length()<=256)
313 JDBObjectNew->type = STRING_256_TYPE;
314 length += stringa.length() + 2;
315 namedLength += stringa.length() + 4;
316 JDBObjectNew->namedLength = stringa.length() + 2;
318 else if(stringa.length()<=65536)
320 JDBObjectNew->type = STRING_65536_TYPE;
321 length += stringa.length() + 3;
322 namedLength += stringa.length() + 5;
323 JDBObjectNew->namedLength = stringa.length() + 3;
325 else if(stringa.length()<=16777216)
327 JDBObjectNew->type = STRING_16777216_TYPE;
328 length += stringa.length() + 4;
329 namedLength += stringa.length() + 6;
330 JDBObjectNew->namedLength = stringa.length() + 4;
334 JDBObjectNew->type = STRING_TYPE;
335 length += stringa.length() + 5;
336 namedLength += stringa.length() + 7;
337 JDBObjectNew->namedLength = stringa.length() + 5;
339 JDBObjectNew->length = stringa.length();
340 JDBObjectNew->value = stringa;
341 packets.push_back(JDBObjectNew);
350 void addPacket(
char stringa[],
string name)
352 AMEFObject* JDBObjectNew = addPacket(stringa);
353 JDBObjectNew->name = name;
355 namedLength += name.length();
356 JDBObjectNew->namedLength += name.length();
365 JDBObjectNew->name =
"";
367 if(strlen(stringa)<=256)
369 JDBObjectNew->type = STRING_256_TYPE;
370 length += strlen(stringa) + 2;
371 namedLength += strlen(stringa) + 4;
372 JDBObjectNew->namedLength = strlen(stringa) + 2;
374 else if(strlen(stringa)<=65536)
376 JDBObjectNew->type = STRING_65536_TYPE;
377 length += strlen(stringa) + 3;
378 namedLength += strlen(stringa) + 5;
379 JDBObjectNew->namedLength = strlen(stringa) + 3;
381 else if(strlen(stringa)<=16777216)
383 JDBObjectNew->type = STRING_16777216_TYPE;
384 length += strlen(stringa) + 4;
385 namedLength += strlen(stringa) + 6;
386 JDBObjectNew->namedLength = strlen(stringa) + 4;
390 JDBObjectNew->type = STRING_TYPE;
391 length += strlen(stringa) + 5;
392 namedLength += strlen(stringa) + 7;
393 JDBObjectNew->namedLength = strlen(stringa) + 5;
395 JDBObjectNew->length = strlen(stringa);
396 JDBObjectNew->value = stringa;
397 packets.push_back(JDBObjectNew);
406 void addPacket(
bool boole,
string name)
409 JDBObjectNew->name = name;
411 namedLength += name.length();
412 JDBObjectNew->namedLength += name.length();
421 JDBObjectNew->type = BOOLEAN_TYPE;
422 JDBObjectNew->name =
"";
423 JDBObjectNew->length = 1;
426 JDBObjectNew->value =
"1";
430 JDBObjectNew->value =
"0";
432 packets.push_back(JDBObjectNew);
435 JDBObjectNew->namedLength = 2;
439 void addPacket(
char chr,
string name)
442 JDBObjectNew->name = name;
444 namedLength += name.length();
445 JDBObjectNew->namedLength += name.length();
454 JDBObjectNew->type =
'c';
455 JDBObjectNew->name =
"";
456 JDBObjectNew->length = 1;
457 JDBObjectNew->value.push_back(chr);
458 packets.push_back(JDBObjectNew);
461 JDBObjectNew->namedLength = 2;
468 JDBObjectNew->type = type;
469 JDBObjectNew->name =
"";
470 JDBObjectNew->length = 1;
471 JDBObjectNew->value.push_back(value);
472 packets.push_back(JDBObjectNew);
475 JDBObjectNew->namedLength = 2;
484 void addPacket(
long lon,
string name)
487 JDBObjectNew->name = name;
489 namedLength += name.length();
490 JDBObjectNew->namedLength += name.length();
502 JDBObjectNew->type = VERY_SMALL_INT_TYPE;
503 JDBObjectNew->value = longTocharArray(lon, 1);
506 JDBObjectNew->namedLength = 2;
507 JDBObjectNew->length = 1;
511 JDBObjectNew->type = SMALL_INT_TYPE;
512 JDBObjectNew->value = longTocharArray(lon, 2);
515 JDBObjectNew->namedLength = 3;
516 JDBObjectNew->length = 2;
518 else if(lon<16777216)
520 JDBObjectNew->type = BIG_INT_TYPE;
521 JDBObjectNew->value = longTocharArray(lon, 3);
524 JDBObjectNew->namedLength = 4;
525 JDBObjectNew->length = 3;
527 else if(lon<4294967296ULL)
529 JDBObjectNew->type = INT_TYPE;
530 JDBObjectNew->value = longTocharArray(lon, 4);
533 JDBObjectNew->namedLength = 5;
534 JDBObjectNew->length = 4;
536 else if(lon<1099511627776ULL)
538 JDBObjectNew->type = VS_LONG_INT_TYPE;
539 JDBObjectNew->value = longTocharArray(lon, 5);
542 JDBObjectNew->namedLength = 6;
543 JDBObjectNew->length = 5;
545 else if(lon<281474976710656ULL)
547 JDBObjectNew->type = S_LONG_INT_TYPE;
548 JDBObjectNew->value = longTocharArray(lon, 6);
551 JDBObjectNew->namedLength = 7;
552 JDBObjectNew->length = 6;
554 else if(lon<72057594037927936ULL)
556 JDBObjectNew->type = B_LONG_INT_TYPE;
557 JDBObjectNew->value = longTocharArray(lon, 7);
560 JDBObjectNew->namedLength = 8;
561 JDBObjectNew->length = 7;
565 JDBObjectNew->type = LONG_INT_TYPE;
566 JDBObjectNew->value = longTocharArray(lon, 8);
569 JDBObjectNew->namedLength = 9;
570 JDBObjectNew->length = 8;
572 JDBObjectNew->name =
"";
573 packets.push_back(JDBObjectNew);
581 JDBObjectNew->type = VERY_SMALL_INT_TYPE;
582 JDBObjectNew->value = longTocharArray(lon, 1);
585 JDBObjectNew->namedLength = 2;
586 JDBObjectNew->length = 1;
590 JDBObjectNew->type = SMALL_INT_TYPE;
591 JDBObjectNew->value = longTocharArray(lon, 2);
594 JDBObjectNew->namedLength = 3;
595 JDBObjectNew->length = 2;
597 else if(lon<16777216)
599 JDBObjectNew->type = BIG_INT_TYPE;
600 JDBObjectNew->value = longTocharArray(lon, 3);
603 JDBObjectNew->namedLength = 4;
604 JDBObjectNew->length = 3;
606 else if(lon<(
long)4294967296ULL)
608 JDBObjectNew->type = INT_TYPE;
609 JDBObjectNew->value = longTocharArray(lon, 4);
612 JDBObjectNew->namedLength = 5;
613 JDBObjectNew->length = 4;
615 else if(lon<(
long)1099511627776ULL)
617 JDBObjectNew->type = VS_LONG_INT_TYPE;
618 JDBObjectNew->value = longTocharArray(lon, 5);
621 JDBObjectNew->namedLength = 6;
622 JDBObjectNew->length = 5;
624 else if(lon<(
long)281474976710656ULL)
626 JDBObjectNew->type = S_LONG_INT_TYPE;
627 JDBObjectNew->value = longTocharArray(lon, 6);
630 JDBObjectNew->namedLength = 7;
631 JDBObjectNew->length = 6;
633 else if(lon<(
long)72057594037927936ULL)
635 JDBObjectNew->type = B_LONG_INT_TYPE;
636 JDBObjectNew->value = longTocharArray(lon, 7);
639 JDBObjectNew->namedLength = 8;
640 JDBObjectNew->length = 7;
644 JDBObjectNew->type = LONG_INT_TYPE;
645 JDBObjectNew->value = longTocharArray(lon, 8);
648 JDBObjectNew->namedLength = 9;
649 JDBObjectNew->length = 8;
651 JDBObjectNew->name =
"";
652 packets.push_back(JDBObjectNew);
661 JDBObjectNew->type = VERY_SMALL_INT_TYPE;
662 JDBObjectNew->value = longTocharArray(lon, 1);
665 JDBObjectNew->namedLength = 2;
666 JDBObjectNew->length = 1;
670 JDBObjectNew->type = SMALL_INT_TYPE;
671 JDBObjectNew->value = longTocharArray(lon, 2);
674 JDBObjectNew->namedLength = 3;
675 JDBObjectNew->length = 2;
677 else if(lon<16777216)
679 JDBObjectNew->type = BIG_INT_TYPE;
680 JDBObjectNew->value = longTocharArray(lon, 3);
683 JDBObjectNew->namedLength = 4;
684 JDBObjectNew->length = 3;
686 else if(lon<4294967296ULL)
688 JDBObjectNew->type = INT_TYPE;
689 JDBObjectNew->value = longTocharArray(lon, 4);
692 JDBObjectNew->namedLength = 5;
693 JDBObjectNew->length = 4;
695 else if(lon<1099511627776ULL)
697 JDBObjectNew->type = VS_LONG_INT_TYPE;
698 JDBObjectNew->value = longTocharArray(lon, 5);
701 JDBObjectNew->namedLength = 6;
702 JDBObjectNew->length = 5;
704 else if(lon<281474976710656ULL)
706 JDBObjectNew->type = S_LONG_INT_TYPE;
707 JDBObjectNew->value = longTocharArray(lon, 6);
710 JDBObjectNew->namedLength = 7;
711 JDBObjectNew->length = 6;
713 else if(lon<72057594037927936ULL)
715 JDBObjectNew->type = B_LONG_INT_TYPE;
716 JDBObjectNew->value = longTocharArray(lon, 7);
719 JDBObjectNew->namedLength = 8;
720 JDBObjectNew->length = 7;
724 JDBObjectNew->type = LONG_INT_TYPE;
725 JDBObjectNew->value = longTocharArray(lon, 8);
728 JDBObjectNew->namedLength = 9;
729 JDBObjectNew->length = 8;
731 JDBObjectNew->name =
"";
732 packets.push_back(JDBObjectNew);
740 JDBObjectNew->type = VERY_SMALL_INT_TYPE;
741 JDBObjectNew->value = longTocharArray(lon, 1);
744 JDBObjectNew->namedLength = 2;
745 JDBObjectNew->length = 1;
749 JDBObjectNew->type = SMALL_INT_TYPE;
750 JDBObjectNew->value = longTocharArray(lon, 2);
753 JDBObjectNew->namedLength = 3;
754 JDBObjectNew->length = 2;
756 else if(lon<16777216)
758 JDBObjectNew->type = BIG_INT_TYPE;
759 JDBObjectNew->value = longTocharArray(lon, 3);
762 JDBObjectNew->namedLength = 4;
763 JDBObjectNew->length = 3;
767 JDBObjectNew->type = INT_TYPE;
768 JDBObjectNew->value = longTocharArray(lon, 4);
771 JDBObjectNew->namedLength = 5;
772 JDBObjectNew->length = 4;
774 JDBObjectNew->name =
"";
775 packets.push_back(JDBObjectNew);
784 void addPacket(
float doub,
string name)
787 JDBObjectNew->name = name;
789 namedLength += name.length();
790 JDBObjectNew->namedLength += name.length();
799 JDBObjectNew->type = DOUBLE_FLOAT_TYPE;
800 JDBObjectNew->name =
"";
801 JDBObjectNew->value = CastUtil::lexical_cast<
string>(doub);
802 JDBObjectNew->length = JDBObjectNew->value.length();
803 length += JDBObjectNew->value.length() + 2;
804 namedLength += JDBObjectNew->value.length() + 4;
805 JDBObjectNew->namedLength = JDBObjectNew->value.length() + 2;
806 packets.push_back(JDBObjectNew);
816 void addPacket(
double doub,
string name)
819 JDBObjectNew->name = name;
821 namedLength += name.length();
822 JDBObjectNew->namedLength += name.length();
831 JDBObjectNew->type = DOUBLE_FLOAT_TYPE;
832 JDBObjectNew->name =
"";
833 JDBObjectNew->value = CastUtil::lexical_cast<
string>(doub);
834 JDBObjectNew->length = JDBObjectNew->value.length();
835 length += JDBObjectNew->value.length() + 2;
836 namedLength += JDBObjectNew->value.length() + 4;
837 JDBObjectNew->namedLength = JDBObjectNew->value.length() + 2;
838 packets.push_back(JDBObjectNew);
847 void addPacket(
int integer,
string name)
849 AMEFObject* JDBObjectNew = addPacket(integer);
850 JDBObjectNew->name = name;
852 namedLength += name.length();
853 JDBObjectNew->namedLength += name.length();
864 JDBObjectNew->type = VERY_SMALL_INT_TYPE;
865 JDBObjectNew->value = intTocharArray(integer, 1);
868 JDBObjectNew->namedLength = 2;
869 JDBObjectNew->length = 1;
871 else if(integer<65536)
873 JDBObjectNew->type = SMALL_INT_TYPE;
874 JDBObjectNew->value = intTocharArray(integer, 2);
877 JDBObjectNew->namedLength = 3;
878 JDBObjectNew->length = 2;
880 else if(integer<16777216)
882 JDBObjectNew->type = BIG_INT_TYPE;
883 JDBObjectNew->value = intTocharArray(integer, 3);
886 JDBObjectNew->namedLength = 4;
887 JDBObjectNew->length = 3;
891 JDBObjectNew->type = INT_TYPE;
892 JDBObjectNew->value = intTocharArray(integer, 4);
895 JDBObjectNew->namedLength = 5;
896 JDBObjectNew->length = 4;
898 JDBObjectNew->name =
"";
899 packets.push_back(JDBObjectNew);
942 packets.push_back(packet);
943 if(packet->type==
'o')
945 if(packet->length+1<256)
947 else if(packet->length+1<65536)
949 else if(packet->length+1<16777216)
954 length += packet->getLength();
955 namedLength += packet->getNamedLength(
false);
967 void addPacket(
char packet[],
char type)
969 if(type==
's' || type==
'd' || type==
't' || type==
'h' || type==
'y')
973 else if(type==
'n' || type==
'w' || type==
'r' || type==
'i')
975 addPacket(charArrayToInt(packet));
977 else if(type==
'f' || type==
'x' || type==
'e' || type==
'l')
979 addPacket(charArrayToLong(packet));
987 addPacket(packet[0]==
'1'?
true:
false);
991 addPacket((
char)packet[0]);
993 else if(type==
'a' || type==
'g' || type==
'j' || type==
'k' || type==
'v' || type==
'z')
1039 static bool isstring(
char type)
1041 if(type==
's' || type==
't' || type==
'h' || type==
'y' || type==
'a')
1046 static bool isFloatingPoint(
char type)
1048 if(type==
'u' || type==
'k')
1053 static bool isNumber(
char type)
1055 if(type==
'n' || type==
'w' || type==
'r' || type==
'i'
1056 || type==
'f' || type==
'x' || type==
'e' || type==
'l' || type==
'g')
1061 static bool isInteger(
char type)
1063 if(type==
'n' || type==
'w' || type==
'r' || type==
'i')
1068 static bool isLong(
char type)
1070 if(type==
'n' || type==
'w' || type==
'r' || type==
'i'
1071 || type==
'f' || type==
'x' || type==
'e' || type==
'l')
1076 static bool isChar(
char type)
1078 if(type==
'c' || type==
'z')
1083 static bool isBoolean(
char type)
1085 if(type==
'b' || type==
'v')
1090 static bool isDate(
char type)
1092 if(type==
'd' || type==
'j')
1097 bool isStringOrNullString()
1099 if(type==
's' || type==
't' || type==
'h' || type==
'y' || type==
'a')
1106 if(type==
's' || type==
't' || type==
'h' || type==
'y')
1111 bool isFloatingPoint()
1113 if(type==
'u' || type==
'k')
1120 if(type==
'n' || type==
'w' || type==
'r' || type==
'i'
1121 || type==
'f' || type==
'x' || type==
'e' || type==
'l' || type==
'g')
1126 bool isNumberOrNullNumber()
1128 if(type==
'n' || type==
'w' || type==
'r' || type==
'i'
1129 || type==
'f' || type==
'x' || type==
'e' || type==
'l')
1136 if(type==
'b' || type==
'c' || type==
'v' || type==
'z')
1143 if(type==
'd' || type==
'j')
1148 int getNamedLength(
bool ignoreName)
1156 else if(length<65536)
1158 else if(length<16777216)
1167 if(getType()!=
'n' && getType()!=
'w' && getType()!=
'r'
1168 && getType()!=
'i' && getType()!=
'f' && getType()!=
'x'
1169 && getType()!=
'e' && getType()!=
'l' && getType()!=
'b'
1174 if(getType()==
'a' || getType()==
'g'
1175 || getType()==
'j' || getType()==
'v' || getType()==
'z')
1179 else if(length<65536)
1181 else if(length<16777216)
1192 if(2 + namedLength<256)
1197 else if(2 + namedLength<65536)
1202 else if(2 + namedLength<16777216)
1214 else if(getType()==
'm' || getType()==
'p' || getType()==
'q')
1220 return 2 + namedLength;
1226 void setLength(
int length)
1228 this->length = length;
1233 return (
char*)name.c_str();
1239 void setName(
const string& name)
1247 vector<AMEFObject*> getPackets()
1251 void setPackets(vector<AMEFObject*> packets)
1253 this->packets = packets;
1260 void setType(
char type)
1293 string getValueStr()
1297 void pushChar(
char v)
1299 this->value.push_back(v);
1301 void setValue(
char value[])
1303 int len = strlen(value);
1304 for (
int var = 0; var < len; var++) {
1305 this->value.push_back(value[var]);
1309 void setValue(
char *value,
int len)
1311 this->value.append(value,len);
1313 void setValue(
const string& value)
1315 this->value = value;
1324 return (value[0]==
'1'?
true:
false);
1334 if(type==
'n' || type==
'w' || type==
'r' || type==
'i')
1336 return charArrayToInt(value);
1345 short getShortValue()
1347 if(type==
'n' || type==
'w' || type==
'r' || type==
'i')
1349 return (
short)charArrayToInt(value);
1358 double getDoubleValue()
1361 return (CastUtil::lexical_cast<double>(getValueStr()));
1369 float getFloatValue()
1372 return (CastUtil::lexical_cast<float>(getValueStr()));
1382 if(type==
'f' || type==
'x' || type==
'e' || type==
'l')
1384 return charArrayToLong(value);
1390 long getNumericValue()
1392 if(type==
'f' || type==
'x' || type==
'e' || type==
'l'
1393 || type==
'n' || type==
'w' || type==
'r' || type==
'i')
1395 return charArrayToLong(value);
1423 return displayObject(
"");
1426 string displayObject(
string tab)
1429 for (
int i=0;i<(int)getPackets().size();i++)
1432 displ += tab +
"Object Type = ";
1434 displ +=
"\n" + tab +
"Object Name = " + obj->name +
"\n";
1435 displ += tab +
"Object Value = ";
1436 if(obj->isStringOrNullString() || obj->isFloatingPoint() || obj->isDate())
1437 displ += (obj->getValueStr()) +
"\n";
1438 else if(obj->isChar())
1441 displ += CastUtil::lexical_cast<
string>(obj->
getBoolValue()) +
"\n";
1443 displ += (char)obj->value[0] +
"\n";
1445 else if(obj->isNumberOrNullNumber())
1447 displ += CastUtil::lexical_cast<
string>(obj->getNumericValue()) +
"\n";
1449 if(obj->type==
'o' || obj->type==
'p' || obj->type==
'q' || obj->type==
'm')
1451 displ += obj->displayObject(tab+
"\t");
1459 packets.push_back(obj);