sen-ether-client 0.1.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.
- package/API.md +239 -0
- package/LICENSE +21 -0
- package/README.md +227 -0
- package/bin/node-sen-probe.js +426 -0
- package/bin/node-sen-scan.js +77 -0
- package/index.js +75 -0
- package/lib/bus.js +740 -0
- package/lib/client.js +634 -0
- package/lib/codec.js +501 -0
- package/lib/crc32.js +26 -0
- package/lib/discovery.js +439 -0
- package/lib/hash32.js +40 -0
- package/lib/protocol/generated.js +157 -0
- package/lib/sen.js +1346 -0
- package/lib/values.js +421 -0
- package/package.json +31 -0
- package/resources/protocol/ether/discovery.stl +19 -0
- package/resources/protocol/ether/runtime.stl +40 -0
- package/resources/protocol/kernel/basic_types.stl +274 -0
- package/resources/protocol/kernel/bus_protocol.stl +198 -0
- package/resources/protocol/kernel/type_specs.stl +554 -0
- package/resources/protocol/protocol.json +15 -0
- package/scripts/generate-protocol.mjs +111 -0
|
@@ -0,0 +1,554 @@
|
|
|
1
|
+
import "stl/sen/kernel/basic_types.stl"
|
|
2
|
+
|
|
3
|
+
// IMPORTANT NOTE: Types defined in this file CANNOT be erased, as we need to keep track of older versions to ensure
|
|
4
|
+
// runtime compatibility. Older versions are marked with a suffix V# after the name, being # the KernelProtocolVersion.
|
|
5
|
+
|
|
6
|
+
package sen.kernel;
|
|
7
|
+
|
|
8
|
+
// built-in integrals
|
|
9
|
+
enum IntegralType : u8
|
|
10
|
+
{
|
|
11
|
+
uint8Type,
|
|
12
|
+
int16Type,
|
|
13
|
+
uint16Type,
|
|
14
|
+
int32Type,
|
|
15
|
+
uint32Type,
|
|
16
|
+
int64Type,
|
|
17
|
+
uint64Type
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
// built-in reals
|
|
21
|
+
enum RealType: u8
|
|
22
|
+
{
|
|
23
|
+
float32Type,
|
|
24
|
+
float64Type
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
// all built-in numeric types
|
|
28
|
+
variant NumericType
|
|
29
|
+
{
|
|
30
|
+
IntegralType,
|
|
31
|
+
RealType
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
// built-in others
|
|
35
|
+
enum BasicType: u8
|
|
36
|
+
{
|
|
37
|
+
booleanType,
|
|
38
|
+
stringType,
|
|
39
|
+
durationType,
|
|
40
|
+
timestampType,
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
// all built-in types
|
|
44
|
+
variant BuiltInType
|
|
45
|
+
{
|
|
46
|
+
NumericType,
|
|
47
|
+
BasicType
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
// optional value for a f64
|
|
51
|
+
optional<f64> MaybeF64;
|
|
52
|
+
|
|
53
|
+
// optional value for a u64
|
|
54
|
+
optional<u64> MaybeU64;
|
|
55
|
+
|
|
56
|
+
// an enumerator
|
|
57
|
+
struct EnumeratorSpec
|
|
58
|
+
{
|
|
59
|
+
name : string, // enumerator name
|
|
60
|
+
key : u32, // enumerator value
|
|
61
|
+
description : string // enumerator description
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
struct EnumeratorSpecV5
|
|
65
|
+
{
|
|
66
|
+
name : string, // enumerator name
|
|
67
|
+
key : u64, // enumerator value
|
|
68
|
+
hash : u32 // unique hash
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
struct EnumeratorSpecV4
|
|
72
|
+
{
|
|
73
|
+
name : string, // enumerator name
|
|
74
|
+
key : u64 // enumerator value
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
// list of enumerators
|
|
78
|
+
sequence<EnumeratorSpec> EnumeratorSpecList;
|
|
79
|
+
sequence<EnumeratorSpecV5> EnumeratorSpecListV5;
|
|
80
|
+
sequence<EnumeratorSpecV4> EnumeratorSpecListV4;
|
|
81
|
+
|
|
82
|
+
// spec of an enum type
|
|
83
|
+
struct EnumTypeSpec
|
|
84
|
+
{
|
|
85
|
+
enums : EnumeratorSpecList, // enumerators
|
|
86
|
+
storageType : IntegralType // type used to store the value
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
struct EnumTypeSpecV5
|
|
90
|
+
{
|
|
91
|
+
enums : EnumeratorSpecListV5, // enumerators
|
|
92
|
+
storageType : IntegralType, // type used to store the value
|
|
93
|
+
hash : u32 // unique hash
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
struct EnumTypeSpecV4
|
|
97
|
+
{
|
|
98
|
+
enums : EnumeratorSpecListV4, // enumerators
|
|
99
|
+
storageType : IntegralType // type used to store the value
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
// spec of a quantity type
|
|
103
|
+
struct QuantityTypeSpec
|
|
104
|
+
{
|
|
105
|
+
elementType : NumericType, // type used to store the value
|
|
106
|
+
unit : UnitInfo, // used unit
|
|
107
|
+
minValue : MaybeF64, // discarded if >= maxValue
|
|
108
|
+
maxValue : MaybeF64, // discarded if <= minValue
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
struct QuantityTypeSpecV5
|
|
112
|
+
{
|
|
113
|
+
numericType : NumericType, // type used to store the value
|
|
114
|
+
unit : UnitInfo, // used unit
|
|
115
|
+
minValue : f64, // discarded if >= maxValue
|
|
116
|
+
maxValue : f64, // discarded if <= minValue
|
|
117
|
+
hash : u32 // unique hash
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
struct QuantityTypeSpecV4
|
|
121
|
+
{
|
|
122
|
+
numericType : NumericType, // type used to store the value
|
|
123
|
+
unit : UnitInfo, // used unit
|
|
124
|
+
minValue : f64, // discarded if >= maxValue
|
|
125
|
+
maxValue : f64 // discarded if <= minValue
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
// spec of a sequence type
|
|
129
|
+
struct SequenceTypeSpec
|
|
130
|
+
{
|
|
131
|
+
elementType : string, // qualified type name for stored values
|
|
132
|
+
maxSize : MaybeU64, // discarded when 0
|
|
133
|
+
fixedSize : bool,
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
struct SequenceTypeSpecV5
|
|
137
|
+
{
|
|
138
|
+
elementType : string, // qualified type name for stored values
|
|
139
|
+
maxSize : u64, // discarded when 0
|
|
140
|
+
fixedSize : bool,
|
|
141
|
+
hash : u32 // unique hash
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
struct SequenceTypeSpecV4
|
|
145
|
+
{
|
|
146
|
+
elementType : string, // qualified type name for stored values
|
|
147
|
+
maxSize : u64 // discarded when 0
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
// a field of a struct
|
|
151
|
+
struct StructTypeFieldSpec
|
|
152
|
+
{
|
|
153
|
+
name : string, // field name
|
|
154
|
+
description : string, // documentation
|
|
155
|
+
type : string, // qualified type name held by this field
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
struct StructTypeFieldSpecV5
|
|
159
|
+
{
|
|
160
|
+
name : string, // field name
|
|
161
|
+
description : string, // documentation
|
|
162
|
+
type : string, // qualified type name held by this field
|
|
163
|
+
hash : u32 // unique hash
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
struct StructTypeFieldSpecV4
|
|
167
|
+
{
|
|
168
|
+
name : string, // field name
|
|
169
|
+
description : string, // documentation
|
|
170
|
+
type : string // qualified type name held by this field
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
// list of struct fields
|
|
174
|
+
sequence<StructTypeFieldSpec> StructTypeFieldSpecList;
|
|
175
|
+
sequence<StructTypeFieldSpecV5> StructTypeFieldSpecListV5;
|
|
176
|
+
sequence<StructTypeFieldSpecV4> StructTypeFieldSpecListV4;
|
|
177
|
+
|
|
178
|
+
// spec of an struct type
|
|
179
|
+
struct StructTypeSpec
|
|
180
|
+
{
|
|
181
|
+
fields : StructTypeFieldSpecList, // fields
|
|
182
|
+
parent : string, // qualified type name the parent struct, empty means none
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
struct StructTypeSpecV5
|
|
186
|
+
{
|
|
187
|
+
fields : StructTypeFieldSpecListV5, // fields
|
|
188
|
+
parent : string, // qualified type name the parent struct, empty means none
|
|
189
|
+
hash : u32 // unique hash
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
struct StructTypeSpecV4
|
|
193
|
+
{
|
|
194
|
+
fields : StructTypeFieldSpecListV4, // fields
|
|
195
|
+
parent : string // qualified type name the parent struct, empty means none
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
// a field of a variant
|
|
199
|
+
struct VariantTypeFieldSpec
|
|
200
|
+
{
|
|
201
|
+
key : u32, // key/index of this type within the variant
|
|
202
|
+
description : string, // documentation
|
|
203
|
+
type : string, // qualified type name held by this field
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
struct VariantTypeFieldSpecV5
|
|
207
|
+
{
|
|
208
|
+
key : u32, // key/index of this type within the variant
|
|
209
|
+
description : string, // documentation
|
|
210
|
+
type : string, // qualified type name held by this field
|
|
211
|
+
hash : u32 // unique hash
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
struct VariantTypeFieldSpecV4
|
|
215
|
+
{
|
|
216
|
+
key : u32, // key/index of this type within the variant
|
|
217
|
+
description : string, // documentation
|
|
218
|
+
type : string // qualified type name held by this field
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
// list of variant fields
|
|
222
|
+
sequence<VariantTypeFieldSpec> VariantTypeFieldSpecList;
|
|
223
|
+
sequence<VariantTypeFieldSpecV5> VariantTypeFieldSpecListV5;
|
|
224
|
+
sequence<VariantTypeFieldSpecV4> VariantTypeFieldSpecListV4;
|
|
225
|
+
|
|
226
|
+
// spec of an struct type
|
|
227
|
+
struct VariantTypeSpec
|
|
228
|
+
{
|
|
229
|
+
fields : VariantTypeFieldSpecList,
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
struct VariantTypeSpecV5
|
|
233
|
+
{
|
|
234
|
+
fields : VariantTypeFieldSpecListV5,
|
|
235
|
+
hash : u32
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
struct VariantTypeSpecV4
|
|
239
|
+
{
|
|
240
|
+
fields : VariantTypeFieldSpecListV4
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
// data of an aliased type
|
|
244
|
+
struct AliasTypeSpec
|
|
245
|
+
{
|
|
246
|
+
aliasedType : string // qualified type name being aliased
|
|
247
|
+
}
|
|
248
|
+
|
|
249
|
+
struct AliasTypeSpecV5
|
|
250
|
+
{
|
|
251
|
+
aliasedType : string, // qualified type name being aliased
|
|
252
|
+
hash : u32 // unique hash
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
struct AliasTypeSpecV4
|
|
256
|
+
{
|
|
257
|
+
aliasedType : string // qualified type name being aliased
|
|
258
|
+
}
|
|
259
|
+
|
|
260
|
+
// data of an optional type
|
|
261
|
+
struct OptionalTypeSpec
|
|
262
|
+
{
|
|
263
|
+
type : string // qualified type name
|
|
264
|
+
}
|
|
265
|
+
|
|
266
|
+
struct OptionalTypeSpecV5
|
|
267
|
+
{
|
|
268
|
+
type : string, // qualified type name
|
|
269
|
+
hash : u32 // unique hash
|
|
270
|
+
}
|
|
271
|
+
|
|
272
|
+
struct OptionalTypeSpecV4
|
|
273
|
+
{
|
|
274
|
+
type : string // qualified type name
|
|
275
|
+
}
|
|
276
|
+
|
|
277
|
+
// how to transport information
|
|
278
|
+
enum TransportModeSpec : u8
|
|
279
|
+
{
|
|
280
|
+
unicast, // directed to each receiver, unreliable, unordered, no congestion control
|
|
281
|
+
multicast, // directed to all receivers, unreliable, unordered, no congestion control
|
|
282
|
+
confirmed, // directed to each receiver, reliable, ordered, with congestion control, relatively heavyweight
|
|
283
|
+
}
|
|
284
|
+
|
|
285
|
+
// an argument of a callable (methods and events)
|
|
286
|
+
struct ArgSpec
|
|
287
|
+
{
|
|
288
|
+
name : string, // argument name
|
|
289
|
+
description : string, // documentation
|
|
290
|
+
type : string // qualified type name of the argument
|
|
291
|
+
}
|
|
292
|
+
|
|
293
|
+
struct ArgSpecV5
|
|
294
|
+
{
|
|
295
|
+
name : string, // argument name
|
|
296
|
+
nameHash : u32, // hash computed with the argument name
|
|
297
|
+
description : string, // documentation
|
|
298
|
+
type : string, // qualified type name of the argument
|
|
299
|
+
hash : u32 // unique hash
|
|
300
|
+
}
|
|
301
|
+
|
|
302
|
+
struct ArgSpecV4
|
|
303
|
+
{
|
|
304
|
+
name : string, // argument name
|
|
305
|
+
description : string, // documentation
|
|
306
|
+
type : string // qualified type name of the argument
|
|
307
|
+
}
|
|
308
|
+
|
|
309
|
+
// list of argument specs
|
|
310
|
+
sequence<ArgSpec> ArgSpecList;
|
|
311
|
+
sequence<ArgSpecV5> ArgSpecListV5;
|
|
312
|
+
sequence<ArgSpecV4> ArgSpecListV4;
|
|
313
|
+
|
|
314
|
+
// spec for an event
|
|
315
|
+
struct EventSpec
|
|
316
|
+
{
|
|
317
|
+
name : string, // name of the type
|
|
318
|
+
description : string, // documentation
|
|
319
|
+
args : ArgSpecList, // arguments
|
|
320
|
+
transportMode : TransportModeSpec, // transport mode
|
|
321
|
+
}
|
|
322
|
+
|
|
323
|
+
struct EventSpecV5
|
|
324
|
+
{
|
|
325
|
+
memberHash : u32, // hash of the class member
|
|
326
|
+
name : string, // name of the type
|
|
327
|
+
description : string, // documentation
|
|
328
|
+
args : ArgSpecListV5, // arguments
|
|
329
|
+
transportMode : TransportModeSpec, // transport mode
|
|
330
|
+
hash : u32 // unique hash
|
|
331
|
+
}
|
|
332
|
+
|
|
333
|
+
struct EventSpecV4
|
|
334
|
+
{
|
|
335
|
+
memberHash : u32, // hash of the class member
|
|
336
|
+
name : string, // name of the type
|
|
337
|
+
description : string, // documentation
|
|
338
|
+
args : ArgSpecListV4, // arguments
|
|
339
|
+
transportMode : TransportModeSpec // transport mode
|
|
340
|
+
}
|
|
341
|
+
|
|
342
|
+
// list of event specs
|
|
343
|
+
sequence<EventSpec> EventSpecList;
|
|
344
|
+
sequence<EventSpecV5> EventSpecListV5;
|
|
345
|
+
sequence<EventSpecV4> EventSpecListV4;
|
|
346
|
+
|
|
347
|
+
// method constness
|
|
348
|
+
enum MethodConstnessSpec : u8
|
|
349
|
+
{
|
|
350
|
+
constant,
|
|
351
|
+
nonConstant,
|
|
352
|
+
}
|
|
353
|
+
|
|
354
|
+
// method property relation
|
|
355
|
+
enum PropertyRelationSpec : u8
|
|
356
|
+
{
|
|
357
|
+
nonPropertyRelated,
|
|
358
|
+
propertyGetter,
|
|
359
|
+
propertySetter
|
|
360
|
+
}
|
|
361
|
+
|
|
362
|
+
// spec for methods
|
|
363
|
+
struct MethodSpec
|
|
364
|
+
{
|
|
365
|
+
name : string, // name of the type
|
|
366
|
+
description : string, // documentation
|
|
367
|
+
args : ArgSpecList, // arguments
|
|
368
|
+
transportMode : TransportModeSpec, // transport mode
|
|
369
|
+
constness : MethodConstnessSpec, // if it changes the state of the object
|
|
370
|
+
deferred : bool, // if the execution of the method is deferred
|
|
371
|
+
returnType : string, // qualified return type name
|
|
372
|
+
propertyRelation : PropertyRelationSpec, // property relation of the method
|
|
373
|
+
localOnly : bool // true if the method can only be called locally
|
|
374
|
+
}
|
|
375
|
+
|
|
376
|
+
struct MethodSpecV5
|
|
377
|
+
{
|
|
378
|
+
memberHash : u32, // hash of the class member
|
|
379
|
+
name : string, // name of the type
|
|
380
|
+
description : string, // documentation
|
|
381
|
+
args : ArgSpecListV5, // arguments
|
|
382
|
+
transportMode : TransportModeSpec, // transport mode
|
|
383
|
+
constness : MethodConstnessSpec, // if it changes the state of the object
|
|
384
|
+
localOnly : bool, // true if the method can only be called locally
|
|
385
|
+
returnTypeId : string, // qualified return type name (empty for none)
|
|
386
|
+
hash : u32 // unique hash
|
|
387
|
+
}
|
|
388
|
+
|
|
389
|
+
struct MethodSpecV4
|
|
390
|
+
{
|
|
391
|
+
memberHash : u32, // hash of the class member
|
|
392
|
+
name : string, // name of the type
|
|
393
|
+
description : string, // documentation
|
|
394
|
+
args : ArgSpecListV4, // arguments
|
|
395
|
+
transportMode : TransportModeSpec, // transport mode
|
|
396
|
+
constness : MethodConstnessSpec, // if it changes the state of the object
|
|
397
|
+
deferred : bool, // true if the method is marked as deferred
|
|
398
|
+
returnTypeId : string // qualified return type name (empty for none)
|
|
399
|
+
}
|
|
400
|
+
|
|
401
|
+
// list of method specs
|
|
402
|
+
sequence<MethodSpec> MethodSpecList;
|
|
403
|
+
sequence<MethodSpecV5> MethodSpecListV5;
|
|
404
|
+
sequence<MethodSpecV4> MethodSpecListV4;
|
|
405
|
+
|
|
406
|
+
// how a property is seen by others
|
|
407
|
+
enum PropertyCategorySpec: u8
|
|
408
|
+
{
|
|
409
|
+
staticRW, // does not change over time, can be set via code and config
|
|
410
|
+
staticRO, // does not change over time, can be set via code
|
|
411
|
+
dynamicRW, // may change over time, can be set from outside
|
|
412
|
+
dynamicRO // may change over time, cannot be set from outside
|
|
413
|
+
}
|
|
414
|
+
|
|
415
|
+
// spec of a property
|
|
416
|
+
struct PropertySpec
|
|
417
|
+
{
|
|
418
|
+
name : string, // name of the type
|
|
419
|
+
description : string, // documentation
|
|
420
|
+
category : PropertyCategorySpec, // category
|
|
421
|
+
type : string, // qualified type name of the property
|
|
422
|
+
transportMode : TransportModeSpec, // how to transport the data
|
|
423
|
+
tags : StringList, // user-defined tags
|
|
424
|
+
checkedSet : bool // if setting the property is checked
|
|
425
|
+
}
|
|
426
|
+
|
|
427
|
+
struct PropertySpecV5
|
|
428
|
+
{
|
|
429
|
+
memberHash : u32, // hash of the class member
|
|
430
|
+
name : string, // name of the type
|
|
431
|
+
description : string, // documentation
|
|
432
|
+
category : PropertyCategorySpec, // category
|
|
433
|
+
type : string, // qualified type name of the property
|
|
434
|
+
transportMode : TransportModeSpec, // how to transport the data
|
|
435
|
+
tags : StringList, // user-defined tags
|
|
436
|
+
hash : u32 // unique hash
|
|
437
|
+
}
|
|
438
|
+
|
|
439
|
+
struct PropertySpecV4
|
|
440
|
+
{
|
|
441
|
+
memberHash : u32, // hash of the class member
|
|
442
|
+
name : string, // name of the type
|
|
443
|
+
description : string, // documentation
|
|
444
|
+
category : PropertyCategorySpec, // category
|
|
445
|
+
type : string, // qualified type name of the property
|
|
446
|
+
transportMode : TransportModeSpec, // how to transport the data
|
|
447
|
+
tags : StringList // user-defined tags
|
|
448
|
+
}
|
|
449
|
+
|
|
450
|
+
// list of property specs
|
|
451
|
+
sequence<PropertySpec> PropertySpecList;
|
|
452
|
+
sequence<PropertySpecV5> PropertySpecListV5;
|
|
453
|
+
sequence<PropertySpecV4> PropertySpecListV4;
|
|
454
|
+
|
|
455
|
+
// spec of a class
|
|
456
|
+
struct ClassTypeSpec
|
|
457
|
+
{
|
|
458
|
+
properties : PropertySpecList,
|
|
459
|
+
methods : MethodSpecList,
|
|
460
|
+
events : EventSpecList,
|
|
461
|
+
constructor : MethodSpec,
|
|
462
|
+
parents : StringList,
|
|
463
|
+
isInterface : bool,
|
|
464
|
+
}
|
|
465
|
+
|
|
466
|
+
struct ClassTypeSpecV5
|
|
467
|
+
{
|
|
468
|
+
properties : PropertySpecListV5,
|
|
469
|
+
methods : MethodSpecListV5,
|
|
470
|
+
events : EventSpecListV5,
|
|
471
|
+
isInterface : bool,
|
|
472
|
+
id : u32,
|
|
473
|
+
constructor : MethodSpecV5,
|
|
474
|
+
parents : StringList,
|
|
475
|
+
hash : u32
|
|
476
|
+
}
|
|
477
|
+
|
|
478
|
+
struct ClassTypeSpecV4
|
|
479
|
+
{
|
|
480
|
+
properties : PropertySpecListV4,
|
|
481
|
+
methods : MethodSpecListV4,
|
|
482
|
+
events : EventSpecListV4,
|
|
483
|
+
isInterface : bool,
|
|
484
|
+
id : u32,
|
|
485
|
+
constructor : MethodSpecV4,
|
|
486
|
+
parents : StringList
|
|
487
|
+
}
|
|
488
|
+
|
|
489
|
+
// all custom types
|
|
490
|
+
variant CustomTypeData
|
|
491
|
+
{
|
|
492
|
+
EnumTypeSpec,
|
|
493
|
+
QuantityTypeSpec,
|
|
494
|
+
SequenceTypeSpec,
|
|
495
|
+
StructTypeSpec,
|
|
496
|
+
VariantTypeSpec,
|
|
497
|
+
AliasTypeSpec,
|
|
498
|
+
OptionalTypeSpec,
|
|
499
|
+
ClassTypeSpec
|
|
500
|
+
}
|
|
501
|
+
|
|
502
|
+
variant CustomTypeDataV5
|
|
503
|
+
{
|
|
504
|
+
EnumTypeSpecV5,
|
|
505
|
+
QuantityTypeSpecV5,
|
|
506
|
+
SequenceTypeSpecV5,
|
|
507
|
+
StructTypeSpecV5,
|
|
508
|
+
VariantTypeSpecV5,
|
|
509
|
+
AliasTypeSpecV5,
|
|
510
|
+
OptionalTypeSpecV5,
|
|
511
|
+
ClassTypeSpecV5
|
|
512
|
+
}
|
|
513
|
+
|
|
514
|
+
variant CustomTypeDataV4
|
|
515
|
+
{
|
|
516
|
+
EnumTypeSpecV4,
|
|
517
|
+
QuantityTypeSpecV4,
|
|
518
|
+
SequenceTypeSpecV4,
|
|
519
|
+
StructTypeSpecV4,
|
|
520
|
+
VariantTypeSpecV4,
|
|
521
|
+
AliasTypeSpecV4,
|
|
522
|
+
OptionalTypeSpecV4,
|
|
523
|
+
ClassTypeSpecV4
|
|
524
|
+
}
|
|
525
|
+
|
|
526
|
+
// spec of a custom type
|
|
527
|
+
struct CustomTypeSpec
|
|
528
|
+
{
|
|
529
|
+
name : string, // name of the type
|
|
530
|
+
qualifiedName : string, // package-qualified name
|
|
531
|
+
description : string, // documentation
|
|
532
|
+
data : CustomTypeData // spec data
|
|
533
|
+
}
|
|
534
|
+
|
|
535
|
+
struct CustomTypeSpecV5
|
|
536
|
+
{
|
|
537
|
+
name : string, // name of the type
|
|
538
|
+
qualifiedName : string, // package-qualified name
|
|
539
|
+
description : string, // documentation
|
|
540
|
+
data : CustomTypeDataV5 // spec data
|
|
541
|
+
}
|
|
542
|
+
|
|
543
|
+
struct CustomTypeSpecV4
|
|
544
|
+
{
|
|
545
|
+
name : string, // name of the type
|
|
546
|
+
qualifiedName : string, // package-qualified name
|
|
547
|
+
description : string, // documentation
|
|
548
|
+
data : CustomTypeDataV4 // spec data
|
|
549
|
+
}
|
|
550
|
+
|
|
551
|
+
// list of custom types
|
|
552
|
+
sequence<CustomTypeSpec> CustomTypeSpecList;
|
|
553
|
+
sequence<CustomTypeSpecV5> CustomTypeSpecListV5;
|
|
554
|
+
sequence<CustomTypeSpecV4> CustomTypeSpecListV4;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
{
|
|
2
|
+
"kernelProtocolVersion": 9,
|
|
3
|
+
"etherProtocolVersion": 2,
|
|
4
|
+
"source": {
|
|
5
|
+
"senVersion": "0.6.0-rc1",
|
|
6
|
+
"note": "Informational only. Runtime compatibility is checked with kernelProtocolVersion and etherProtocolVersion."
|
|
7
|
+
},
|
|
8
|
+
"files": {
|
|
9
|
+
"etherRuntime": "ether/runtime.stl",
|
|
10
|
+
"etherDiscovery": "ether/discovery.stl",
|
|
11
|
+
"kernelBus": "kernel/bus_protocol.stl",
|
|
12
|
+
"kernelBasicTypes": "kernel/basic_types.stl",
|
|
13
|
+
"kernelTypeSpecs": "kernel/type_specs.stl"
|
|
14
|
+
}
|
|
15
|
+
}
|
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import fs from 'node:fs';
|
|
3
|
+
import path from 'node:path';
|
|
4
|
+
import { fileURLToPath } from 'node:url';
|
|
5
|
+
|
|
6
|
+
const rootDir = path.resolve(path.dirname(fileURLToPath(import.meta.url)), '..');
|
|
7
|
+
const protocolDir = path.join(rootDir, 'resources', 'protocol');
|
|
8
|
+
const outputFile = path.join(rootDir, 'lib', 'protocol', 'generated.js');
|
|
9
|
+
|
|
10
|
+
const protocol = JSON.parse(fs.readFileSync(path.join(protocolDir, 'protocol.json'), 'utf8'));
|
|
11
|
+
|
|
12
|
+
function readProtocolFile(name) {
|
|
13
|
+
return fs.readFileSync(path.join(protocolDir, protocol.files[name]), 'utf8');
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
function stripComments(source) {
|
|
17
|
+
return source
|
|
18
|
+
.replace(/\/\*[\s\S]*?\*\//g, '')
|
|
19
|
+
.replace(/\/\/.*$/gm, '');
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
function parseBlock(source, keyword, name) {
|
|
23
|
+
const clean = stripComments(source);
|
|
24
|
+
const pattern = new RegExp(`${keyword}\\s+${name}\\s*(?::\\s*\\w+)?\\s*\\{([\\s\\S]*?)\\}`, 'm');
|
|
25
|
+
const match = clean.match(pattern);
|
|
26
|
+
if (!match) {
|
|
27
|
+
throw new Error(`missing ${keyword} ${name}`);
|
|
28
|
+
}
|
|
29
|
+
return match[1]
|
|
30
|
+
.split(',')
|
|
31
|
+
.map(item => item.trim())
|
|
32
|
+
.filter(Boolean);
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
function parseEnum(source, name) {
|
|
36
|
+
return parseBlock(source, 'enum', name);
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
function parseVariant(source, name) {
|
|
40
|
+
return parseBlock(source, 'variant', name);
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
function indexMap(values) {
|
|
44
|
+
return Object.fromEntries(values.map((value, index) => [value, index]));
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
function js(value) {
|
|
48
|
+
return JSON.stringify(value, null, 2);
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
const etherRuntime = readProtocolFile('etherRuntime');
|
|
52
|
+
const kernelBus = readProtocolFile('kernelBus');
|
|
53
|
+
const kernelBasicTypes = readProtocolFile('kernelBasicTypes');
|
|
54
|
+
const kernelTypeSpecs = readProtocolFile('kernelTypeSpecs');
|
|
55
|
+
|
|
56
|
+
const constants = {
|
|
57
|
+
KERNEL_PROTOCOL_VERSION: protocol.kernelProtocolVersion,
|
|
58
|
+
ETHER_PROTOCOL_VERSION: protocol.etherProtocolVersion,
|
|
59
|
+
|
|
60
|
+
ETHER_CONTROL_MESSAGE: parseVariant(etherRuntime, 'ControlMessage'),
|
|
61
|
+
KERNEL_CONTROL_MESSAGE: parseVariant(kernelBus, 'ControlMessage'),
|
|
62
|
+
TYPE_SPEC_RESPONSE: parseVariant(kernelBus, 'TypeSpecResponse'),
|
|
63
|
+
|
|
64
|
+
OS_KIND: parseEnum(kernelBasicTypes, 'OsKind'),
|
|
65
|
+
CPU_ARCH: parseEnum(kernelBasicTypes, 'CpuArch'),
|
|
66
|
+
UNIT_CATEGORY: parseEnum(kernelBasicTypes, 'UnitCat'),
|
|
67
|
+
|
|
68
|
+
INTEGRAL_TYPE: parseEnum(kernelTypeSpecs, 'IntegralType'),
|
|
69
|
+
REAL_TYPE: parseEnum(kernelTypeSpecs, 'RealType'),
|
|
70
|
+
NUMERIC_TYPE: parseVariant(kernelTypeSpecs, 'NumericType'),
|
|
71
|
+
BASIC_TYPE: parseEnum(kernelTypeSpecs, 'BasicType'),
|
|
72
|
+
BUILT_IN_TYPE: parseVariant(kernelTypeSpecs, 'BuiltInType'),
|
|
73
|
+
TRANSPORT_MODE: parseEnum(kernelTypeSpecs, 'TransportModeSpec'),
|
|
74
|
+
METHOD_CONSTNESS: parseEnum(kernelTypeSpecs, 'MethodConstnessSpec'),
|
|
75
|
+
PROPERTY_RELATION: parseEnum(kernelTypeSpecs, 'PropertyRelationSpec'),
|
|
76
|
+
PROPERTY_CATEGORY: parseEnum(kernelTypeSpecs, 'PropertyCategorySpec'),
|
|
77
|
+
CUSTOM_TYPE_DATA: parseVariant(kernelTypeSpecs, 'CustomTypeData')
|
|
78
|
+
};
|
|
79
|
+
|
|
80
|
+
const output = `// Generated by scripts/generate-protocol.mjs from resources/protocol.
|
|
81
|
+
// Do not edit by hand.
|
|
82
|
+
|
|
83
|
+
export const KERNEL_PROTOCOL_VERSION = ${constants.KERNEL_PROTOCOL_VERSION};
|
|
84
|
+
export const ETHER_PROTOCOL_VERSION = ${constants.ETHER_PROTOCOL_VERSION};
|
|
85
|
+
|
|
86
|
+
export const ETHER_CONTROL_MESSAGE = Object.freeze(${js(constants.ETHER_CONTROL_MESSAGE)});
|
|
87
|
+
export const ETHER_CONTROL_MESSAGE_KEY = Object.freeze(${js(indexMap(constants.ETHER_CONTROL_MESSAGE))});
|
|
88
|
+
|
|
89
|
+
export const KERNEL_CONTROL_MESSAGE = Object.freeze(${js(constants.KERNEL_CONTROL_MESSAGE)});
|
|
90
|
+
export const KERNEL_CONTROL_MESSAGE_KEY = Object.freeze(${js(indexMap(constants.KERNEL_CONTROL_MESSAGE))});
|
|
91
|
+
|
|
92
|
+
export const TYPE_SPEC_RESPONSE = Object.freeze(${js(constants.TYPE_SPEC_RESPONSE)});
|
|
93
|
+
|
|
94
|
+
export const OS_KIND = Object.freeze(${js(constants.OS_KIND)});
|
|
95
|
+
export const CPU_ARCH = Object.freeze(${js(constants.CPU_ARCH)});
|
|
96
|
+
export const UNIT_CATEGORY = Object.freeze(${js(constants.UNIT_CATEGORY)});
|
|
97
|
+
|
|
98
|
+
export const INTEGRAL_TYPE = Object.freeze(${js(constants.INTEGRAL_TYPE)});
|
|
99
|
+
export const REAL_TYPE = Object.freeze(${js(constants.REAL_TYPE)});
|
|
100
|
+
export const NUMERIC_TYPE = Object.freeze(${js(constants.NUMERIC_TYPE)});
|
|
101
|
+
export const BASIC_TYPE = Object.freeze(${js(constants.BASIC_TYPE)});
|
|
102
|
+
export const BUILT_IN_TYPE = Object.freeze(${js(constants.BUILT_IN_TYPE)});
|
|
103
|
+
export const TRANSPORT_MODE = Object.freeze(${js(constants.TRANSPORT_MODE)});
|
|
104
|
+
export const METHOD_CONSTNESS = Object.freeze(${js(constants.METHOD_CONSTNESS)});
|
|
105
|
+
export const PROPERTY_RELATION = Object.freeze(${js(constants.PROPERTY_RELATION)});
|
|
106
|
+
export const PROPERTY_CATEGORY = Object.freeze(${js(constants.PROPERTY_CATEGORY)});
|
|
107
|
+
export const CUSTOM_TYPE_DATA = Object.freeze(${js(constants.CUSTOM_TYPE_DATA)});
|
|
108
|
+
`;
|
|
109
|
+
|
|
110
|
+
fs.mkdirSync(path.dirname(outputFile), { recursive: true });
|
|
111
|
+
fs.writeFileSync(outputFile, output);
|