|
CMSDK 2.0.1
Cross-platform C++ base library and SDK for the Psyclone AIOS platform
|
Header + typed payload wrapper for one observation, serializable to/from DataMessage and raw memory. More...
#include <Observations.h>
Public Member Functions | |
| GenericObservation () | |
| Empty observation (zeroed header and payload). | |
| GenericObservation (const char *data, uint32 size, uint64 id=0) | |
Deserialize from a raw blob; id 0 means "first/any". | |
| ~GenericObservation () | |
| std::string | print () |
| One-line human-readable rendering (header + payload). | |
| 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. | |
| bool | writeToMessage (DataMessage *msg, uint64 id) |
Append this observation to msg under entry id id. | |
| bool | readFromMessage (DataMessage *msg, uint64 id=0) |
Read the observation with id id (0 = first) from msg. | |
| bool | readFromData (const char *data, uint32 size, uint64 id=0) |
| Parse from a raw blob. | |
| bool | isBetween (GenericObservation< T > *a, GenericObservation< T > *b) |
| Range test delegated to the payload's isBetween(); see per-type notes on semantics. | |
Static Public Member Functions | |
| static std::list< GenericObservation< T > * > | ReadAllFromMessage (DataMessage *msg) |
Deserialize every observation of type T carried by msg. | |
| static bool | WriteAllToMessage (DataMessage *msg, std::list< GenericObservation< T > * > &list) |
Serialize all observations in list into msg. | |
Public Attributes | |
| ObsHeader | header |
| Identity/provenance/confidence header. | |
| T | data |
| Typed payload. | |
Header + typed payload wrapper for one observation, serializable to/from DataMessage and raw memory.
| T | One of the Obs* payload structs (ObsLocation, ObsDimension, ObsInteger, ObsFloat, ObsTime, ObsString). Implementations are in Observations.tpl.h. |
Definition at line 348 of file Observations.h.
| cmlabs::GenericObservation< T >::GenericObservation | ( | ) |
Empty observation (zeroed header and payload).
Construct an empty observation: zeroed header stamped with the current time and the payload's type tag (data.getType()), then T::init() on the payload.
Definition at line 61 of file Observations.tpl.h.
References data, cmlabs::GetTimeNow(), header, and OBSERVATIONID.
Referenced by isBetween(), ReadAllFromMessage(), and WriteAllToMessage().
| cmlabs::GenericObservation< T >::GenericObservation | ( | const char * | cdata, |
| uint32 | size, | ||
| uint64 | id = 0 ) |
Deserialize from a raw blob; id 0 means "first/any".
Construct from a serialized blob (ObsHeader + T payload).
Falls back to the default-constructed state (fresh header, T::init()) when cdata is NULL, the size does not match, or the type tag differs; no error is reported.
| cdata | Serialized bytes (copied, not retained). |
| size | Byte count. |
| id | Optional id hint (currently unused by readFromData()). |
Definition at line 76 of file Observations.tpl.h.
References data, cmlabs::GetTimeNow(), header, OBSERVATIONID, and readFromData().
| cmlabs::GenericObservation< T >::~GenericObservation | ( | ) |
Definition at line 89 of file Observations.tpl.h.
| bool cmlabs::GenericObservation< T >::extractDataFromMessage | ( | DataMessage * | msg, |
| std::map< std::string, std::string > & | mappings ) |
Populate the payload from a message using logical→actual field mappings.
Populate payload and header fields from an arbitrary DataMessage.
First lets the payload pull its own fields via T::extractDataFromMessage() using the caller-supplied name mappings (message field name to observation field name); on success, fills the header from the message's well-known entries (SystemID, ObjectID, Confidence, Consensus, creation time).
Definition at line 171 of file Observations.tpl.h.
References data, cmlabs::DataMessage::getCreatedTime(), cmlabs::DataMessage::getFloat(), cmlabs::DataMessage::getInt(), cmlabs::DataMessage::getSystemID(), and header.
Referenced by cmlabs::Observations_UnitTest().
| bool cmlabs::GenericObservation< T >::isBetween | ( | GenericObservation< T > * | a, |
| GenericObservation< T > * | b ) |
Range test delegated to the payload's isBetween(); see per-type notes on semantics.
Delegates to T::isBetween(): is this observation's payload between a's and b's (payload-defined ordering, e.g.
spatial or temporal interpolation range)?
Definition at line 159 of file Observations.tpl.h.
References data, and GenericObservation().
Referenced by cmlabs::Observations_UnitTest().
| std::string cmlabs::GenericObservation< T >::print | ( | ) |
One-line human-readable rendering (header + payload).
Human-readable one-line description of the payload (delegates to T::print()).
Definition at line 186 of file Observations.tpl.h.
References data.
|
static |
Deserialize every observation of type T carried by msg.
Extract every "OBS" data entry of matching size from msg into new observations.
Iterates ids 1,2,3,... until getData() finds no more entries; each blob whose size equals sizeof(ObsHeader)+sizeof(T) and whose type tag matches T is deserialized. Entries of the wrong observation type are skipped (readFromData() rejects them), but iteration stops at the first missing/short id, so ids must be contiguous from 1.
Definition at line 32 of file Observations.tpl.h.
References data, GenericObservation(), cmlabs::DataMessage::getData(), and readFromData().
Referenced by cmlabs::Observations_UnitTest().
| bool cmlabs::GenericObservation< T >::readFromData | ( | const char * | cdata, |
| uint32 | size, | ||
| uint64 | id = 0 ) |
Parse from a raw blob.
Deserialize header and payload from a raw blob.
Strict validation: size must equal sizeof(ObsHeader)+sizeof(T) and the blob's type tag must match this instantiation's type (set at construction), so reading a blob of another observation type fails cleanly rather than mis-interpreting bytes.
| cdata | Serialized bytes (borrowed; copied into this object). |
| size | Byte count; must equal sizeof(ObsHeader)+sizeof(T). |
| id | Unused. |
Definition at line 131 of file Observations.tpl.h.
Referenced by GenericObservation(), ReadAllFromMessage(), and readFromMessage().
| bool cmlabs::GenericObservation< T >::readFromMessage | ( | DataMessage * | msg, |
| uint64 | id = 0 ) |
Read the observation with id id (0 = first) from msg.
Deserialize the "OBS" data entry stored under id in msg (via readFromData()).
Definition at line 144 of file Observations.tpl.h.
References cmlabs::DataMessage::getData(), and readFromData().
Referenced by cmlabs::Observations_UnitTest().
| std::string cmlabs::GenericObservation< T >::toJSON | ( | ) |
JSON object rendering.
Render header metadata plus the payload's own JSON (T::toJSON()) as one JSON object.
If the payload produces no JSON, a stub object with "datatype": "unknown" is emitted so consumers still see the header fields.
Definition at line 194 of file Observations.tpl.h.
References data, header, cmlabs::PrintTimeString(), and cmlabs::utils::StringFormat().
|
static |
Serialize all observations in list into msg.
Bulk serialization counterpart of ReadAllFromMessage().
Definition at line 53 of file Observations.tpl.h.
References GenericObservation().
| bool cmlabs::GenericObservation< T >::writeToMessage | ( | DataMessage * | msg, |
| uint64 | id ) |
Append this observation to msg under entry id id.
Serialize this observation into msg as data entry id of type "OBS".
The blob is header followed by a raw memcpy of the T payload (see the file-level note on portability). Fails if neither id nor header.id is set, or if the message already contains an "OBS" entry under that id (no overwrite).
| msg | Target message (caller-owned). |
| id | Entry id; 0 means use header.id. |
Definition at line 103 of file Observations.tpl.h.
References data, cmlabs::DataMessage::getData(), header, and cmlabs::DataMessage::setData().
Referenced by cmlabs::Observations_UnitTest().
| T cmlabs::GenericObservation< T >::data |
Typed payload.
Definition at line 360 of file Observations.h.
Referenced by extractDataFromMessage(), GenericObservation(), GenericObservation(), isBetween(), cmlabs::Observations_UnitTest(), print(), ReadAllFromMessage(), readFromData(), toJSON(), and writeToMessage().
| ObsHeader cmlabs::GenericObservation< T >::header |
Identity/provenance/confidence header.
Definition at line 359 of file Observations.h.
Referenced by extractDataFromMessage(), GenericObservation(), GenericObservation(), cmlabs::Observations_UnitTest(), readFromData(), toJSON(), and writeToMessage().