53std::string
DataMessageHeader::toJSON(std::map<uint16, std::string>* subtypes, std::map<uint16, std::string>* subcontexts, std::map<uint32, std::string>* compNames) {
55 if (!subtypes && !subcontexts && !compNames)
56 return utils::StringFormat(
"{ \"size\": %u, \"memid\": \"%llu\", \"time\": \"%llu\", \"time__desc\": \"%s\", \"sendtime\": \"%llu\", \"sendtime__desc\": \"%s\", \"recvtime\": \"%llu\", \"recvtime__desc\": \"%s\", "
57 "\"modulecputime\": %u, \"modulewalltime\": %u, \"chaincputime\": %u, \"chainwalltime\": %u, \"chaincount\": %u, "
58 "\"origin\": %u, \"destination\": %u, \"ttl\": \"%llu\", \"eol__desc\": \"%s\", \"priority\": %u, \"policy\": %u, \"from\": %u, \"to\": %u, \"type\": \"%s\", \"tag\": \"%u\", \"status\": %u, \"reference\": \"%llu\", \"serial\": \"%llu\", \"contextchange\": \"%s\", \"userdatacount\": %u, \"userdatasize\": %u }",
69 std::string typeStr, contextStr, fromStr, toStr;
70 typeStr =
type.toString(subtypes);
73 fromStr = (*compNames)[
from];
74 toStr = (*compNames)[
to];
76 if (!fromStr.length()) {
80 if (!toStr.length()) {
84 return utils::StringFormat(
"{ \"size\": %u, \"memid\": \"%llu\", \"time\": \"%llu\", \"time__desc\": \"%s\", \"sendtime\": \"%llu\", \"sendtime__desc\": \"%s\", \"recvtime\": \"%llu\", \"recvtime__desc\": \"%s\", "
85 "\"modulecputime\": %u, \"modulewalltime\": %u, \"chaincputime\": %u, \"chainwalltime\": %u, \"chaincount\": %u, "
86 "\"origin\": %u, \"destination\": %u, \"ttl\": \"%llu\", \"eol__desc\": \"%s\", \"priority\": %u, \"policy\": %u, \"from\": \"%s\", \"to\": \"%s\", \"type\": \"%s\", \"tag\": \"%u\", \"status\": %u, \"reference\": \"%llu\", \"serial\": \"%llu\", \"contextchange\": \"%s\", \"userdatacount\": %u, \"userdatasize\": %u }",
101std::string
DataMessageHeader::toXML(std::map<uint16, std::string>* subtypes, std::map<uint16, std::string>* subcontexts, std::map<uint32, std::string>* compNames) {
104 if (!subtypes && !subcontexts && !compNames)
105 return utils::StringFormat(
"<datamessage size=\"%u\" memid=\"%llu\" time=\"%llu\" timetext=\"%s\" sendtime=\"%llu\" sendtimetext=\"%s\" recvtime=\"%llu\" recvtimetext=\"%s\" "
106 "modulecputime=\"%u\" modulewalltime=\"%u\" chaincputime=\"%u\" chainwalltime=\"%u\" chaincount=\"%u\" "
107 "origin=\"%u\" destination=\"%u\" ttl=\"%llu\" eoltext=\"%s\" priority=\"%u\" policy=\"%u\" from=\"%u\" to=\"%u\" type=\"%s\" tag=\"%u\" status=\"%u\" reference=\"%llu\" serial=\"%llu\" contextchange=\"%s\" userdatacount=\"%u\" userdatasize=\"%u\" />\n",
113 origin,
destination,
ttl,
ttl ?
PrintTimeString(
time +
ttl).c_str() :
"",
priority,
policy,
from,
to,
type.toString().c_str(),
tag,
status,
reference,
serial,
contextchange.isValid() ?
contextchange.toString().c_str() :
"",
userCount,
userSize);
115 std::string typeStr, contextStr, fromStr, toStr;
116 typeStr =
type.toString(subtypes);
119 fromStr = (*compNames)[
from];
120 toStr = (*compNames)[
to];
122 if (!fromStr.length()) {
126 if (!toStr.length()) {
131 return utils::StringFormat(
"<datamessage size=\"%u\" memid=\"%llu\" time=\"%llu\" timetext=\"%s\" sendtime=\"%llu\" sendtimetext=\"%s\" recvtime=\"%llu\" recvtimetext=\"%s\" "
132 "modulecputime=\"%u\" modulewalltime=\"%u\" chaincputime=\"%u\" chainwalltime=\"%u\" chaincount=\"%u\" "
133 "origin=\"%u\" destination=\"%u\" ttl=\"%llu\" eoltext=\"%s\" priority=\"%u\" policy=\"%u\" from=\"%s\" to=\"%s\" type=\"%s\" tag=\"%u\" status=\"%u\" reference=\"%llu\" serial=\"%llu\" contextchange=\"%s\" userdatacount=\"%u\" userdatasize=\"%u\" />\n",
162 while (src < srcEnd) {
179 struct ArrayElem { int64 index;
char* entryPtr; uint32 cid; };
180 struct MapElem { std::string index;
char* entryPtr; uint32 cid; };
191 if (!
data->userCount)
194 std::map< std::string, std::list<ArrayElem> > userArrays;
195 std::map< std::string, std::list<MapElem> > userMaps;
199 const char* mapStart, *mapEnd;
200 std::string userData;
201 userData.reserve(
data->userSize +
data->userCount * 64);
203 char* srcEnd = (
char*)
data +
data->size;
204 while (src < srcEnd) {
208 if ((mapStart = strstr(key,
"_-|")) && (mapEnd = strstr(key,
"|-_"))) {
210 e.index =
utils::Ascii2Int64(std::string(mapStart + 3, mapEnd - mapStart - 3).c_str());
213 userArrays[std::string(key, mapStart - key)].push_back(e);
217 else if ((mapStart = strstr(key,
"_-[")) && (mapEnd = strstr(key,
"]-_"))) {
219 e.index = std::string(mapStart + 3, mapEnd - mapStart - 3);
222 userMaps[std::string(key, mapStart - key)].push_back(e);
257 if (userData.length()) userData +=
", ";
272 std::string subUserData;
274 std::list<ArrayElem>::iterator entryII, entryEE;
275 std::map< std::string, std::list<ArrayElem> >::iterator keyII = userArrays.begin(), keyEE = userArrays.end();
276 while (keyII != keyEE) {
278 entryII = keyII->second.begin();
279 entryEE = keyII->second.end();
280 while (entryII != entryEE) {
281 char* ep = entryII->entryPtr;
283 uint32 cid = entryII->cid;
300 if (subUserData.length()) subUserData +=
", ";
306 subUserData +=
utils::StringFormat(
"%lld : %lld (integer)\n", entryII->index, *(int64*)val);
312 subUserData +=
utils::StringFormat(
"%lld : (string of size %lld)\n", entryII->index, *(int64*)val);
315 subUserData +=
utils::StringFormat(
"%lld : (binary of size %lld)\n", entryII->index, *(int64*)val);
318 subUserData +=
utils::StringFormat(
"%lld : (message of size %lld)\n", entryII->index, *(int64*)val);
329 std::list<MapElem>::iterator entryI, entryE;
330 std::map< std::string, std::list<MapElem> >::iterator keyI = userMaps.begin(), keyE = userMaps.end();
331 while (keyI != keyE) {
333 entryI = keyI->second.begin();
334 entryE = keyI->second.end();
335 while (entryI != entryE) {
336 char* ep = entryI->entryPtr;
338 uint32 cid = entryI->cid;
345 entryI->index.c_str(),
355 if (subUserData.length()) subUserData +=
", ";
361 subUserData +=
utils::StringFormat(
"'%s' : %lld (integer)\n", entryI->index.c_str(), *(int64*)val);
364 subUserData +=
utils::StringFormat(
"'%s' : %f (float)\n", entryI->index.c_str(), *(float64*)val);
367 subUserData +=
utils::StringFormat(
"'%s' : (string of size %lld)\n", entryI->index.c_str(), *(int64*)val);
370 subUserData +=
utils::StringFormat(
"'%s' : (binary of size %lld)\n", entryI->index.c_str(), *(int64*)val);
373 subUserData +=
utils::StringFormat(
"'%s' : (message of size %lld)\n", entryI->index.c_str(), *(int64*)val);
395 if (!
data->userCount)
398 std::map< std::string, std::list<ArrayElem> > userArrays;
399 std::map< std::string, std::list<MapElem> > userMaps;
401 const char* oldData = NULL;
404 const char* mapStart, *mapEnd;
405 std::string userData;
406 userData.reserve(
data->userSize +
data->userCount * 64);
408 char* srcEnd = (
char*)
data +
data->size;
409 while (src < srcEnd) {
413 if ((mapStart = strstr(key,
"_-|")) && (mapEnd = strstr(key,
"|-_"))) {
415 e.index =
utils::Ascii2Int64(std::string(mapStart + 3, mapEnd - mapStart - 3).c_str());
418 userArrays[std::string(key, mapStart - key)].push_back(e);
422 else if ((mapStart = strstr(key,
"_-[")) && (mapEnd = strstr(key,
"]-_"))) {
424 e.index = std::string(mapStart + 3, mapEnd - mapStart - 3);
427 userMaps[std::string(key, mapStart - key)].push_back(e);
433 if (userData.length()) userData +=
", ";
440 if (userData.length()) userData +=
", ";
442 userData +=
utils::StringFormat(
"\"%s\": {\"type\": \"time\", \"value\": %llu, \"text\": \"%s\" }\n",
453 if (userData.length()) userData +=
", ";
458 if (userData.length()) userData +=
", ";
465 if (userData.length()) userData +=
", ";
479 if (userData.length()) userData +=
", ";
490 if (userData.length()) userData +=
", ";
496 if (userData.length()) userData +=
", ";
502 if (userData.length()) userData +=
", ";
519 std::string subUserData;
521 std::list<ArrayElem>::iterator entryII, entryEE;
522 std::map< std::string, std::list<ArrayElem> >::iterator keyII = userArrays.begin(), keyEE = userArrays.end();
523 while (keyII != keyEE) {
525 entryII = keyII->second.begin();
526 entryEE = keyII->second.end();
527 while (entryII != entryEE) {
528 char* ep = entryII->entryPtr;
530 uint32 cid = entryII->cid;
531 if (subUserData.length()) subUserData +=
", ";
535 subUserData +=
utils::StringFormat(
"%lld: {\"type\": \"text\", \"value\": \"%s\" }\n", entryII->index, val);
541 subUserData +=
utils::StringFormat(
"%lld: {\"type\": \"time\", \"value\": %llu, \"text\": \"%s\" }\n",
542 entryII->index, *(uint64*)val,
555 if (subUserData.length()) subUserData +=
", ";
557 subUserData +=
utils::StringFormat(
"%lld: {\"type\": \"message\", \"value\": %s }\n", entryII->index, msg->
toJSON().c_str());
565 subUserData +=
utils::StringFormat(
"%lld: {\"type\": \"integer\", \"value\": %lld }\n", entryII->index, *(int64*)val);
571 subUserData +=
utils::StringFormat(
"%lld: {\"type\": \"double\", \"value\": %f }\n", entryII->index, *(float64*)val);
577 subUserData +=
utils::StringFormat(
"%lld: {\"type\": \"textinfo\", \"size\": %lld }", entryII->index, *(int64*)val);
581 subUserData +=
utils::StringFormat(
"%lld: {\"type\": \"binary\", \"size\": %lld }", entryII->index, *(int64*)val);
585 subUserData +=
utils::StringFormat(
"%lld: {\"type\": \"messageinfo\", \"size\": %lld }", entryII->index, *(int64*)val);
592 if (userData.length()) userData +=
", ";
594 userData +=
utils::StringFormat(
"\"%s\": {\"type\": \"array\", \"value\":\n{%s} }\n", keyII->first.c_str(), subUserData.c_str());
596 userData +=
utils::StringFormat(
"\"%s\": {%s}\n", keyII->first.c_str(), subUserData.c_str());
601 std::list<MapElem>::iterator entryI, entryE;
602 std::map< std::string, std::list<MapElem> >::iterator keyI = userMaps.begin(), keyE = userMaps.end();
603 while (keyI != keyE) {
605 entryI = keyI->second.begin();
606 entryE = keyI->second.end();
607 while (entryI != entryE) {
608 char* ep = entryI->entryPtr;
610 uint32 cid = entryI->cid;
611 if (subUserData.length()) subUserData +=
", ";
615 subUserData +=
utils::StringFormat(
"\"%s\": {\"type\": \"text\", \"value\": \"%s\" }\n", entryI->index.c_str(), val);
621 subUserData +=
utils::StringFormat(
"\"%s\": {\"type\": \"time\", \"value\": %llu, \"text\": \"%s\" }\n",
622 entryI->index.c_str(), *(uint64*)val,
635 if (subUserData.length()) subUserData +=
", ";
637 subUserData +=
utils::StringFormat(
"\"%s\": {\"type\": \"message\", \"value\": %s }\n", entryI->index.c_str(), msg->
toJSON().c_str());
645 subUserData +=
utils::StringFormat(
"\"%s\": {\"type\": \"integer\", \"value\": %lld }\n", entryI->index.c_str(), *(int64*)val);
647 subUserData +=
utils::StringFormat(
"\"%s\": \"%lld\"\n", entryI->index.c_str(), *(int64*)val);
651 subUserData +=
utils::StringFormat(
"\"%s\": {\"type\": \"double\", \"value\": %f }\n", entryI->index.c_str(), *(float64*)val);
653 subUserData +=
utils::StringFormat(
"\"%s\": \"%f\" }\n", entryI->index.c_str(), *(float64*)val);
657 subUserData +=
utils::StringFormat(
"\"%s\": {\"type\": \"textinfo\", \"size\": %lld }", entryI->index.c_str(), *(int64*)val);
661 subUserData +=
utils::StringFormat(
"\"%s\": {\"type\": \"binary\", \"size\": %lld }", entryI->index.c_str(), *(int64*)val);
665 subUserData +=
utils::StringFormat(
"\"%s\": {\"type\": \"messageinfo\", \"size\": %lld }", entryI->index.c_str(), *(int64*)val);
672 if (userData.length()) userData +=
", ";
674 userData +=
utils::StringFormat(
"\"%s\": {\"type\": \"map\", \"value\":\n{%s} }\n", keyI->first.c_str(), subUserData.c_str());
676 userData +=
utils::StringFormat(
"\"%s\": {%s}\n", keyI->first.c_str(), subUserData.c_str());
684std::string
DataMessage::toJSON(std::map<uint16, std::string>* subtypes, std::map<uint16, std::string>* subcontexts, std::map<uint32, std::string>* compNames) {
687 if (!
data->userCount)
688 return data->toJSON(subtypes, subcontexts, compNames);
692 std::map< std::string, std::list<std::string> > userMaps;
693 std::map< std::string, std::list<int64> > userArrays;
695 uint32 draftSize = 0;
696 uint32 draftUserSize = 0;
697 uint32 draftUserCount = 0;
701 char* srcEnd = (
char*)
data +
data->size;
702 while (src < srcEnd) {
708 if (strcmp(key,
"OS") == 0)
710 else if (strcmp(key,
"US") == 0)
712 else if (strcmp(key,
"UC") == 0)
722 return utils::StringFormat(
"{ \"draft\":\"yes\", \"size\": %u, \"memid\": \"%llu\", \"time\": \"%llu\", \"time__text\": \"%s\", \"sendtime\": \"%llu\", \"sendtime__text\": \"%s\", \"recvtime\": \"%llu\", \"recvtime__text\": \"%s\", \"origin\": %u, \"destination\": %u, \"ttl\": \"%llu\", \"eol__text\": \"%s\", \"priority\": %u, \"policy\": %u, \"from\": %u, \"to\": %u, \"type\": \"%s\", \"tag\": \"%u\", \"status\": %u, \"reference\": \"%llu\", \"serial\": \"%llu\", \"contextchange\": \"%s\", \"userdatacount\": %u, \"userdatasize\": %u, \"userdata\":\n%s }\n",
723 draftSize,
data->memid,
729 data->contextchange.isValid() ?
data->contextchange.toString().c_str() :
"",
730 draftUserCount, draftUserSize, userData.c_str());
733 return utils::StringFormat(
"{ \"size\": %u, \"memid\": \"%llu\", \"time\": \"%llu\", \"time__text\": \"%s\", \"sendtime\": \"%llu\", \"sendtime__text\": \"%s\", \"recvtime\": \"%llu\", \"recvtime__text\": \"%s\", \"origin\": %u, \"destination\": %u, \"ttl\": \"%llu\", \"eol__text\": \"%s\", \"priority\": %u, \"policy\": %u, \"from\": %u, \"to\": %u, \"type\": \"%s\", \"tag\": \"%u\", \"status\": %u, \"reference\": \"%llu\", \"serial\": \"%llu\", \"contextchange\": \"%s\", \"userdatacount\": %u, \"userdatasize\": %u, \"userdata\":\n%s }\n",
740 data->contextchange.isValid() ?
data->contextchange.toString().c_str() :
"",
741 data->userCount,
data->userSize, userData.c_str());
745std::string
DataMessage::toCSV(
const char* separator,
const char* preample, std::map<uint16, std::string>* subtypes, std::map<uint16, std::string>* subcontexts, std::map<uint32, std::string>* compNames) {
750 if (separator && (len = (uint32)strlen(separator)))
751 memcpy(sep, separator, len+1);
755 std::string userData;
756 if (
data->userCount) {
762 std::string typeStr, contextStr, fromStr, toStr;
763 typeStr =
data->type.toString(subtypes);
764 contextStr =
data->contextchange.toString(subcontexts);
766 fromStr = (*compNames)[
data->from];
767 toStr = (*compNames)[
data->to];
769 if (!fromStr.length()) {
773 if (!toStr.length()) {
778 if (preample && strlen(preample)) {
779 return utils::StringFormat(
"%s%s%s%s%s%s%s%s%s%s%u%s%u%s%u%s%u%s%u%s%u%s%u%s%llu%s%s%s%s%s%u%s%llu%s%s%s%u%s%u%s%s\n",
781 typeStr.c_str(), sep,
785 data->cyclecputime, sep,
786 data->cyclewalltime, sep,
787 data->chaincputime, sep,
788 data->chainwalltime, sep,
789 data->chaincount, sep,
793 fromStr.c_str(), sep,
797 contextStr.c_str(), sep,
798 data->userCount, sep,
803 return utils::StringFormat(
"%s%s%s%s%s%s%s%s%u%s%u%s%u%s%u%s%u%s%u%s%u%s%llu%s%s%s%s%s%u%s%llu%s%s%s%u%s%u%s%s\n",
804 typeStr.c_str(), sep,
808 data->cyclecputime, sep,
809 data->cyclewalltime, sep,
810 data->chaincputime, sep,
811 data->chainwalltime, sep,
812 data->chaincount, sep,
816 fromStr.c_str(), sep,
820 contextStr.c_str(), sep,
821 data->userCount, sep,
832 if (separator && (len = (uint32)strlen(separator)))
833 memcpy(sep, separator, len + 1);
838 if (preample && strlen(preample))
839 header =
utils::StringFormat(
"%s,type,created,sent,received,modulecputime,modulewalltime,chaincputime,chainwalltime,chaincount,size,priority,ttl,from,to,tag,serial,contextchange,userdatacount,userdatasize,userdata\n", preample);
841 header =
"type,created,sent,received,modulecputime,modulewalltime,chaincputime,chainwalltime,chaincount,size,priority,ttl,from,to,tag,serial,contextchange,userdatacount,userdatasize,userdata\n";
850std::string
DataMessage::toXML(std::map<uint16, std::string>* subtypes, std::map<uint16, std::string>* subcontexts, std::map<uint32, std::string>* compNames) {
853 if (!
data->userCount)
854 return data->toXML(subtypes, subcontexts, compNames);
856 std::map< std::string, std::list<ArrayElem> > userArrays;
857 std::map< std::string, std::list<MapElem> > userMaps;
858 uint32 draftSize = 0;
859 uint32 draftUserSize = 0;
860 uint32 draftUserCount = 0;
862 const char* oldData = NULL;
865 const char* mapStart, *mapEnd;
866 std::string userData;
867 userData.reserve(
data->userSize +
data->userCount * 64);
869 char* srcEnd = (
char*)
data +
data->size;
870 while (src < srcEnd) {
874 if ((mapStart = strstr(key,
"_-|")) && (mapEnd = strstr(key,
"|-_"))) {
876 e.index =
utils::Ascii2Int64(std::string(mapStart + 3, mapEnd - mapStart - 3).c_str());
879 userArrays[std::string(key, mapStart - key)].push_back(e);
883 else if ((mapStart = strstr(key,
"_-[")) && (mapEnd = strstr(key,
"]-_"))) {
885 e.index = std::string(mapStart + 3, mapEnd - mapStart - 3);
888 userMaps[std::string(key, mapStart - key)].push_back(e);
897 userData +=
utils::StringFormat(
"<data name=\"%s\" type=\"time\" value=\"%llu\" text=\"%s\" />\n",
935 if (strcmp(key,
"OS") == 0)
937 else if (strcmp(key,
"US") == 0)
939 else if (strcmp(key,
"UC") == 0)
953 std::string subUserData;
955 std::list<ArrayElem>::iterator entryII, entryEE;
956 std::map< std::string, std::list<ArrayElem> >::iterator keyII = userArrays.begin(), keyEE = userArrays.end();
957 while (keyII != keyEE) {
959 entryII = keyII->second.begin();
960 entryEE = keyII->second.end();
961 while (entryII != entryEE) {
962 char* ep = entryII->entryPtr;
964 uint32 cid = entryII->cid;
967 subUserData +=
utils::StringFormat(
"<data name=\"%lld\" type=\"text\" value=\"%s\" />\n", entryII->index, val);
970 subUserData +=
utils::StringFormat(
"<data name=\"%lld\" type=\"time\" value=\"%llu\" text=\"%s\" />\n",
971 entryII->index, *(uint64*)val,
979 subUserData +=
utils::StringFormat(
"<data name=\"%lld\" type=\"integer\" value=\"%lld\" />\n", entryII->index, *(int64*)val);
982 subUserData +=
utils::StringFormat(
"<data name=\"%lld\" type=\"float\" value=\"%f\" />\n", entryII->index, *(float64*)val);
987 subUserData +=
utils::StringFormat(
"<data name=\"%lld\" type=\"datamessage\">\n%s</data>", entryII->index, msg->
toXML().c_str());
992 subUserData +=
utils::StringFormat(
"<data name=\"%lld\" type=\"textinfo\" size=\"%lld\" />\n", entryII->index, *(int64*)val);
995 subUserData +=
utils::StringFormat(
"<data name=\"%lld\" type=\"binary\" size=\"%lld\" />\n", entryII->index, *(int64*)val);
998 subUserData +=
utils::StringFormat(
"<data name=\"%lld\" type=\"messageinfo\" size=\"%lld\" />\n", entryII->index, *(int64*)val);
1005 userData +=
utils::StringFormat(
"<array name=\"%s\">\n%s</array>\n", keyII->first.c_str(), subUserData.c_str());
1009 std::list<MapElem>::iterator entryI, entryE;
1010 std::map< std::string, std::list<MapElem> >::iterator keyI = userMaps.begin(), keyE = userMaps.end();
1011 while (keyI != keyE) {
1012 subUserData.clear();
1013 entryI = keyI->second.begin();
1014 entryE = keyI->second.end();
1015 while (entryI != entryE) {
1016 char* ep = entryI->entryPtr;
1018 uint32 cid = entryI->cid;
1021 subUserData +=
utils::StringFormat(
"<data name=\"%s\" type=\"text\" value=\"%s\" />\n", entryI->index.c_str(), val);
1024 subUserData +=
utils::StringFormat(
"<data name=\"%s\" type=\"time\" value=\"%llu\" text=\"%s\" />\n",
1025 entryI->index.c_str(), *(uint64*)val,
1033 subUserData +=
utils::StringFormat(
"<data name=\"%s\" type=\"integer\" value=\"%lld\" />\n", entryI->index.c_str(), *(int64*)val);
1036 subUserData +=
utils::StringFormat(
"<data name=\"%s\" type=\"float\" value=\"%f\" />\n", entryI->index.c_str(), *(float64*)val);
1041 subUserData +=
utils::StringFormat(
"<data name=\"%s\" type=\"datamessage\">\n%s</data>", entryI->index.c_str(), msg->
toXML().c_str());
1046 subUserData +=
utils::StringFormat(
"<data name=\"%s\" type=\"textinfo\" size=\"%lld\" />\n", entryI->index.c_str(), *(int64*)val);
1049 subUserData +=
utils::StringFormat(
"<data name=\"%s\" type=\"binary\" size=\"%lld\" />\n", entryI->index.c_str(), *(int64*)val);
1052 subUserData +=
utils::StringFormat(
"<data name=\"%s\" type=\"messageinfo\" size=\"%lld\" />\n", entryI->index.c_str(), *(int64*)val);
1059 userData +=
utils::StringFormat(
"<map name=\"%s\">\n%s</map>\n", keyI->first.c_str(), subUserData.c_str());
1064 return utils::StringFormat(
"<datamessage draft=\"yes\" size=\"%u\" memid=\"%llu\" time=\"%llu\" timetext=\"%s\" sendtime=\"%llu\" sendtimetext=\"%s\" recvtime=\"%llu\" recvtimetext=\"%s\" origin=\"%u\" destination=\"%u\" ttl=\"%llu\" eoltext=\"%s\" priority=\"%u\" policy=\"%u\" from=\"%u\" to=\"%u\" type=\"%s\" tag=\"%u\" status=\"%u\" reference=\"%llu\" serial=\"%llu\" contextchange=\"%s\" userdatacount=\"%u\" userdatasize=\"%u\">\n%s</datamessage>\n",
1065 draftSize,
data->memid,
1070 data->priority,
data->policy,
data->from,
data->to,
data->type.toString().c_str(),
data->tag,
data->status,
data->reference,
data->serial,
data->contextchange.isValid() ?
data->contextchange.toString().c_str() :
"", draftUserCount, draftUserSize, userData.c_str());
1073 return utils::StringFormat(
"<datamessage size=\"%u\" memid=\"%llu\" time=\"%llu\" timetext=\"%s\" sendtime=\"%llu\" sendtimetext=\"%s\" recvtime=\"%llu\" recvtimetext=\"%s\" origin=\"%u\" destination=\"%u\" ttl=\"%llu\" eoltext=\"%s\" priority=\"%u\" policy=\"%u\" from=\"%u\" to=\"%u\" type=\"%s\" tag=\"%u\" status=\"%u\" reference=\"%llu\" serial=\"%llu\" contextchange=\"%s\" userdatacount=\"%u\" userdatasize=\"%u\">\n%s</datamessage>\n",
1079 data->priority,
data->policy,
data->from,
data->to,
data->type.toString().c_str(),
data->tag,
data->status,
data->reference,
data->serial,
data->contextchange.isValid() ?
data->contextchange.toString().c_str() :
"",
data->userCount,
data->userSize, userData.c_str());
1128 data->priority = priority;
1145 data->priority = priority;
1162 char* newData = NULL;
1184 uint32 size = *(uint32*)
data;
1186 memcpy(this->data,
data, size);
1217 char* newData = NULL;
1234 uint32 size = *(uint32*)
data;
1236 memcpy(this->data,
data, size);
1287 const char* newData = (
const char*)correctMsg->
data;
1288 uint32 size = *(uint32*)newData;
1289 if (size <= maxDraftSize) {
1291 memcpy(this->data, newData, size);
1312 uint32 size = *(uint32*)
data;
1313 if (size <= maxDraftSize) {
1315 memcpy(this->data,
data, size);
1336 uint32 size = *(uint32*)msg.
data;
1337 if (size <= maxDraftSize) {
1339 memcpy(this->
data, msg.
data, size);
1365 if (!
data->userCount)
1370 if (this->data->
size + (3 * draftInfoSize) > maxDraftSize)
1381 size =
data->userSize;
1383 size =
data->userCount;
1386 std::map< std::string, std::list<std::string> > userMaps;
1389 std::string userData;
1393 char* srcEnd = (
char*)
data +
data->size;
1394 while (src < srcEnd) {
1402 if (this->data->
size + itemSize < maxDraftSize) {
1412 if (this->data->
size + itemSize < maxDraftSize) {
1422 if (this->data->
size + itemSize < maxDraftSize) {
1433 if (this->data->
size + itemSize < maxDraftSize) {
1438 this->data->
userSize += itemSize -
sizeof(int64) + (uint32)size;
1444 if (this->data->
size + itemSize < maxDraftSize) {
1449 this->data->
userSize += itemSize -
sizeof(int64) + (uint32)size;
1456 if (this->data->
size + itemSize < maxDraftSize) {
1461 this->data->
userSize += itemSize -
sizeof(int64) + (uint32)size;
1467 if (this->data->
size + itemSize < maxDraftSize) {
1472 this->data->
userSize += itemSize -
sizeof(int64) + (uint32)size;
1478 if (this->data->
size + itemSize < maxDraftSize) {
1483 this->data->
userSize += itemSize -
sizeof(int64) + (uint32)size;
1498 while (src < srcEnd) {
1507 if (this->data->
size + itemSize + size < maxDraftSize) {
1511 else if (this->data->
size + itemSize +
sizeof(int64) < maxDraftSize) {
1516 this->data->
userSize += itemSize + (uint32)size;
1551 const char* oldData = (
const char*)this->data;
1609 return (*(uint64*)src != 0);
1613 return (*(int64*)src != 0);
1615 return (((int64)(*(float64*)src)) != 0);
1632 if (
stricmp(key,
"size") == 0)
1634 else if (
stricmp(key,
"cid") == 0)
1636 else if (
stricmp(key,
"memid") == 0)
1638 else if (
stricmp(key,
"time") == 0)
1640 else if (
stricmp(key,
"sendtime") == 0)
1642 else if (
stricmp(key,
"recvtime") == 0)
1644 else if (
stricmp(key,
"timetext") == 0)
1646 else if (
stricmp(key,
"sendtimetext") == 0)
1648 else if (
stricmp(key,
"recvtimetext") == 0)
1650 else if (
stricmp(key,
"origin") == 0)
1652 else if (
stricmp(key,
"destination") == 0)
1654 else if (
stricmp(key,
"ttl") == 0)
1656 else if (
stricmp(key,
"eol") == 0)
1658 else if (
stricmp(key,
"eoltext") == 0)
1660 else if (
stricmp(key,
"priority") == 0)
1662 else if (
stricmp(key,
"policy") == 0)
1664 else if (
stricmp(key,
"from") == 0)
1666 else if (
stricmp(key,
"to") == 0)
1668 else if (
stricmp(key,
"type") == 0)
1669 return data->type.toString();
1670 else if (
stricmp(key,
"tag") == 0)
1672 else if (
stricmp(key,
"status") == 0)
1674 else if (
stricmp(key,
"reference") == 0)
1676 else if (
stricmp(key,
"serial") == 0)
1678 else if (
stricmp(key,
"contextchange") == 0)
1679 return data->contextchange.isValid() ?
data->contextchange.toString() :
"";
1680 else if (
stricmp(key,
"userSize") == 0)
1682 else if (
stricmp(key,
"userCount") == 0)
1713 bool success =
false;
1718 bool success =
false;
1723 bool success =
false;
1728 bool success =
false;
1729 value =
getInt(key, success);
1734 bool success =
false;
1740 bool success =
false;
1746 bool success =
false;
1747 return getData(key, size, success);
1751 bool success =
false;
1756 bool success =
false;
1798 if (src == NULL)
return 0;
1804 if (src == NULL)
return 0;
1812 if (src == NULL)
return 0;
1825 if (src == NULL)
return 0;
1835 bool success =
false;
1836 return getInt(key, success);
1842 if (src == NULL)
return false;
1854 if (src == NULL)
return false;
1864 bool success =
false;
1869 bool success =
false;
1876 if (src == NULL)
return NULL;
1890 if (src == NULL)
return NULL;
1895 char*
data =
new char[size];
1906 if (src == NULL)
return NULL;
1942 float64 val = value;
1988 data->size = oldSize + fullSpaceReq;
1991 src = (
char*)
data + oldSize;
2003 data->userSize += fullSpaceReq;
2021 char* srcEnd = (
char*)
data +
data->size;
2022 while (src < srcEnd) {
2039 char* srcEnd = (
char*)
data +
data->size;
2040 while (src < srcEnd) {
2058 char* srcEnd = (
char*)
data +
data->size;
2059 while (src < srcEnd) {
2072 delete[] arrayKeyStart;
2073 delete[] mapKeyStart;
2086 if (src == NULL)
return 0;
2092 if (src == NULL)
return 0;
2098 if (src == NULL)
return 0;
2104 if (src == NULL)
return 0;
2110 if (src == NULL)
return 0;
2116 if (src == NULL)
return 0;
2127 int n = snprintf(buf,
sizeof(buf),
"%s_-|%lld|-_", key, i);
2128 if (n < 0 || (
size_t)n >=
sizeof(buf))
2179 return getInt(i, key, success);
2194 return getInt(idx, key, success);
2204 return getFloat(idx, key, success);
2253 int n = snprintf(buf,
sizeof(buf),
"%s_-[%s]-_", key, idx);
2254 if (n < 0 || (
size_t)n >=
sizeof(buf))
2352 std::map<int64, uint64> map;
2359 char* srcEnd = (
char*)
data +
data->size;
2360 while (src < srcEnd) {
2378 std::map<int64, int64> map;
2385 char* srcEnd = (
char*)
data +
data->size;
2386 while (src < srcEnd) {
2425 std::map<int64, float64> map;
2432 char* srcEnd = (
char*)
data +
data->size;
2433 while (src < srcEnd) {
2472 std::map<int64, std::string> map;
2479 char* srcEnd = (
char*)
data +
data->size;
2480 while (src < srcEnd) {
2519 std::map<int64, std::string> map;
2526 char* srcEnd = (
char*)
data +
data->size;
2527 while (src < srcEnd) {
2546 std::map<int64, int64> map;
2553 char* srcEnd = (
char*)
data +
data->size;
2554 while (src < srcEnd) {
2572 std::map<int64, double> map;
2579 char* srcEnd = (
char*)
data +
data->size;
2580 while (src < srcEnd) {
2598 std::map<int64, float64> map;
2605 char* srcEnd = (
char*)
data +
data->size;
2606 while (src < srcEnd) {
2624 std::map<int64, DataMessage*> map;
2631 char* srcEnd = (
char*)
data +
data->size;
2632 while (src < srcEnd) {
2650 std::map<int64, uint64>::iterator i = map.begin(), e = map.end();
2652 if (!
setTime(i->first, key, i->second))
2660 std::map<int64, std::string>::iterator i = map.begin(), e = map.end();
2662 if (!
setString(i->first, key, i->second.c_str()))
2670 std::map<int64, int64>::iterator i = map.begin(), e = map.end();
2672 if (!
setInt(i->first, key, i->second))
2680 std::map<int64, double>::iterator i = map.begin(), e = map.end();
2682 if (!
setDouble(i->first, key, i->second))
2690 std::map<int64, float64>::iterator i = map.begin(), e = map.end();
2692 if (!
setFloat(i->first, key, i->second))
2700 std::map<int64, DataMessage*>::iterator i = map.begin(), e = map.end();
2723 char* srcEnd = (
char*)
data +
data->size;
2724 while (src < srcEnd) {
2749 char* srcEnd = (
char*)
data +
data->size;
2750 while (src < srcEnd) {
2775 std::map<std::string, uint64> map;
2782 char* srcEnd = (
char*)
data +
data->size;
2783 while (src < srcEnd) {
2800 std::map<std::string, int64> map;
2807 char* srcEnd = (
char*)
data +
data->size;
2808 while (src < srcEnd) {
2844 std::map<std::string, float64> map;
2851 char* srcEnd = (
char*)
data +
data->size;
2852 while (src < srcEnd) {
2888 std::map<std::string, std::string> map;
2895 char* srcEnd = (
char*)
data +
data->size;
2896 while (src < srcEnd) {
2932 std::map<std::string, std::string> map;
2939 char* srcEnd = (
char*)
data +
data->size;
2940 while (src < srcEnd) {
2957 std::map<std::string, int64> map;
2964 char* srcEnd = (
char*)
data +
data->size;
2965 while (src < srcEnd) {
2982 std::map<std::string, double> map;
2989 char* srcEnd = (
char*)
data +
data->size;
2990 while (src < srcEnd) {
3007 std::map<std::string, float64> map;
3014 char* srcEnd = (
char*)
data +
data->size;
3015 while (src < srcEnd) {
3032 std::map<std::string, DataMessage*> map;
3039 char* srcEnd = (
char*)
data +
data->size;
3040 while (src < srcEnd) {
3057 std::map<std::string, uint64>::iterator i = map.begin(), e = map.end();
3059 if (!
setTime(i->first.c_str(), key, i->second))
3067 std::map<std::string, std::string>::iterator i = map.begin(), e = map.end();
3069 if (!
setString(i->first.c_str(), key, i->second.c_str()))
3077 std::map<std::string, int64>::iterator i = map.begin(), e = map.end();
3079 if (!
setInt(i->first.c_str(), key, i->second))
3087 std::map<std::string, double>::iterator i = map.begin(), e = map.end();
3089 if (!
setDouble(i->first.c_str(), key, i->second))
3097 std::map<std::string, float64>::iterator i = map.begin(), e = map.end();
3099 if (!
setFloat(i->first.c_str(), key, i->second))
3107 std::map<std::string, DataMessage*>::iterator i = map.begin(), e = map.end();
3118 uint64 bestCandidateDiff = 0, diff;
3120 std::map<uint64, DataMessage*>::reverse_iterator i = messages.rbegin(), e = messages.rend();
3122 if (!bestCandidate) {
3123 bestCandidate = i->second;
3124 bestCandidateDiff = (i->first > t) ? i->first - t : t - i->first;
3127 diff = (i->first > t) ? i->first - t : t - i->first;
3128 if (diff < bestCandidateDiff) {
3129 bestCandidate = i->second;
3130 bestCandidateDiff = diff;
3135 return bestCandidate;
3141 data->chaincputime = chainCPUTime + cycleCPUTime;
3142 data->chainwalltime = chainWallTime + cycleWallTime;
3143 data->chaincount = chainCount;
3145 data->cyclecputime = cycleCPUTime;
3146 data->cyclewalltime = cycleWallTime;
3153 if (!
data)
return false;
3169 *newData =
new char[newSize];
3171 memset(*newData, 0, newSize);
3205 *newData =
new char[header->
size];
3206 memcpy(*newData,
data, header->
size);
3209 switch (header->
cver) {
3211 *newData =
new char[header->
size];
3212 memcpy(*newData,
data, header->
size);
3229 unittest::fail(
"DataMessage test: default constructor invalid\n");
3239 unittest::fail(
"DataMessage test: DataMessage(type, from) invalid\n");
3245 unittest::fail(
"DataMessage test: DataMessage(type, from, to, ttl, priority) invalid\n");
3254 const uint64 t = 1234567890ULL;
3257 if (!msg.
setInt(
"I", -42)) {
unittest::fail(
"DataMessage test: setInt failed\n");
return false; }
3260 const char bin[] = {
'x',
'y',
'z' };
3261 if (!msg.
setData(
"B", bin, 3)) {
unittest::fail(
"DataMessage test: setData failed\n");
return false; }
3263 if (msg.
getTime(
"T") != t) {
unittest::fail(
"DataMessage test: getTime mismatch\n");
return false; }
3265 if (!s || strcmp(s,
"hello") != 0) {
unittest::fail(
"DataMessage test: getString mismatch\n");
return false; }
3267 if (!msg.
getInt(
"I", i) || i != -42) {
unittest::fail(
"DataMessage test: getInt mismatch\n");
return false; }
3269 if (!msg.
getDouble(
"D", d) || d < 3.13 || d > 3.15) {
unittest::fail(
"DataMessage test: getDouble mismatch\n");
return false; }
3271 if (!msg.
getFloat(
"F", f) || f < 2.4f || f > 2.6f) {
unittest::fail(
"DataMessage test: getFloat mismatch\n");
return false; }
3273 const char* b = msg.
getData(
"B", bsize);
3274 if (!b || bsize != 3 || b[0] !=
'x' || b[1] !=
'y' || b[2] !=
'z') {
3275 unittest::fail(
"DataMessage test: getData mismatch\n");
return false;
3284 unittest::fail(
"DataMessage test: hasKey/hasString etc failed\n");
return false;
3287 unittest::fail(
"DataMessage test: getKeyType/isSingleValue failed\n");
return false;
3295 if (!cpy || csize != 3) {
unittest::fail(
"DataMessage test: getDataCopy failed\n");
return false; }
3303 if (!got || got->
getUserCount() == 0) {
unittest::fail(
"DataMessage test: getAttachedMessageCopy failed\n");
delete got;
return false; }
3304 if (got->
getAsString(
"nested") !=
"value") {
unittest::fail(
"DataMessage test: attached message content mismatch\n");
delete got;
return false; }
3315 if (!msg.
setTime(
static_cast<int64
>(0),
"arr", 100ULL)) {
unittest::fail(
"DataMessage test: setTime array failed\n");
return false; }
3316 if (!msg.
setString(1,
"arr",
"one")) {
unittest::fail(
"DataMessage test: setString array failed\n");
return false; }
3317 if (!msg.
setInt(2,
"arr", 999)) {
unittest::fail(
"DataMessage test: setInt array failed\n");
return false; }
3318 if (msg.
getTime(
static_cast<int64
>(0),
"arr") != 100ULL) {
unittest::fail(
"DataMessage test: getTime array mismatch\n");
return false; }
3319 if (msg.
getAsString(1,
"arr") !=
"one") {
unittest::fail(
"DataMessage test: getAsString array mismatch\n");
return false; }
3321 if (!msg.
getInt(2,
"arr", vi) || vi != 999) {
unittest::fail(
"DataMessage test: getInt array mismatch\n");
return false; }
3323 unittest::fail(
"DataMessage test: array key type failed\n");
return false;
3327 unittest::fail(
"DataMessage test: getArraySize failed\n");
return false;
3330 std::map<int64, uint64> tmap; tmap[0] = 10; tmap[1] = 20;
3332 std::map<int64, std::string> smap; smap[0] =
"a"; smap[1] =
"b";
3334 std::map<int64, int64> imap; imap[0] = 1; imap[1] = 2;
3336 std::map<int64, double> dmap; dmap[0] = 1.1; dmap[1] = 2.2;
3338 std::map<int64, uint64> gotT = msg.
getTimeArray(
"tarr");
3339 if (gotT.size() != 2 || gotT[0] != 10 || gotT[1] != 20) {
unittest::fail(
"DataMessage test: getTimeArray mismatch\n");
return false; }
3341 if (gotS.size() != 2 || gotS[0] !=
"a" || gotS[1] !=
"b") {
unittest::fail(
"DataMessage test: getAsStringArray mismatch\n");
return false; }
3342 std::map<int64, int64> gotI = msg.
getIntArray(
"iarr");
3343 if (gotI.size() != 2 || gotI[0] != 1 || gotI[1] != 2) {
unittest::fail(
"DataMessage test: getIntArray mismatch\n");
return false; }
3345 if (gotD.size() != 2 || gotD[0] < 1.0 || gotD[0] > 1.2 || gotD[1] < 2.1 || gotD[1] > 2.3) {
unittest::fail(
"DataMessage test: getDoubleArray mismatch\n");
return false; }
3352 if (!msg.
setTime(
"x",
"m", 200ULL)) {
unittest::fail(
"DataMessage test: setTime map failed\n");
return false; }
3353 if (!msg.
setString(
"y",
"m",
"mapval")) {
unittest::fail(
"DataMessage test: setString map failed\n");
return false; }
3354 if (!msg.
setInt(
"z",
"m", -7)) {
unittest::fail(
"DataMessage test: setInt map failed\n");
return false; }
3355 if (msg.
getTime(
"x",
"m") != 200ULL) {
unittest::fail(
"DataMessage test: getTime map mismatch\n");
return false; }
3356 if (msg.
getAsString(
"y",
"m") !=
"mapval") {
unittest::fail(
"DataMessage test: getAsString map mismatch\n");
return false; }
3358 if (!msg.
getInt(
"z",
"m", vi) || vi != -7) {
unittest::fail(
"DataMessage test: getInt map mismatch\n");
return false; }
3360 unittest::fail(
"DataMessage test: map key type failed\n");
return false;
3364 unittest::fail(
"DataMessage test: getMapSize failed\n");
return false;
3367 std::map<std::string, uint64> tmap; tmap[
"a"] = 1; tmap[
"b"] = 2;
3369 std::map<std::string, std::string> smap; smap[
"k1"] =
"v1"; smap[
"k2"] =
"v2";
3371 std::map<std::string, int64> imap; imap[
"i1"] = 10; imap[
"i2"] = 20;
3373 std::map<std::string, uint64> gotT = msg.
getTimeMap(
"tm");
3374 if (gotT.size() != 2 || gotT[
"a"] != 1 || gotT[
"b"] != 2) {
unittest::fail(
"DataMessage test: getTimeMap mismatch\n");
return false; }
3375 std::map<std::string, std::string> gotS = msg.
getAsStringMap(
"sm");
3376 if (gotS.size() != 2 || gotS[
"k1"] !=
"v1" || gotS[
"k2"] !=
"v2") {
unittest::fail(
"DataMessage test: getAsStringMap mismatch\n");
return false; }
3377 std::map<std::string, int64> gotI = msg.
getIntMap(
"im");
3378 if (gotI.size() != 2 || gotI[
"i1"] != 10 || gotI[
"i2"] != 20) {
unittest::fail(
"DataMessage test: getIntMap mismatch\n");
return false; }
3388 std::map<int64, std::string> amap; amap[0] =
"elem0";
3390 std::map<std::string, int64> mmap; mmap[
"idx"] = 42;
3394 if (!raw || sz == 0) {
unittest::fail(
"DataMessage test: getRawData/getSize failed\n");
return false; }
3396 if (!decoded.
isValid()) {
unittest::fail(
"DataMessage test: decoded message invalid\n");
return false; }
3398 unittest::fail(
"DataMessage test: round-trip getUserCount mismatch\n");
return false;
3400 if (decoded.
getAsString(
"k") !=
"roundtrip") {
unittest::fail(
"DataMessage test: round-trip string mismatch\n");
return false; }
3402 if (!decoded.
getInt(
"n", nval) || nval != 77) {
unittest::fail(
"DataMessage test: round-trip int mismatch\n");
return false; }
3404 if (!decoded.
getDouble(
"x", xval) || xval < 1.4 || xval > 1.6) {
unittest::fail(
"DataMessage test: round-trip double mismatch\n");
return false; }
3406 if (decoded.
getIntMap(
"m")[
"idx"] != 42) {
unittest::fail(
"DataMessage test: round-trip map mismatch\n");
return false; }
3415 if (ustr.empty()) {
unittest::fail(
"DataMessage test: getUserEntriesAsString empty\n");
return false; }
3417 if (ujson.empty()) {
unittest::fail(
"DataMessage test: getUserEntriesAsJSON empty\n");
return false; }
3419 std::string json = msg.
toJSON();
3420 if (json.empty()) {
unittest::fail(
"DataMessage test: toJSON empty\n");
return false; }
3421 std::string xml = msg.
toXML();
3422 if (xml.empty()) {
unittest::fail(
"DataMessage test: toXML empty\n");
return false; }
3423 std::string csv = msg.
toCSV();
3424 if (csv.empty()) {
unittest::fail(
"DataMessage test: toCSV empty\n");
return false; }
3426 if (hdr.empty()) {
unittest::fail(
"DataMessage test: GetCSVHeader empty\n");
return false; }
3437 unittest::fail(
"DataMessage test: copyUserEntriesFromMessage count\n");
return false;
3440 unittest::fail(
"DataMessage test: copyUserEntriesFromMessage content\n");
return false;
3444 if (dst.
hasKey(
"a")) {
unittest::fail(
"DataMessage test: removeEntry key still present\n");
return false; }
3452 if (msg.
hasKey(
"nonexistent")) {
unittest::fail(
"DataMessage test: hasKey nonexistent true\n");
return false; }
3453 if (msg.
getString(
"nonexistent") != NULL) {
unittest::fail(
"DataMessage test: getString nonexistent non-NULL\n");
return false; }
3454 if (msg.
getTime(
"nonexistent") != 0) {
unittest::fail(
"DataMessage test: getTime nonexistent non-zero\n");
return false; }
3467 "Data message encode/decode, arrays, maps, serialisation",
"core");
The binary DataMessage container — the central data-exchange object of Psyclone/CMSDK.
#define CURRENTDATAMESSAGEVERSION
#define DATAMESSAGEINFOID
#define GetObjID(data)
Extract the cid field from a binary object block: the uint32 at byte offset 4 (after the leading size...
#define DATAMESSAGEDRAFTID
CMSDK time: µs-resolution 64-bit timestamps and the Time Mapping Constant (TMC).
Small, dependency-free unit test harness used by all CMSDK object tests.
bool setTime(const char *key, uint64 value)
setTime(const char* key, uint64 value)
std::map< int64, float64 > getAsFloatArray(const char *key)
getAsFloatArray(const char* key)
bool setFloatArray(const char *key, std::map< int64, float64 > &map)
setFloatArray(const char* key, std::map<int64, float64>& map) Sets the whole float array named key in...
static bool UnitTest()
Run the built-in self test for the DataMessage implementation.
DataMessage()
DataMessage() Creates an empty DataMessage.
bool getDouble(const char *key, double &value)
getDouble(const char* key, double& value)
~DataMessage()
~DataMessage() Message destructor
std::string toXML(std::map< uint16, std::string > *subtypes=NULL, std::map< uint16, std::string > *subcontexts=NULL, std::map< uint32, std::string > *compNames=NULL)
toXML()
static DataMessage * FindClosestMessage(uint64 t, std::map< uint64, DataMessage * > &messages)
FindClosestMessage(uint64 t, std::map<uint64, DataMessage*> &messages) In a map of time -> DataMessag...
bool setFloat(const char *key, float64 value)
setFloat(const char* key, float64 value)
std::map< int64, int64 > getIntArray(const char *key)
getIntArray(const char* key)
bool addTimeUsage(uint32 cycleCPUTime, uint32 cycleWallTime, uint32 chainCPUTime=0, uint32 chainWallTime=0, uint32 chainCount=0)
addTimeUsage()
std::map< std::string, double > getDoubleMap(const char *key)
returns the user double entry with this key
bool setString(const char *key, const char *value)
setString(const char* key, const char* value)
bool getInt(const char *key, int64 &value)
getInt(const char* key, int64& value)
bool setInt(const char *key, int64 value)
setInt(const char* key, int64 value)
bool isSingleValue(const char *key)
isSingleValue(const char* key)
bool hasData(const char *key)
Check if key variable exists and is a data entry.
uint32 getMapCount(const char *key)
getMapCount(const char* key) Returns the number of elements in map with name '<key>'
std::map< std::string, uint64 > getTimeMap(const char *key)
returns the user time entry with this key
std::map< std::string, int64 > getIntMap(const char *key)
returns the user integer entry with this key
uint32 getArraySize(const char *key)
getArraySize(const char* key) Returns the number of elements in array with name '<key>'
char * getDataCopy(const char *key, uint32 &size)
getDataCopy(const char* key, uint32& size)
bool setDoubleMap(const char *key, std::map< std::string, double > &map)
sets the user double entry with this key to the value provided
std::string getAsString(const char *key)
getAsString(const char* key)
DataMessageHeader * data
Pointer to the message's flat memory block (header + user entries).
std::string toJSON(std::map< uint16, std::string > *subtypes=NULL, std::map< uint16, std::string > *subcontexts=NULL, std::map< uint32, std::string > *compNames=NULL)
toJSON()
std::map< int64, float64 > getFloatArray(const char *key)
getFloatArray(const char* key)
std::string toCSV(const char *separator=NULL, const char *preample=NULL, std::map< uint16, std::string > *subtypes=NULL, std::map< uint16, std::string > *subcontexts=NULL, std::map< uint32, std::string > *compNames=NULL)
toCSV()
bool hasFloat(const char *key)
Check if key variable exists and is a float.
bool setIntMap(const char *key, std::map< std::string, int64 > &map)
sets the user integer entry with this key
char * findEntry(const char *key)
findEntry(const char* key)
const char * getData(const char *key, uint32 &size)
getData(const char* key, uint32& size)
bool getAsBool(const char *key)
getAsBool(const char* key)
uint32 getUserCount()
getUserCount()
uint32 getSize()
getSize() Get message size Many types of data of any size can be put into a message as user entries; ...
static bool ConvertDataFromOlderMessageFormat(const char *data, char **newData)
Convert a binary block in the legacy (pre-version-10, DATAMESSAGEOLDID) format to the current DataMes...
uint32 copyUserEntriesFromMessage(DataMessage *msg)
copyUserEntriesFromMessage(DataMessage* msg) Copies all user data from a message into this message,...
std::string getUserEntriesAsJSON(bool asText)
getUserEntriesAsJSON(bool asText) Returns the JSON representation of the full message including all u...
bool setAttachedMessage(const char *key, DataMessage *msg)
setAttachedMessage(const char* key, DataMessage* msg)
bool setTimeArray(const char *key, std::map< int64, uint64 > &map)
setTimeArray(const char* key, std::map<int64, uint64>& map) Sets the whole time array named key in on...
std::map< std::string, std::string > getStringMap(const char *key)
returns the user string entry with this key
std::map< int64, std::string > getStringArray(const char *key)
getStringArray(const char* key)
bool setAttachedMessageArray(const char *key, std::map< int64, DataMessage * > &map)
setAttachedMessageArray(const char* key, std::map<int64, DataMessage*>& map) Sets the whole array of ...
bool removeEntry(const char *key)
removeEntry(const char* key)
bool hasTime(const char *key)
Check if key variable exists and is a time.
std::map< int64, std::string > getAsStringArray(const char *key)
getAsStringArray(const char* key)
bool setIntArray(const char *key, std::map< int64, int64 > &map)
setIntArray(const char* key, std::map<int64, int64>& map) Sets the whole integer array named key in o...
std::map< std::string, DataMessage * > getAttachedMessageMap(const char *key)
returns a copy of the user message entry with this key
bool setTimeMap(const char *key, std::map< std::string, uint64 > &map)
sets the user time entry with this key
uint32 getContentSize(const char *key)
getContentSize(const char* key)
void invalidateFindKeyCache()
Internal: clears the single-entry key-lookup cache.
uint32 getArrayCount(const char *key)
getArrayCount(const char* key) Returns the number of elements in array with name '<key>'
std::map< std::string, int64 > getAsIntMap(const char *key)
returns the user entry as an integer map regardless of what type it is
bool setFloatMap(const char *key, std::map< std::string, float64 > &map)
sets the user float entry with this key to the value provided
uint64 getAsTime(const char *key)
getAsTime(const char* key)
bool isMapContent(const char *key)
isMapContent(const char* key)
bool hasKey(const char *key)
Check if key variable exists.
uint64 getTime(const char *key)
getTime(const char* key)
bool getFloat(const char *key, float64 &value)
getFloat(const char* key, float64& value)
bool setRawData(const char *key, const char *value, uint32 size, uint32 datatype)
Internal: low-level entry writer used by all typed set...() overloads.
bool setDouble(const char *key, double value)
setDouble(const char* key, double value)
std::map< std::string, std::string > getAsStringMap(const char *key)
returns the user entry as a string regardless of what type it is
int64 getAsInt(const char *key)
getAsInt(const char* key)
bool setDoubleArray(const char *key, std::map< int64, double > &map)
setDoubleArray(const char* key, std::map<int64, double>& map) Sets the whole double array named key i...
bool setStringMap(const char *key, std::map< std::string, std::string > &map)
sets the user string entry with this key
bool isArrayContent(const char *key)
isArrayContent(const char* key)
DataMessage * getAttachedMessageCopy(const char *key)
getAttachedMessageCopy(const char* key)
bool isValid()
isValid() Checks that the message memory block exists and carries the current-format object id (DATAM...
bool hasMessage(const char *key)
Check if key variable exists and is a message.
char * getRawData()
getRawData() Retrieve a pointer to the raw binary block of the message (header + entries).
const char * swapMessageData(const char *data)
swapMessageData(const char* data)
std::map< int64, uint64 > getTimeArray(const char *key)
uint32 getMapSize(const char *key)
getMapSize(const char* key) Returns the number of elements in map with name '<key>'
std::map< int64, double > getDoubleArray(const char *key)
getDoubleArray(const char* key)
bool setData(const char *key, const char *value, uint32 size)
setData(const char* key, const char* value, uint32 size)
bool hasString(const char *key)
Check if key variable exists and is a string.
std::map< int64, DataMessage * > getAttachedMessageArray(const char *key)
getAttachedMessageArray(const char* key)
const char * getString(const char *key)
getString(const char* key)
char * findSpace(uint32 space)
findSpace(uint32 space)
static std::string GetCSVHeader(const char *separator=NULL, const char *preample=NULL)
toCSVHeader()
bool fillInDraftUserDataFrom(const char *data, uint32 maxDraftSize)
fillInDraftUserDataFrom(const char* data, uint32 maxDraftSize)
KeyType getKeyType(const char *key)
getKeyType(const char* key)
uint32 getContentType(const char *key)
getContentType(const char* key)
bool setStringArray(const char *key, std::map< int64, std::string > &map)
setStringArray(const char* key, std::map<int64, std::string>& map) Sets the whole string array named ...
DataMessage * copy()
copy() Creates a full deep copy of the message and returns it.
bool hasInteger(const char *key)
Check if key variable exists and is an integer.
std::map< int64, int64 > getAsIntArray(const char *key)
getAsIntArray(const char* key)
bool setAttachedMessageMap(const char *key, std::map< std::string, DataMessage * > &map)
sets the user message entry with this key to the provided message
std::string getUserEntriesAsString()
getUserEntriesAsString() Returns the textual representation of the full message including all user en...
float64 getAsFloat(const char *key)
getAsFloat(const char* key)
std::map< std::string, float64 > getFloatMap(const char *key)
returns the user float entry with this key
std::map< std::string, float64 > getAsFloatMap(const char *key)
returns the user entry as a float map regardless of what type it is
static UnitTestRunner & instance()
Access the singleton (created on first use).
void registerTest(const char *name, UnitTestFunc func, const char *description="", const char *category="", bool inDefaultRun=true)
Register a test with the runner.
std::string PrintTimeString(uint64 t, bool local=true, bool us=true, bool ms=true)
uint64 GetTimeNow()
Return the current absolute time (µs since year 0) according to the TMC.
bool TextStartsWith(const char *str, const char *start, bool caseSensitive=true)
Test whether str starts with start.
bool TextEndsWith(const char *str, const char *end, bool caseSensitive=true)
Test whether str ends with end.
uint32 strcpyavail(char *dst, const char *src, uint32 maxlen, bool copyAvailable)
Bounded strcpy that always NUL-terminates.
void fail(const char *fmt,...)
Set an explanatory reason shown on the FAIL line.
void progress(int percent, const char *action)
Report progress with a short description of the current action.
std::string TextIndent(const char *text, const char *indent)
Prefix every line of text with indent.
uint32 StringSingleReplace(std::string &text, std::string key, std::string value, bool onlyFirst)
Replace occurrences of key with value in text.
std::string StringFormat(const char *format,...)
printf into a std::string.
uint64 Ascii2Uint64(const char *ascii, uint32 start=0, uint32 end=0)
Parse an unsigned 64-bit decimal integer from a substring.
int64 Ascii2Int64(const char *ascii, uint32 start=0, uint32 end=0)
Parse a signed 64-bit decimal integer from a substring.
float64 Ascii2Float64(const char *ascii, uint32 start=0, uint32 end=0)
Parse a 64-bit float from a substring (decimal point, not locale dependent).
void Register_DataMessage_Tests()
static struct PsyType CTRL_TEST
Hierarchical message type identifier — the key used for publish/subscribe matching in Psyclone.