98#if !defined(_DATAMESSAGE_H_)
99#define _DATAMESSAGE_H_
109#define CURRENTDATAMESSAGEVERSION 10
111#define DATAMESSAGE_CENC_PACKED 0x0100
232 std::string
toJSON(std::map<uint16, std::string>* subtypes = NULL, std::map<uint16, std::string>* subcontexts = NULL, std::map<uint32, std::string>* compNames = NULL);
238 std::string
toXML(std::map<uint16, std::string>* subtypes = NULL, std::map<uint16, std::string>* subcontexts = NULL, std::map<uint32, std::string>* compNames = NULL);
319 DataMessage(
PsyType type, uint32 from, uint32 to, uint64 ttl = 0, uint16 priority = 0);
330 DataMessage(
PsyType type, uint32 from, uint32 to, uint32 tag, uint64 time, uint64 ttl = 0, uint16 priority = 0);
521 uint64
getTime(
const char* key);
540 const char*
getString(
const char* key, uint32 &size);
550 bool getInt(
const char* key, int64& value);
561 bool getDouble(
const char* key,
double& value);
572 bool getFloat(
const char* key, float64& value);
582 const char*
getData(
const char* key, uint32& size);
616 uint64
getTime(
const char* key,
bool& success);
627 const char*
getString(
const char* key,
bool& success);
638 const char*
getString(
const char* key, uint32 &size,
bool& success);
650 int64
getInt(
const char* key,
bool& success);
662 double getDouble(
const char* key,
bool& success);
673 float64
getFloat(
const char* key,
bool& success);
684 const char*
getData(
const char* key, uint32& size,
bool& success);
697 char*
getDataCopy(
const char* key, uint32& size,
bool& success);
720 int64
getInt(
const char* key);
758 bool setTime(
const char* key, uint64 value);
769 bool setString(
const char* key,
const char* value);
779 bool setInt(
const char* key, int64 value);
789 bool setDouble(
const char* key,
double value);
800 bool setFloat(
const char* key, float64 value);
812 bool setData(
const char* key,
const char* value, uint32 size);
832 return data->userSize;
841 return data->userCount;
900 bool hasKey(
const char* key);
973 uint64
getTime(int64 i,
const char* key);
987 int64
getAsInt(int64 i,
const char* key);
994 uint64
getAsTime(int64 i,
const char* key);
1001 float64
getAsFloat(int64 i,
const char* key);
1008 const char*
getString(int64 i,
const char* key);
1016 const char*
getString(int64 i,
const char* key, uint32 &size);
1024 bool getInt(int64 i,
const char* key, int64& value);
1032 bool getDouble(int64 i,
const char* key,
double& value);
1040 bool getFloat(int64 i,
const char* key, float64& value);
1048 int64
getInt(int64 i,
const char* key,
bool& success);
1055 double getDouble(int64 i,
const char* key,
bool& success);
1062 float64
getFloat(int64 i,
const char* key,
bool& success);
1069 int64
getInt(int64 i,
const char* key);
1075 double getDouble(int64 i,
const char* key);
1081 float64
getFloat(int64 i,
const char* key);
1089 const char*
getData(int64 i,
const char* key, uint32& size);
1097 char*
getDataCopy(int64 i,
const char* key, uint32& size);
1114 bool setTime(int64 i,
const char* key, uint64 value);
1122 bool setString(int64 i,
const char* key,
const char* value);
1130 bool setInt(int64 i,
const char* key, int64 value);
1138 bool setDouble(int64 i,
const char* key,
double value);
1146 bool setFloat(int64 i,
const char* key, float64 value);
1154 bool setData(int64 i,
const char* key,
const char* value, uint32 size);
1192 std::map<int64, int64>
getIntArray(
const char* key);
1243 bool setTimeArray(
const char* key, std::map<int64, uint64>& map);
1251 bool setStringArray(
const char* key, std::map<int64, std::string>& map);
1259 bool setIntArray(
const char* key, std::map<int64, int64>& map);
1267 bool setDoubleArray(
const char* key, std::map<int64, double>& map);
1275 bool setFloatArray(
const char* key, std::map<int64, float64>& map);
1319 uint64
getTime(
const char* idx,
const char* key);
1328 std::string
getAsString(
const char* idx,
const char* key);
1337 int64
getAsInt(
const char* idx,
const char* key);
1346 uint64
getAsTime(
const char* idx,
const char* key);
1355 float64
getAsFloat(
const char* idx,
const char* key);
1363 const char*
getString(
const char* idx,
const char* key);
1372 const char*
getString(
const char* idx,
const char* key, uint32 &size);
1382 bool getInt(
const char* idx,
const char* key, int64& value);
1392 bool getDouble(
const char* idx,
const char* key,
double& value);
1402 bool getFloat(
const char* idx,
const char* key, float64& value);
1410 int64
getInt(
const char* idx,
const char* key,
bool& success);
1419 double getDouble(
const char* idx,
const char* key,
bool& success);
1428 float64
getFloat(
const char* idx,
const char* key,
bool& success);
1436 int64
getInt(
const char* idx,
const char* key);
1445 double getDouble(
const char* idx,
const char* key);
1453 float64
getFloat(
const char* idx,
const char* key);
1462 const char*
getData(
const char* idx,
const char* key, uint32& size);
1472 char*
getDataCopy(
const char* idx,
const char* key, uint32& size);
1489 bool setTime(
const char* idx,
const char* key, uint64 value);
1498 bool setString(
const char* idx,
const char* key,
const char* value);
1507 bool setInt(
const char* idx,
const char* key, int64 value);
1517 bool setDouble(
const char* idx,
const char* key,
double value);
1527 bool setFloat(
const char* idx,
const char* key, float64 value);
1537 bool setData(
const char* idx,
const char* key,
const char* value, uint32 size);
1554 std::map<std::string, uint64>
getTimeMap(
const char* key);
1562 std::map<std::string, std::string>
getAsStringMap(
const char* key);
1570 std::map<std::string, int64>
getAsIntMap(
const char* key);
1578 std::map<std::string, float64>
getAsFloatMap(
const char* key);
1585 std::map<std::string, std::string>
getStringMap(
const char* key);
1592 std::map<std::string, int64>
getIntMap(
const char* key);
1600 std::map<std::string, double>
getDoubleMap(
const char* key);
1607 std::map<std::string, float64>
getFloatMap(
const char* key);
1622 bool setTimeMap(
const char* key, std::map<std::string, uint64>& map);
1630 bool setStringMap(
const char* key, std::map<std::string, std::string>& map);
1638 bool setIntMap(
const char* key, std::map<std::string, int64>& map);
1647 bool setDoubleMap(
const char* key, std::map<std::string, double>& map);
1656 bool setFloatMap(
const char* key, std::map<std::string, float64>& map);
1673 std::string
toJSON(std::map<uint16, std::string>* subtypes = NULL, std::map<uint16, std::string>* subcontexts = NULL, std::map<uint32, std::string>* compNames = NULL);
1680 std::string
toXML(std::map<uint16, std::string>* subtypes = NULL, std::map<uint16, std::string>* subcontexts = NULL, std::map<uint32, std::string>* compNames = NULL);
1692 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);
1701 static std::string
GetCSVHeader(
const char* separator = NULL,
const char* preample = NULL);
1744 return data->origin;
1753 return data->destination;
1763 data->origin = addr;
1774 data->destination = addr;
1799 bool setMultiple(uint32 from, uint32 to, uint32 tag, uint64 ttl, uint8 policy, uint64 sendtime) {
1801 if (from)
data->from = from;
1802 if (to)
data->to = to;
1803 if (tag)
data->tag = tag;
1804 if (ttl)
data->ttl = ttl;
1805 if (policy)
data->policy = policy;
1806 if (sendtime)
data->sendtime = sendtime;
1843 return data->reference;
1853 data->reference = ref;
1864 return data->systemid;
1874 data->systemid = id;
1997 return data->contextchange;
2015 data->contextchange = context;
2090 int64 ttl = eol -
data->time;
2092 data->ttl = (uint64)ttl;
2111 return data->priority;
2130 data->priority = priority;
2146 return data->policy;
2162 data->policy = policy;
2177 return data->sendtime;
2193 data->sendtime = time;
2208 return data->recvtime;
2224 data->recvtime = time;
2271 return data->status;
2287 data->status = status;
2301 return data->serial;
2317 data->serial = serial;
2344 bool addTimeUsage(uint32 cycleCPUTime, uint32 cycleWallTime, uint32 chainCPUTime = 0, uint32 chainWallTime = 0, uint32 chainCount = 0);
2358 return data->cyclecputime;
2374 data->cyclecputime = t;
2392 return data->cyclewalltime;
2408 data->cyclewalltime = t;
2427 return data->chaincputime;
2443 data->chaincputime = t;
2461 return data->chainwalltime;
2477 data->chainwalltime = t;
2494 return data->chaincount;
2510 data->chaincount= count;
2572 bool setRawData(
const char* key,
const char* value, uint32 size, uint32 datatype);
2587 char* srcEnd = (
char*)
data +
data->size;
2588 while (src < srcEnd) {
2614 if (src == NULL)
return NULL;
2634 if (src == NULL)
return true;
2657 char* srcEnd = (
char*)
data +
data->size;
2658 while (src < srcEnd) {
Object type ids used to tag and verify every binary structure in CMSDK memory.
#define GetObjID(data)
Extract the cid field from a binary object block: the uint32 at byte offset 4 (after the leading size...
Core fixed-width scalar typedefs and the PsyType / PsyContext hierarchical identifiers.
static struct PsyType NOTYPE
The empty/unset message type (isValid() == false).
static struct PsyContext NOCONTEXT
The empty/unset context (isValid() == false).
Cross-platform utility toolbox for CMSDK: threading, synchronization, shared memory,...
The central Psyclone data container: a self-contained binary message with typed, named user entries.
bool setOrigin(uint16 addr)
setOrigin(uint16 addr) Set origin to address addr and return new origin
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)
uint16 getOrigin()
getOrigin() Get the NodeID of the node the message originated on
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...
bool setChainCount(uint32 count)
setChainCount(uint32 count)
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()
bool setTTL(uint64 ttl)
setTTL(uint64 ttl)
bool deleteEntry(const char *key)
deleteEntry(const char* key)
uint32 getSystemID()
getSystemID() Get and return message system id
uint32 removeCollectionEntries(const char *key)
removeEntry(const char* key)
bool setEOL(uint64 eol)
setEOL(uint64 eol)
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 setPriority(uint16 priority)
setPriority(uint16 priority)
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 setMemID(uint64 id)
setMemID(uint64 id) Set memory ID to id
bool setChainWallTime(uint32 t)
setChainWallTime(uint32 t)
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
uint32 getFrom()
getFrom() Get the sender id
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
bool setChainCPUTime(uint32 t)
setChainCPUTime(uint32 t)
bool setTag(uint32 tag)
setTag(uint32 tag)
std::string _lastFindKey
Internal: last key looked up (single-entry lookup cache; mutable so const-style getters can update it...
uint16 getDestination()
getDestination() Get the NodeID of the destination node
bool setDestination(uint16 addr)
setDestination(uint16 addr) Set destination to address addr and return new destination
PsyContext getContextChange()
getContextChange()
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)
uint16 getCycleWallTime()
getCycleWallTime()
bool setDoubleMap(const char *key, std::map< std::string, double > &map)
sets the user double entry with this key to the value provided
static bool IsPacked(const char *data, uint32 size)
True if data (at least 8 bytes) starts a packed message.
std::string getAsString(const char *key)
getAsString(const char* key)
DataMessageHeader * data
Pointer to the message's flat memory block (header + user entries).
bool setStatus(uint16 status)
setStatus(uint16 status)
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()
PsyType getType()
getType()
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 * findKey(const char *key)
findKey(const char* key) Internal function: linear scan of the entry list for an entry whose key matc...
char * findEntry(const char *key)
findEntry(const char* key)
const char * getData(const char *key, uint32 &size)
getData(const char* key, uint32& size)
uint16 getChainCPUTime()
getChainCPUTime()
uint16 getStatus()
getStatus()
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; ...
uint64 getReference()
getReference() Get and return message reference id
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...
char * _lastFindKeyResult
Internal: cached location of the last key's entry inside the block; NULL if not found.
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...
bool setRecvTime(uint64 time)
setRecvTime(uint64 time)
std::map< std::string, std::string > getStringMap(const char *key)
returns the user string entry with this key
std::map< std::string, KeyType > getAllKeys()
getAllKeys()
char * toPacked(uint32 &size) const
Encode this message in the packed wire form.
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)
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...
bool setFrom(uint32 from)
setFrom(uint32 from)
std::map< std::string, DataMessage * > getAttachedMessageMap(const char *key)
returns a copy of the user message entry with this key
bool setTo(uint32 to)
setTo(uint32 to)
bool setTimeMap(const char *key, std::map< std::string, uint64 > &map)
sets the user time entry with this key
bool setCreatedTime(uint64 t)
setCreatedTime(uint64 t)
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>'
bool setReference(uint64 ref)
setReference(uint64 ref) Set message reference
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)
uint16 getPriority()
getPriority()
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 setSystemID(uint32 id)
setSystemID(uint32 id) Set message system id
bool setType(PsyType &type)
setType(PsyType &type)
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)
uint16 getChainWallTime()
getChainWallTime()
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)
uint64 getMemID()
getMemID() Get and return memory ID
bool isValid()
isValid() Checks that the message memory block exists and carries the current-format object id (DATAM...
uint64 getSerial()
getSerial()
bool setPolicy(uint8 policy)
setPolicy(uint8 policy)
uint8 getPolicy()
getPolicy()
uint64 getCreatedTime()
getCreatedTime()
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).
uint32 getTag()
getTag() Retrieve and return message tag id Tags can be used to segment data temporally,...
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 setSerial(uint64 serial)
setSerial(uint64 serial)
bool setCycleWallTime(uint32 t)
setCycleWallTime(uint32 t)
uint32 getChainCount()
getChainCount()
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 ...
uint64 getRecvTime()
getRecvTime()
uint16 getCycleCPUTime()
getCycleCPUTime()
uint64 getSendTime()
getSendTime()
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
bool setMultiple(uint32 from, uint32 to, uint32 tag, uint64 ttl, uint8 policy, uint64 sendtime)
setMultiple(uint32 from, uint32 to, uint32 tag, uint64 ttl, uint8 policy, uint64 sendtime) Set multip...
static DataMessage * FromPacked(const char *data, uint32 size)
Decode a packed message (as written by toPacked() or the Kotlin codec).
bool setContextChange(PsyContext &context)
setContextChange(PsyContext& context)
uint32 getUserSize()
getUserSize()
bool setSendTime(uint64 time)
setSendTime(uint64 time)
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
bool setCycleCPUTime(uint32 t)
setCycleCPUTime(uint32 t)
std::map< std::string, float64 > getAsFloatMap(const char *key)
returns the user entry as a float map regardless of what type it is
Hierarchical execution-context identifier.
Hierarchical message type identifier — the key used for publish/subscribe matching in Psyclone.