CMSDK 2.0.1
Cross-platform C++ base library and SDK for the Psyclone AIOS platform
Loading...
Searching...
No Matches
layout.cpp
Go to the documentation of this file.
1// CMSDK DataMessage wire-layout dump: the single source of truth for non-C++ codecs.
2//
3// Prints the byte layout of DataMessageHeader (offset + size of every field, as the C++
4// compiler lays it out, including padding), the entry header, the content-type ids and the
5// constants a codec needs, as JSON. kotlin/fixtures/layout.json is this program's output and
6// the Kotlin codec's tests check their own offsets against it, so a change to the C++ struct
7// fails the Kotlin build until the codec is updated.
8//
9// Build + run (from CMSDK/): make -C kotlin/tools (writes kotlin/fixtures/layout.json)
10#include "DataMessage.h"
11#include "ObjectIDs.h"
12#include "PsyTime.h"
13#include <cstddef>
14#include <cstdio>
15
16using namespace cmlabs;
17
18#define F(name) printf(" \"%s\": { \"offset\": %u, \"size\": %u },\n", #name, \
19 (unsigned)offsetof(DataMessageHeader, name), (unsigned)sizeof(((DataMessageHeader*)0)->name))
20#define FL(name) printf(" \"%s\": { \"offset\": %u, \"size\": %u }\n", #name, \
21 (unsigned)offsetof(DataMessageHeader, name), (unsigned)sizeof(((DataMessageHeader*)0)->name))
22
23int main() {
24 printf("{\n");
25 printf(" \"format\": \"CMSDK DataMessage\",\n");
26 printf(" \"version\": %u,\n", (unsigned)CURRENTDATAMESSAGEVERSION);
27 printf(" \"byteOrder\": \"little-endian (native host order; x86/ARM)\",\n");
28 printf(" \"headerSize\": %u,\n", (unsigned)sizeof(DataMessageHeader));
29 printf(" \"entryHeaderSize\": %u,\n", (unsigned)sizeof(DataMessageEntryHeader));
30 printf(" \"psyTypeLevels\": %u,\n", (unsigned)PSYTYPELEVELS);
31 printf(" \"psyContextLevels\": %u,\n", (unsigned)PSYCONTEXTLEVELS);
32 printf(" \"usecYear0To1970\": %lld,\n", (long long)USEC_YEAR_0_TO_1970);
33 printf(" \"ids\": { \"DATAMESSAGEID\": %u, \"UNUSEDID\": %u, \"CONSTCHARID\": %u, \"TIMEID\": %u, "
34 "\"CHARDATAID\": %u, \"INTID\": %u, \"DOUBLEID\": %u },\n",
35 (unsigned)DATAMESSAGEID, (unsigned)UNUSEDID, (unsigned)CONSTCHARID, (unsigned)TIMEID,
36 (unsigned)CHARDATAID, (unsigned)INTID, (unsigned)DOUBLEID);
37 printf(" \"header\": {\n");
38 F(size); F(cid); F(cver); F(cenc); F(memid); F(time); F(sendtime); F(recvtime);
39 F(origin); F(destination); F(ttl); F(priority); F(policy); F(from); F(to); F(type);
40 F(tag); F(status); F(reference); F(serial); F(contextchange); F(userSize); F(userCount);
41 F(cyclecputime); F(cyclewalltime); F(chaincputime); F(chainwalltime); F(chaincount);
42 FL(systemid);
43 printf(" }\n}\n");
44 return 0;
45}
The binary DataMessage container — the central data-exchange object of Psyclone/CMSDK.
#define CURRENTDATAMESSAGEVERSION
Object type ids used to tag and verify every binary structure in CMSDK memory.
#define CONSTCHARID
Definition ObjectIDs.h:38
#define CHARDATAID
Definition ObjectIDs.h:40
#define DOUBLEID
Definition ObjectIDs.h:42
#define DATAMESSAGEID
Definition ObjectIDs.h:75
#define INTID
Definition ObjectIDs.h:41
#define UNUSEDID
Definition ObjectIDs.h:37
#define TIMEID
Definition ObjectIDs.h:39
CMSDK time: µs-resolution 64-bit timestamps and the Time Mapping Constant (TMC).
#define PSYCONTEXTLEVELS
Number of hierarchy levels in a PsyContext.
Definition Types.h:267
#define PSYTYPELEVELS
Number of hierarchy levels in a PsyType.
Definition Types.h:100
#define USEC_YEAR_0_TO_1970
Microseconds between year 0000 and the Unix epoch (1970-01-01).
Definition PsyTime.h:84
#define F(name)
Definition layout.cpp:18
#define FL(name)
Definition layout.cpp:20
int main()
Definition layout.cpp:23
Header preceding every user entry inside a DataMessage's flat memory block.
The current (version 10) DataMessage wire/shared-memory header.