@ebusd/ebus-typespec 0.1.0 → 0.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,210 @@
1
+ #!/usr/bin/env node
2
+ import { compile, createSourceFile, formatDiagnostic, NodeHost } from "@typespec/compiler";
3
+ import { createWriteStream } from "fs";
4
+ import { readFile } from "node:fs/promises";
5
+ import { createConnection } from "node:net";
6
+ import { createInterface } from "node:readline";
7
+ import { extname, isAbsolute, resolve } from "path";
8
+ let outFile = undefined;
9
+ async function run() {
10
+ const args = process.argv.slice(2);
11
+ let inFiles = [];
12
+ let outFileName = undefined;
13
+ let ebusdHostPort = undefined;
14
+ for (let idx = 0; idx < args.length; idx++) {
15
+ const arg = args[idx];
16
+ if (arg === '-') {
17
+ break;
18
+ }
19
+ if (arg[0] !== '-') {
20
+ inFiles = args.slice(idx);
21
+ break;
22
+ }
23
+ if (arg === '-h' || arg === '--help') {
24
+ const helpTxt = [
25
+ 'usage: tsp2ebusd [-e host[:port]] [-o outfile] [infile*]',
26
+ 'converts eBUS TypeSpec file(s) or stdin to an ebusd CSV file or stdout.',
27
+ 'with:',
28
+ ' -e, --ebusd host[:port] the ebusd host and optional port of ebusd REPL to send the CSV output to (needs to have the "--define" feature enabled)',
29
+ ' -o, --output file the output file to write to instead of stdout',
30
+ ' infile the input file(s) to use instead of stdin',
31
+ ];
32
+ console.log(helpTxt.join('\n'));
33
+ return;
34
+ }
35
+ if (arg === '-o' || arg === '--output') {
36
+ outFileName = args[++idx];
37
+ }
38
+ else if (arg === '-e' || arg === '--ebusd') {
39
+ const parts = args[++idx].split(':');
40
+ if (!parts[0].length) {
41
+ throw new Error('invalid ebusd host');
42
+ }
43
+ const ebusdPort = parts.length > 1 ? parseInt(parts[1], 10) : 8888;
44
+ if (ebusdPort < 1 || ebusdPort > 65535 || isNaN(ebusdPort)) {
45
+ throw new Error('invalid ebusd port');
46
+ }
47
+ ebusdHostPort = [parts[0], ebusdPort];
48
+ }
49
+ else {
50
+ throw new Error('invalid arguments');
51
+ }
52
+ }
53
+ if (outFileName) {
54
+ // console.log(`redirecting output to ${outFileName}`);
55
+ outFile = createWriteStream(outFileName);
56
+ }
57
+ const log = outFile ? (...args) => outFile.write(args.join(' ') + '\n') : console.log;
58
+ const inputFiles = {};
59
+ let entryFile = '';
60
+ if (inFiles.length) {
61
+ for (const inFile of inFiles) {
62
+ let name = extname(inFile) === '.tsp' ? inFile : `${inFile}.tsp`;
63
+ const relative = !isAbsolute(name);
64
+ if (relative) {
65
+ name = './' + name;
66
+ }
67
+ if (!entryFile) {
68
+ if (!relative) {
69
+ // bit of a hack for aquiring the context of the cwd for typespec compiler
70
+ name = './main.tsp';
71
+ }
72
+ entryFile = name;
73
+ }
74
+ inputFiles[name] = createSourceFile(await readFile(inFile, 'utf-8'), name);
75
+ if (relative) {
76
+ inputFiles[resolve(name)] = inputFiles[name];
77
+ }
78
+ }
79
+ }
80
+ else {
81
+ entryFile = './main.tsp';
82
+ const input = ['using Ebus;\n'];
83
+ for await (const chunk of process.stdin) {
84
+ input.push(chunk);
85
+ }
86
+ inputFiles[entryFile] = createSourceFile(input.join(''), entryFile);
87
+ }
88
+ inputFiles[entryFile.substring(2)] = inputFiles[entryFile];
89
+ // console.log('inp',Object.keys(inputFiles))
90
+ const inputSourceStat = { isDirectory: () => false, isFile: () => true };
91
+ const logs = [];
92
+ const logSink = { log: (log) => logs.push(log) };
93
+ const options = {
94
+ emit: ['@ebusd/ebus-typespec'],
95
+ additionalImports: ['@ebusd/ebus-typespec'],
96
+ };
97
+ const outputFiles = {};
98
+ const host = {
99
+ ...NodeHost,
100
+ logSink,
101
+ realpath: async (path) => inputFiles[path] ? path : NodeHost.realpath(path),
102
+ readFile: async (path) => inputFiles[path] || await NodeHost.readFile(path),
103
+ stat: async (path) => inputFiles[path] ? inputSourceStat : NodeHost.stat(path),
104
+ writeFile: async (path, content) => { outputFiles[path] = content; },
105
+ mkdirp: async (path) => path,
106
+ };
107
+ const program = await compile(host, entryFile, options);
108
+ if (program.hasError() || program.diagnostics.length) {
109
+ throw new Error(`compilation failed:\n${program.diagnostics.map(formatDiagnostic).join('\n')}`);
110
+ }
111
+ const filenames = Object.keys(outputFiles);
112
+ if (filenames.length == 0) {
113
+ throw new Error(`no file emitted`);
114
+ }
115
+ if (filenames.length != 1) {
116
+ throw new Error(`too many files emitted: ${filenames.join()}`);
117
+ }
118
+ if (!ebusdHostPort) {
119
+ log(outputFiles[filenames[0]]);
120
+ }
121
+ else {
122
+ const lines = outputFiles[filenames[0]].split('\n');
123
+ await sendToEbusd(lines, ebusdHostPort, log);
124
+ }
125
+ }
126
+ const sendToEbusd = async (inputLines, ebusdHostPort, log) => {
127
+ // find the relevant line(s) from the output
128
+ let removeLevel = undefined;
129
+ const lines = inputLines.filter(line => {
130
+ if (removeLevel === undefined) {
131
+ removeLevel = line.includes(',level,');
132
+ return;
133
+ }
134
+ if (!line || line.startsWith('#') || line.startsWith('*'))
135
+ return;
136
+ return line;
137
+ }).map(line => {
138
+ if (!removeLevel)
139
+ return line;
140
+ const parts = line.split(',');
141
+ parts.splice(2, 1);
142
+ return parts.join(',');
143
+ });
144
+ if (!lines.length) {
145
+ throw new Error('no usable result');
146
+ }
147
+ const conn = createConnection({ port: ebusdHostPort[1], host: ebusdHostPort[0], allowHalfOpen: false });
148
+ conn.setEncoding('utf-8');
149
+ let timer;
150
+ try {
151
+ const send = () => {
152
+ if (timer) {
153
+ clearTimeout(timer);
154
+ }
155
+ const line = lines.shift();
156
+ if (!line) {
157
+ return;
158
+ }
159
+ timer = setTimeout(() => conn.destroy(), 3000);
160
+ const cmd = `read -V -def "${line}"`;
161
+ log(cmd);
162
+ conn.write(cmd + '\n');
163
+ return true;
164
+ };
165
+ send();
166
+ for await (const line of createInterface(conn)) {
167
+ if (!line) {
168
+ if (!send()) {
169
+ break; // end of commands
170
+ }
171
+ continue;
172
+ }
173
+ if (line.startsWith('ERR:')) {
174
+ throw new Error('error from ebusd: ' + line);
175
+ }
176
+ log('# ' + line);
177
+ }
178
+ }
179
+ finally {
180
+ try {
181
+ conn.write('\x04');
182
+ }
183
+ catch (_e) {
184
+ // ignore
185
+ }
186
+ if (timer) {
187
+ clearTimeout(timer);
188
+ }
189
+ conn.destroy();
190
+ }
191
+ };
192
+ run()
193
+ .catch(err => {
194
+ if (outFile) {
195
+ try {
196
+ outFile.write(err.toString());
197
+ }
198
+ catch (_e) {
199
+ // ignore
200
+ }
201
+ }
202
+ console.error(err);
203
+ process.exit(1);
204
+ })
205
+ .finally(() => {
206
+ if (outFile) {
207
+ outFile.close();
208
+ }
209
+ });
210
+ //# sourceMappingURL=tsp2ebusd.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"tsp2ebusd.js","sourceRoot":"","sources":["../../src/tsp2ebusd.ts"],"names":[],"mappings":";AAEA,OAAO,EAAC,OAAO,EAAE,gBAAgB,EAAE,gBAAgB,EAAE,QAAQ,EAA8E,MAAM,oBAAoB,CAAC;AACtK,OAAO,EAAC,iBAAiB,EAAmB,MAAM,IAAI,CAAC;AACvD,OAAO,EAAC,QAAQ,EAAC,MAAM,kBAAkB,CAAC;AAC1C,OAAO,EAAC,gBAAgB,EAAC,MAAM,UAAU,CAAC;AAC1C,OAAO,EAAC,eAAe,EAAC,MAAM,eAAe,CAAC;AAC9C,OAAO,EAAC,OAAO,EAAE,UAAU,EAAE,OAAO,EAAC,MAAM,MAAM,CAAC;AAElD,IAAI,OAAO,GAA0B,SAAS,CAAC;AAE/C,KAAK,UAAU,GAAG;IAChB,MAAM,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;IACnC,IAAI,OAAO,GAAa,EAAE,CAAC;IAC3B,IAAI,WAAW,GAAqB,SAAS,CAAC;IAC9C,IAAI,aAAa,GAA+B,SAAS,CAAC;IAC1D,KAAK,IAAI,GAAG,GAAG,CAAC,EAAE,GAAG,GAAG,IAAI,CAAC,MAAM,EAA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AC,KAAK,CAAC,MAAM,CAAC,CAAC;QACrB,CAAC;QAAC,OAAO,EAAE,EAAE,CAAC;YACZ,SAAS;QACX,CAAC;QACD,IAAI,KAAK,EAAE,CAAC;YACV,YAAY,CAAC,KAAK,CAAC,CAAC;QACtB,CAAC;QACD,IAAI,CAAC,OAAO,EAAE,CAAC;IACjB,CAAC;AACH,CAAC,CAAA;AAED,GAAG,EAAE;KACJ,KAAK,CAAC,GAAG,CAAC,EAAE;IACX,IAAI,OAAO,EAAE,CAAC;QACZ,IAAI,CAAC;YACH,OAAO,CAAC,KAAK,CAAC,GAAG,CAAC,QAAQ,EAAE,CAAC,CAAC;QAChC,CAAC;QAAC,OAAO,EAAE,EAAE,CAAC;YACZ,SAAS;QACX,CAAC;IACH,CAAC;IACD,OAAO,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;IACnB,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;AAClB,CAAC,CAAC;KACD,OAAO,CAAC,GAAG,EAAE;IACZ,IAAI,OAAO,EAAE,CAAC;QACZ,OAAO,CAAC,KAAK,EAAE,CAAC;IAClB,CAAC;AACH,CAAC,CAAC,CAAC"}
package/docs.md CHANGED
@@ -1,11 +1,11 @@
1
- # ebus
1
+ # @ebusd/ebus-typespec
2
2
 
3
3
  TypeSpec library for defining eBUS messages and emitting to ebusd CSV.
4
4
 
5
5
  ## Install
6
6
 
7
7
  ```bash
8
- npm install https://github.com/john30/ebus-typespec
8
+ npm install @ebusd/ebus-typespec
9
9
  ```
10
10
 
11
11
  ## Emitter
@@ -15,14 +15,14 @@ npm install https://github.com/john30/ebus-typespec
15
15
  1. Via the command line
16
16
 
17
17
  ```bash
18
- tsp compile . --emit=ebus
18
+ tsp compile . --emit=@ebusd/ebus-typespec
19
19
  ```
20
20
 
21
21
  2. Via the config
22
22
 
23
23
  ```yaml
24
24
  emit:
25
- - "ebus"
25
+ - "@ebusd/ebus-typespec"
26
26
  ```
27
27
 
28
28
  ### Emitter options
@@ -99,7 +99,7 @@ Available ruleSets:
99
99
  Define authentication level.
100
100
 
101
101
  ```typespec
102
- @Ebus.auth(auth: valueof string)
102
+ @Ebus.auth(value: valueof string)
103
103
  ```
104
104
 
105
105
  ##### Target
@@ -108,16 +108,16 @@ Define authentication level.
108
108
 
109
109
  ##### Parameters
110
110
 
111
- | Name | Type | Description |
112
- | ---- | ----------------------- | ----------- |
113
- | auth | `valueof scalar string` | |
111
+ | Name | Type | Description |
112
+ | ----- | ----------------------- | ------------------------------------------ |
113
+ | value | `valueof scalar string` | the authentication level (e.g. 'install'). |
114
114
 
115
115
  #### `@base`
116
116
 
117
117
  Define the base message ID to be combined with an extension ID.
118
118
 
119
119
  ```typespec
120
- @Ebus.base(pb: valueof Ebus.Pb, sb: valueof Ebus.Sb, ...id: valueof Ebus.Symbol[])
120
+ @Ebus.base(pb: valueof Ebus.Pb, sb: valueof Ebus.Sb, ...dd: valueof Ebus.Symbol[])
121
121
  ```
122
122
 
123
123
  ##### Target
@@ -130,7 +130,7 @@ Define the base message ID to be combined with an extension ID.
130
130
  | ---- | ----------------------------- | ------------------------- |
131
131
  | pb | `valueof scalar Ebus.Pb` | the primary message ID. |
132
132
  | sb | `valueof scalar Ebus.Sb` | the secondary message ID. |
133
- | id | `valueof model Ebus.Symbol[]` | further message ID parts. |
133
+ | dd | `valueof model Ebus.Symbol[]` | further message ID parts. |
134
134
 
135
135
  #### `@condition`
136
136
 
@@ -210,7 +210,7 @@ Define the factor.
210
210
  Define the whole message ID.
211
211
 
212
212
  ```typespec
213
- @Ebus.id(pb: valueof Ebus.Pb, sb: valueof Ebus.Sb, ...id: valueof Ebus.Symbol[])
213
+ @Ebus.id(pb: valueof Ebus.Pb, sb: valueof Ebus.Sb, ...dd: valueof Ebus.Symbol[])
214
214
  ```
215
215
 
216
216
  ##### Target
@@ -223,7 +223,7 @@ Define the whole message ID.
223
223
  | ---- | ----------------------------- | ------------------------- |
224
224
  | pb | `valueof scalar Ebus.Pb` | the primary message ID. |
225
225
  | sb | `valueof scalar Ebus.Sb` | the secondary message ID. |
226
- | id | `valueof model Ebus.Symbol[]` | further message ID parts. |
226
+ | dd | `valueof model Ebus.Symbol[]` | further message ID parts. |
227
227
 
228
228
  #### `@in`
229
229
 
@@ -246,7 +246,7 @@ None
246
246
  Define the inherited model(s).
247
247
 
248
248
  ```typespec
249
- @Ebus.inherit(...models: valueof Model[])
249
+ @Ebus.inherit(...models: Model[])
250
250
  ```
251
251
 
252
252
  ##### Target
@@ -255,9 +255,9 @@ Define the inherited model(s).
255
255
 
256
256
  ##### Parameters
257
257
 
258
- | Name | Type | Description |
259
- | ------ | ----------------------- | ----------------- |
260
- | models | `valueof model Model[]` | inherited models. |
258
+ | Name | Type | Description |
259
+ | ------ | --------------- | ----------------- |
260
+ | models | `model Model[]` | inherited models. |
261
261
 
262
262
  #### `@out`
263
263
 
@@ -423,7 +423,7 @@ None
423
423
  Define the max bits.
424
424
 
425
425
  ```typespec
426
- @Ebus.internal.maxBits(value: valueof numeric)
426
+ @Ebus.internal.maxBits(value: valueof uint8)
427
427
  ```
428
428
 
429
429
  ##### Target
@@ -432,9 +432,9 @@ Define the max bits.
432
432
 
433
433
  ##### Parameters
434
434
 
435
- | Name | Type | Description |
436
- | ----- | ------------------------ | ------------- |
437
- | value | `valueof scalar numeric` | the max bits. |
435
+ | Name | Type | Description |
436
+ | ----- | ---------------------- | ------------- |
437
+ | value | `valueof scalar uint8` | the max bits. |
438
438
 
439
439
  #### `@reverse`
440
440
 
@@ -1,4 +1,4 @@
1
- import "../dist/src/decorators.js";
1
+ import "../dist/src/index.js";
2
2
  import "./types.tsp";
3
3
 
4
4
  using TypeSpec.Reflection;
@@ -25,14 +25,15 @@ extern dec passive(target: Model);
25
25
 
26
26
  /**
27
27
  * Define authentication level.
28
+ * @param value the authentication level (e.g. 'install').
28
29
  */
29
- extern dec auth(target: Model, auth: valueof string);
30
+ extern dec auth(target: Model, value: valueof string);
30
31
 
31
32
  /**
32
33
  * Define the source address.
33
34
  * @param value the source address QQ.
34
35
  */
35
- extern dec qq(source: Model, value?: valueof Source);
36
+ extern dec qq(target: Model, value?: valueof Source);
36
37
 
37
38
  /**
38
39
  * Define the target address.
@@ -44,17 +45,17 @@ extern dec zz(target: Model|Namespace, value?: valueof Target);
44
45
  * Define the whole message ID.
45
46
  * @param pb the primary message ID.
46
47
  * @param sb the secondary message ID.
47
- * @param id further message ID parts.
48
+ * @param dd further message ID parts.
48
49
  */
49
- extern dec id(target: Model, pb: valueof Pb, sb: valueof Sb, ...id: valueof Symbol[]);
50
+ extern dec id(target: Model, pb: valueof Pb, sb: valueof Sb, ...dd: valueof Symbol[]);
50
51
 
51
52
  /**
52
53
  * Define the base message ID to be combined with an extension ID.
53
54
  * @param pb the primary message ID.
54
55
  * @param sb the secondary message ID.
55
- * @param id further message ID parts.
56
+ * @param dd further message ID parts.
56
57
  */
57
- extern dec base(target: Model, pb: valueof Pb, sb: valueof Sb, ...id: valueof Symbol[]);
58
+ extern dec base(target: Model, pb: valueof Pb, sb: valueof Sb, ...dd: valueof Symbol[]);
58
59
 
59
60
  /**
60
61
  * Define the extension message ID to be combined with a base ID.
@@ -66,7 +67,7 @@ extern dec ext(target: Model, ...id: valueof Symbol[]);
66
67
  * Define the inherited model(s).
67
68
  * @param models inherited models.
68
69
  */
69
- extern dec inherit(target: Model, ...models: valueof Model[]);
70
+ extern dec inherit(target: Model, ...models: Model[]);
70
71
 
71
72
  /**
72
73
  * Define message part outbound to target.
@@ -123,5 +124,5 @@ namespace internal {
123
124
  * Define the max bits.
124
125
  * @param value the max bits.
125
126
  */
126
- extern dec maxBits(target: numeric, value: valueof numeric);
127
+ extern dec maxBits(target: numeric, value: valueof uint8);
127
128
  }
package/lib/main.tsp CHANGED
@@ -1,3 +1,4 @@
1
+ import "../dist/src/index.js"; // needed for $flags to be effective
1
2
  import "./decorators.tsp";
2
3
  import "./types.tsp";
3
4
  import "./models.tsp";
package/lib/models.tsp CHANGED
@@ -36,7 +36,7 @@ namespace id {
36
36
  }
37
37
 
38
38
  @values(manufacturers)
39
- scalar manufacturer extends UCH
39
+ scalar manufacturer extends UCH;
40
40
 
41
41
  model id_read {}
42
42
  @zz(BROADCAST)
package/lib/types.tsp CHANGED
@@ -1,7 +1,7 @@
1
1
  namespace Ebus;
2
2
 
3
3
  /** A symbol on the bus. */
4
- scalar Symbol extends uint8
4
+ scalar Symbol extends uint8;
5
5
 
6
6
  /** List of special symbols. */
7
7
  union symbols {
@@ -11,10 +11,10 @@ union symbols {
11
11
  }
12
12
 
13
13
  /** A source address 'QQ. */
14
- scalar Source extends Symbol
14
+ scalar Source extends Symbol;
15
15
 
16
16
  /** A target address 'ZZ'. */
17
- scalar Target extends Symbol
17
+ scalar Target extends Symbol;
18
18
 
19
19
  /** List of special target addresses. */
20
20
  union targets {
@@ -26,144 +26,144 @@ union targets {
26
26
  alias BROADCAST = 0xfe; // todo should be possible as targets.Broadcast someday
27
27
 
28
28
  /** the primary command symbol 'PB'. */
29
- scalar Pb extends Symbol
29
+ scalar Pb extends Symbol;
30
30
 
31
31
  /** the secondary command symbol 'SB'. */
32
- scalar Sb extends Symbol
32
+ scalar Sb extends Symbol;
33
33
 
34
34
  /** The known numeric base types. */
35
35
  namespace num {
36
36
  @encode("uint8")
37
- scalar BI0 extends boolean
37
+ scalar BI0 extends boolean;
38
38
  @encode("uint8")
39
- scalar BI1 extends boolean
39
+ scalar BI1 extends boolean;
40
40
  @encode("uint8")
41
- scalar BI2 extends boolean
41
+ scalar BI2 extends boolean;
42
42
  @encode("uint8")
43
- scalar BI3 extends boolean
43
+ scalar BI3 extends boolean;
44
44
  @encode("uint8")
45
- scalar BI4 extends boolean
45
+ scalar BI4 extends boolean;
46
46
  @encode("uint8")
47
- scalar BI5 extends boolean
47
+ scalar BI5 extends boolean;
48
48
  @encode("uint8")
49
- scalar BI6 extends boolean
49
+ scalar BI6 extends boolean;
50
50
  @encode("uint8")
51
- scalar BI7 extends boolean
51
+ scalar BI7 extends boolean;
52
52
  @internal.maxBits(7)
53
- scalar BI0_7 extends uint8
53
+ scalar BI0_7 extends uint8;
54
54
 
55
- scalar UCH extends uint8
56
- scalar SCH extends int8
55
+ scalar UCH extends uint8;
56
+ scalar SCH extends int8;
57
57
  alias D1B = SCH;
58
58
  @internal.bcd
59
- scalar BCD extends uint8
59
+ scalar BCD extends uint8;
60
60
  @internal.hex
61
- scalar HCD extends uint8
61
+ scalar HCD extends uint8;
62
62
  @divisor(2)
63
- scalar D1C extends uint8
63
+ scalar D1C extends uint8;
64
64
 
65
65
  @internal.reverse
66
66
  @internal.bcd
67
- scalar PIN extends uint16
68
- scalar UIN extends uint16
67
+ scalar PIN extends uint16;
68
+ scalar UIN extends uint16;
69
69
  @internal.reverse
70
- scalar UIR extends UIN
71
- scalar SIN extends int16
70
+ scalar UIR extends UIN;
71
+ scalar SIN extends int16;
72
72
  @internal.reverse
73
- scalar SIR extends SIN
73
+ scalar SIR extends SIN;
74
74
  @internal.hex
75
- scalar HCD2 extends uint16
75
+ scalar HCD2 extends uint16;
76
76
 
77
77
  @divisor(256)
78
- scalar D2B extends int16
78
+ scalar D2B extends int16;
79
79
 
80
80
  @divisor(16)
81
- scalar D2C extends int16
81
+ scalar D2C extends int16;
82
82
 
83
83
  @divisor(1000)
84
- scalar FLT extends int16
84
+ scalar FLT extends int16;
85
85
  @internal.reverse
86
- scalar FLR extends FLT
86
+ scalar FLR extends FLT;
87
87
 
88
88
  //todo 3 byte int
89
89
  @internal.bcd
90
- scalar BCD3 extends uint32 // todo 3 bytes
90
+ scalar BCD3 extends uint32; // todo 3 bytes
91
91
  @internal.hex
92
- scalar HCD3 extends uint32 // todo 3 bytes
92
+ scalar HCD3 extends uint32; // todo 3 bytes
93
93
 
94
- scalar ULG extends uint32
94
+ scalar ULG extends uint32;
95
95
  @internal.reverse
96
- scalar ULR extends ULG
97
- scalar SLG extends int32
96
+ scalar ULR extends ULG;
97
+ scalar SLG extends int32;
98
98
  @internal.reverse
99
- scalar SLR extends SLG
99
+ scalar SLR extends SLG;
100
100
  @internal.bcd
101
- scalar BCD4 extends uint32
101
+ scalar BCD4 extends uint32;
102
102
  @internal.hex
103
- scalar HCD4 extends uint32
103
+ scalar HCD4 extends uint32;
104
104
 
105
- scalar EXP extends float32
105
+ scalar EXP extends float32;
106
106
  @internal.reverse
107
- scalar EXR extends EXP
107
+ scalar EXR extends EXP;
108
108
  }
109
109
 
110
110
  /** The known string base types. */
111
111
  namespace str {
112
112
  @maxLength(31)
113
- scalar STR extends string
113
+ scalar STR extends string;
114
114
  @encode("nullterm") // todo
115
115
  @maxLength(31)
116
- scalar NTS extends string
116
+ scalar NTS extends string;
117
117
  @maxLength(31)
118
- scalar IGN extends string // todo bytes would be more logical, but have not length limit
118
+ scalar IGN extends string; // todo bytes would be more logical, but have not length limit
119
119
  @internal.hex
120
120
  @maxLength(31)
121
- scalar HEX extends string
121
+ scalar HEX extends string;
122
122
  }
123
123
 
124
124
  /** The known date/time base types. */
125
125
  namespace dtm {
126
- scalar BDY extends uint8 // todo weekday
127
- scalar HDY extends uint8 // todo weekday
126
+ scalar BDY extends uint8; // todo weekday
127
+ scalar HDY extends uint8; // todo weekday
128
128
  @internal.bcd
129
129
  @encode("", uint32)
130
- scalar BDA extends plainDate
130
+ scalar BDA extends plainDate;
131
131
  alias BDA4 = BDA;
132
- scalar BDA3 extends BDA // todo 3 bytes
133
- scalar BDZ extends BDA
132
+ scalar BDA3 extends BDA; // todo 3 bytes
133
+ scalar BDZ extends BDA;
134
134
  @internal.hex
135
135
  @encode("", uint32)
136
- scalar HDA extends plainDate
136
+ scalar HDA extends plainDate;
137
137
  alias HDA4 = HDA;
138
- scalar HDA3 extends HDA
138
+ scalar HDA3 extends HDA;
139
139
  @encode("", uint16)
140
- scalar DAY extends plainDate
140
+ scalar DAY extends plainDate;
141
141
  @encode("", uint32)
142
- scalar DTM extends offsetDateTime
142
+ scalar DTM extends offsetDateTime;
143
143
 
144
144
  @internal.bcd
145
- scalar BTI extends plainTime // todo 3 bytes
145
+ scalar BTI extends plainTime; // todo 3 bytes
146
146
  @internal.hex
147
- scalar HTI extends plainTime // todo 3 bytes
147
+ scalar HTI extends plainTime; // todo 3 bytes
148
148
  @internal.reverse
149
- scalar VTI extends HTI
149
+ scalar VTI extends HTI;
150
150
  @internal.bcd
151
151
  @encode("", uint16)
152
- scalar BTM extends plainTime
152
+ scalar BTM extends plainTime;
153
153
  @internal.reverse
154
- scalar VTM extends BTM
154
+ scalar VTM extends BTM;
155
155
  @internal.hex
156
156
  @encode("", uint16)
157
- scalar HTM extends plainTime
157
+ scalar HTM extends plainTime;
158
158
  @encode("", uint16)
159
- scalar MIN extends plainTime // todo check if rather duration
159
+ scalar MIN extends plainTime; // todo check if rather duration
160
160
  @divisor(10)
161
161
  @encode("", uint8)
162
- scalar TTM extends plainTime
162
+ scalar TTM extends plainTime;
163
163
  @divisor(30)
164
164
  @encode("", uint8)
165
- scalar TTH extends plainTime
165
+ scalar TTH extends plainTime;
166
166
  @divisor(15)
167
167
  @encode("", uint8) // todo actually 7 bits
168
- scalar TTQ extends plainTime
168
+ scalar TTQ extends plainTime;
169
169
  }