34 std::list<GenericObservation<T>*> list;
38 while ((
data = msg->
getData(n,
"OBS", size)) && size && (size ==
sizeof(
ObsHeader) +
sizeof(T))) {
104 if (!msg || (!
header.id && !
id))
return false;
108 if (msg->
getData(
id,
"OBS", s))
113 char* buffer =
new char[
header.size];
132 if (!cdata || (size != (
sizeof(
ObsHeader) +
sizeof(T))))
145 if (!msg || !
id)
return false;
147 const char* cdata = msg->
getData(
id,
"OBS", s);
172 if (!
data.extractDataFromMessage(msg, mappings))
195 std::string json =
data.toJSON();
197 return utils::StringFormat(
"{ \"datatype\": \"%s\", \"name\": \"%s\", \"id\": %llu, \"timestamp\": %llu, \"timetext\": \"%s\", \"objectid\": %llu, \"systemid\": %llu, \"topicid\": %llu, \"confidence\": %.3f, \"consensus\": %.3f, %s}\n",
198 data.getTypeName().c_str(),
header.name,
header.id,
header.timestamp,
PrintTimeString(
header.timestamp).c_str(),
header.objectID,
header.creatorID,
header.topicID,
header.confidence,
header.consensus, json.c_str());
200 return utils::StringFormat(
"{ \"datatype\": \"%s\", \"name\": \"%s\", \"id\": %llu, \"timestamp\": %llu, \"timetext\": \"%s\", \"objectid\": %llu, \"systemid\": %llu, \"topicid\": %llu, \"confidence\": %.3f, \"consensus\": %.3f, \"datatype\": \"unknown\"}\n",
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.
uint32 getSystemID()
getSystemID() Get and return message system id
bool getInt(const char *key, int64 &value)
getInt(const char* key, int64& value)
const char * getData(const char *key, uint32 &size)
getData(const char* key, uint32& size)
bool getFloat(const char *key, float64 &value)
getFloat(const char* key, float64& value)
uint64 getCreatedTime()
getCreatedTime()
bool setData(const char *key, const char *value, uint32 size)
setData(const char* key, const char* value, uint32 size)
std::string toJSON()
JSON object rendering.
bool extractDataFromMessage(DataMessage *msg, std::map< std::string, std::string > &mappings)
Populate the payload from a message using logical→actual field mappings.
static bool WriteAllToMessage(DataMessage *msg, std::list< GenericObservation< T > * > &list)
Serialize all observations in list into msg.
ObsHeader header
Identity/provenance/confidence header.
bool readFromMessage(DataMessage *msg, uint64 id=0)
Read the observation with id id (0 = first) from msg.
std::string print()
One-line human-readable rendering (header + payload).
static std::list< GenericObservation< T > * > ReadAllFromMessage(DataMessage *msg)
Deserialize every observation of type T carried by msg.
bool writeToMessage(DataMessage *msg, uint64 id)
Append this observation to msg under entry id id.
bool readFromData(const char *data, uint32 size, uint64 id=0)
Parse from a raw blob.
GenericObservation()
Empty observation (zeroed header and payload).
bool isBetween(GenericObservation< T > *a, GenericObservation< T > *b)
Range test delegated to the payload's isBetween(); see per-type notes on semantics.
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.
std::string StringFormat(const char *format,...)
printf into a std::string.