@zzzeros0/nbsp 0.2.1 → 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.
- package/README.md +86 -73
- package/dist/index.d.ts +4 -4
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -2
- package/dist/index.js.map +1 -1
- package/dist/memory.d.ts +6 -6
- package/dist/memory.d.ts.map +1 -1
- package/dist/memory.js +2 -9
- package/dist/memory.js.map +1 -1
- package/dist/structure.d.ts +25 -26
- package/dist/structure.d.ts.map +1 -1
- package/dist/structure.js +24 -27
- package/dist/structure.js.map +1 -1
- package/dist/transformer.d.ts +0 -2
- package/dist/transformer.d.ts.map +1 -1
- package/dist/transformer.js.map +1 -1
- package/dist/type.d.ts +17 -16
- package/dist/type.d.ts.map +1 -1
- package/dist/type.js +1 -1
- package/dist/type.js.map +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -27,27 +27,26 @@ interface AckPacket {
|
|
|
27
27
|
} // domain AckPacket
|
|
28
28
|
|
|
29
29
|
interface Packet {
|
|
30
|
-
header:
|
|
30
|
+
header: byte;
|
|
31
31
|
id: string;
|
|
32
32
|
method: string;
|
|
33
33
|
content: string;
|
|
34
34
|
} // domain Packet
|
|
35
35
|
|
|
36
36
|
// Transformers
|
|
37
|
-
|
|
38
37
|
// Transforms string <-> number[]
|
|
39
38
|
const stringTransform = {
|
|
40
|
-
input: [(data: string) =>
|
|
39
|
+
input: [(data: string) => toBytes(data)],
|
|
41
40
|
output: [(data: bytes) => toString(data)],
|
|
42
41
|
};
|
|
43
42
|
|
|
44
43
|
// Transforms hex string <-> hex number[]
|
|
45
44
|
const hexStringTransform = {
|
|
46
|
-
input: [(data: string) =>
|
|
45
|
+
input: [(data: string) => toBytes(data, true)],
|
|
47
46
|
output: [(data: bytes) => toString(data, true)],
|
|
48
47
|
};
|
|
49
48
|
|
|
50
|
-
const
|
|
49
|
+
const AckPacketStruct = struct<AckPacket, Transformers<AckPacket>>(
|
|
51
50
|
{
|
|
52
51
|
id: charDataType(6),
|
|
53
52
|
},
|
|
@@ -57,9 +56,9 @@ const AckPacketStructure = structure<AckPacket, Transformers<AckPacket>>(
|
|
|
57
56
|
id: hexStringTransform,
|
|
58
57
|
},
|
|
59
58
|
},
|
|
60
|
-
); //
|
|
59
|
+
); // AckPacketStruct Constructor (class)
|
|
61
60
|
|
|
62
|
-
const
|
|
61
|
+
const PacketStruct = struct<Packet, Transformers<Packet>>(
|
|
63
62
|
{
|
|
64
63
|
header: DataType.UINT32LE,
|
|
65
64
|
id: charDataType(6),
|
|
@@ -74,95 +73,95 @@ const PacketStructure = structure<Packet, Transformers<Packet>>(
|
|
|
74
73
|
content: stringTransform,
|
|
75
74
|
},
|
|
76
75
|
},
|
|
77
|
-
); //
|
|
76
|
+
); // PacketStruct Constructor (class)
|
|
78
77
|
|
|
79
|
-
console.log(
|
|
80
|
-
console.log(
|
|
78
|
+
console.log(AckPacketStruct.size); // 6 (Unpacked: 10)
|
|
79
|
+
console.log(PacketStruct.size); // 78 (Unpacked: 128)
|
|
81
80
|
|
|
82
81
|
mqttClient.on("message", (topic, msg) => {
|
|
83
|
-
const packet =
|
|
82
|
+
const packet = PacketStruct.from(msg);
|
|
84
83
|
|
|
85
84
|
processMessage(topic, packet.id, packet.method, packet.content).then(() => {
|
|
86
|
-
const ackMessage =
|
|
85
|
+
const ackMessage = AckPacketStruct.from(msg, sizeof(DataType.UINT32LE)); // Offset the 'header' property
|
|
87
86
|
|
|
88
87
|
mqttClient.publish("ack", ackMessage.data());
|
|
89
88
|
});
|
|
90
89
|
});
|
|
91
90
|
```
|
|
92
91
|
|
|
93
|
-
###
|
|
92
|
+
### Struct Constructor methods
|
|
94
93
|
|
|
95
|
-
| Method | Description | Arguments
|
|
96
|
-
| ------ | ----------------------------------------------------------------- |
|
|
97
|
-
| from | Creates a new instance and copies the buffer content from target. | `(target:
|
|
98
|
-
| toJson | Creates a plain object, resolving with the data of the buffer. |
|
|
94
|
+
| Method | Description | Arguments | Returned type |
|
|
95
|
+
| ------ | ----------------------------------------------------------------- | -------------------------------------------- | ------------- |
|
|
96
|
+
| from | Creates a new instance and copies the buffer content from target. | `(target: Buffer \| Struct, byte: byte = 0)` | `Struct<T>` |
|
|
97
|
+
| toJson | Creates a plain object, resolving with the data of the buffer. | `(target: Buffer, offset: byte = 0)` | T |
|
|
99
98
|
|
|
100
|
-
###
|
|
99
|
+
### Struct methods
|
|
101
100
|
|
|
102
|
-
| Method | Description | Arguments
|
|
103
|
-
| ------ | -------------------------------------- |
|
|
104
|
-
| data | Returns the internal buffer (no copy). |
|
|
105
|
-
| reset | Zero the internal buffer content. |
|
|
106
|
-
| toJson | Returns a plain object. |
|
|
107
|
-
| copy | Copies the buffer content from target. | `(target: Buffer \|
|
|
101
|
+
| Method | Description | Arguments | Returned type |
|
|
102
|
+
| ------ | -------------------------------------- | ---------------------------------------------- | ------------- |
|
|
103
|
+
| data | Returns the internal buffer (no copy). | | `Buffer` |
|
|
104
|
+
| reset | Zero the internal buffer content. | | `void` |
|
|
105
|
+
| toJson | Returns a plain object. | | `T` |
|
|
106
|
+
| copy | Copies the buffer content from target. | `(target: Buffer \| Struct, offset: byte = 0)` | `void` |
|
|
108
107
|
|
|
109
|
-
###
|
|
108
|
+
### Struct Options
|
|
110
109
|
|
|
111
|
-
|
|
110
|
+
Options argument for the `struct` function.
|
|
112
111
|
|
|
113
|
-
| Property | Description
|
|
114
|
-
| --------- |
|
|
115
|
-
| packed | When false, fields of the
|
|
116
|
-
| transform | An object that contains keys from the domain object. Transforms the data obtained from the buffer data.
|
|
112
|
+
| Property | Description | Type | Default |
|
|
113
|
+
| --------- | --------------------------------------------------------------------------------------------------------------------------------------------------------- | ----------------- | ------- |
|
|
114
|
+
| packed | When false, fields of the `struct` are aligned or padded. This is really important especially for binary communications, improving performance and usage. | `boolean` | `false` |
|
|
115
|
+
| transform | An object that contains keys from the domain object. Transforms the data obtained/retrieved from the buffer data. | `Transformers<T>` | `{}` |
|
|
117
116
|
|
|
118
117
|
## Usage
|
|
119
118
|
|
|
120
|
-
1. Create a domain interface.
|
|
121
|
-
|
|
122
|
-
- This will represent your data.
|
|
119
|
+
1. Create a domain interface. This will represent your data.
|
|
123
120
|
|
|
124
121
|
```ts
|
|
125
122
|
interface Person {
|
|
126
|
-
age:
|
|
123
|
+
age: byte;
|
|
127
124
|
name: string;
|
|
128
125
|
} // domain Person
|
|
129
126
|
```
|
|
130
127
|
|
|
131
|
-
2. Create a
|
|
128
|
+
2. Create a Struct for your domain interface. Calling `struct` will return a new class; it is not intended to be extended.
|
|
132
129
|
|
|
133
130
|
```ts
|
|
134
|
-
const
|
|
131
|
+
const PersonStruct = struct<Person>({
|
|
135
132
|
age: DataType.UINT8,
|
|
136
133
|
name: charDataType(4), // strings are arrays of UINT8. charDataType(n) is equivalent to [DataType.UINT8, n]
|
|
137
134
|
});
|
|
138
135
|
```
|
|
139
136
|
|
|
140
|
-
3. Now, you can instantiate the
|
|
137
|
+
3. Now, you can instantiate the struct by using `new` or the `StructConstructor`'s static method `from`. Instance exposes getters and setters to update and retrieve data directly from the fields of the struct in the buffer as well as some other methods to manage it:
|
|
141
138
|
|
|
142
139
|
```ts
|
|
143
|
-
const person1 = new
|
|
140
|
+
const person1 = new PersonStruct({
|
|
144
141
|
age: 24,
|
|
145
|
-
name:
|
|
142
|
+
name: toBytes("Dave"), // Transform the string to UTF-8 UINT8 array
|
|
146
143
|
});
|
|
147
144
|
console.log("Name: %s, age: %d", toString(person1.name), person1.age); // Name: Dave, age: 24
|
|
148
145
|
|
|
149
|
-
const person2 =
|
|
146
|
+
const person2 = PersonStruct.from(Buffer.from("63000000526f7365", "hex"));
|
|
150
147
|
|
|
151
|
-
console.log("Name: %s, age: %d", toString(person2.name), person2.age); // Name: Rose, age:
|
|
148
|
+
console.log("Name: %s, age: %d", toString(person2.name), person2.age); // Name: Rose, age: 99
|
|
152
149
|
|
|
153
|
-
console.log(person2.data()); // <Buffer 52 6f 73 65
|
|
150
|
+
console.log(person2.data()); // <Buffer 63 00 00 00 52 6f 73 65>
|
|
154
151
|
|
|
155
|
-
console.log(person2.toJson()); // { name: [ 82, 111, 115, 101 ]
|
|
152
|
+
console.log(person2.toJson()); // { age: 99, name: [ 82, 111, 115, 101 ] }
|
|
156
153
|
|
|
157
|
-
const person3 =
|
|
154
|
+
const person3 = PersonStruct.toJson(Buffer.from("5a0000004a616b65", "hex"));
|
|
158
155
|
|
|
159
156
|
console.log("Name: %s, age: %d", toString(person3.name), person3.age); // Name: Jake, age: 90
|
|
157
|
+
```
|
|
160
158
|
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
159
|
+
Transformers help to transform data.
|
|
160
|
+
When a property has transformers, its exposed TypeScript type becomes the transformed type instead of the raw BindedType<T>.
|
|
161
|
+
You can have multiple transforms in input/output; each one will receive the last transformed value.
|
|
164
162
|
|
|
165
|
-
|
|
163
|
+
```ts
|
|
164
|
+
const PersonStruct = struct<Person, { name: PropertyTransform }>(
|
|
166
165
|
{
|
|
167
166
|
age: DataType.UINT8,
|
|
168
167
|
name: charDataType(4),
|
|
@@ -171,14 +170,14 @@ const PersonStructure = structure<Person, { name: PropertyTransform }>(
|
|
|
171
170
|
transform: {
|
|
172
171
|
name: {
|
|
173
172
|
// Executed when data is written to the buffer
|
|
174
|
-
input: [(data: string) =>
|
|
173
|
+
input: [(data: string) => toBytes(data)],
|
|
175
174
|
// Executed when data is retrieved from the buffer
|
|
176
175
|
output: [(data: bytes) => toString(data)],
|
|
177
176
|
},
|
|
178
177
|
},
|
|
179
178
|
},
|
|
180
179
|
);
|
|
181
|
-
const person = new
|
|
180
|
+
const person = new PersonStruct({
|
|
182
181
|
age: 24,
|
|
183
182
|
name: "Dave", // Input transformer
|
|
184
183
|
});
|
|
@@ -188,22 +187,22 @@ console.log(person.name); // "Jack", output transformer
|
|
|
188
187
|
|
|
189
188
|
### Arrays & Nesting
|
|
190
189
|
|
|
191
|
-
`
|
|
190
|
+
`Array` types are defined with a `type` and a fixed `length` of items:
|
|
192
191
|
|
|
193
192
|
```ts
|
|
194
|
-
const
|
|
193
|
+
const PersonStruct = struct<Person>({
|
|
195
194
|
name: [DataType.UINT8, 4], // or charDataType(4)
|
|
196
195
|
});
|
|
197
196
|
```
|
|
198
197
|
|
|
199
|
-
> Strings are represented as a fixed array of `UINT8` if no transformer was applied for that property.
|
|
198
|
+
> Strings are represented as a fixed array of `UINT8` if no transformer was applied for that property. Use the shorthand `charDataType`.
|
|
200
199
|
|
|
201
|
-
You can nest `
|
|
200
|
+
You can nest `Structs`:
|
|
202
201
|
|
|
203
202
|
```ts
|
|
204
203
|
interface DeviceConfig {
|
|
205
|
-
mode:
|
|
206
|
-
factor:
|
|
204
|
+
mode: byte;
|
|
205
|
+
factor: byte;
|
|
207
206
|
} // domain DeviceConfig
|
|
208
207
|
|
|
209
208
|
interface Device {
|
|
@@ -211,45 +210,45 @@ interface Device {
|
|
|
211
210
|
config: DeviceConfig; // Provide the domain type
|
|
212
211
|
} // domain Device
|
|
213
212
|
|
|
214
|
-
const
|
|
213
|
+
const DeviceConfigStruct = struct<DeviceConfig>({
|
|
215
214
|
mode: DataType.UINT8,
|
|
216
215
|
factor: DataType.UINT8,
|
|
217
216
|
});
|
|
218
217
|
|
|
219
|
-
const
|
|
218
|
+
const DeviceStruct = struct<Device>({
|
|
220
219
|
id: charDataType(6),
|
|
221
|
-
config:
|
|
220
|
+
config: DeviceConfigStruct, // Provide the struct as type
|
|
222
221
|
});
|
|
223
222
|
|
|
224
|
-
const instance = new
|
|
223
|
+
const instance = new DeviceStruct({
|
|
225
224
|
id: Array.from(randomBytes(6)),
|
|
226
225
|
config: {
|
|
227
226
|
// Create a plain object
|
|
228
|
-
// DO NOT use
|
|
227
|
+
// DO NOT use DeviceConfigStruct constructor
|
|
229
228
|
// it will cause unnecessary allocations
|
|
230
229
|
mode: 4,
|
|
231
230
|
factor: 8,
|
|
232
231
|
},
|
|
233
232
|
});
|
|
234
233
|
|
|
235
|
-
console.log(instance.config.factor); //
|
|
234
|
+
console.log(instance.config.factor); // 8
|
|
236
235
|
```
|
|
237
236
|
|
|
238
|
-
You can also store `
|
|
237
|
+
You can also store `Structs` or `Arrays` inside of `Arrays`:
|
|
239
238
|
|
|
240
239
|
```ts
|
|
241
240
|
interface Group {
|
|
242
241
|
people: Person[];
|
|
243
242
|
} // domain Group
|
|
244
243
|
|
|
245
|
-
const
|
|
246
|
-
people: [
|
|
244
|
+
const GroupStruct = struct<Group>({
|
|
245
|
+
people: [PersonStruct, 100],
|
|
247
246
|
});
|
|
248
247
|
|
|
249
|
-
const groupInstance = new
|
|
248
|
+
const groupInstance = new GroupStruct({
|
|
250
249
|
people: [
|
|
251
250
|
// Create a plain object
|
|
252
|
-
// DO NOT use
|
|
251
|
+
// DO NOT use PersonStruct constructor
|
|
253
252
|
// it will cause unnecessary allocations
|
|
254
253
|
{
|
|
255
254
|
name: "Jack",
|
|
@@ -269,11 +268,11 @@ console.log(groupInstance.people); // Array<100> [ { name: [Getter/Setter] }, ..
|
|
|
269
268
|
|
|
270
269
|
> **Important**
|
|
271
270
|
>
|
|
272
|
-
>
|
|
271
|
+
> Structs must be instantiated with plain objects when are nested, `do not` use the `Struct's constructor`; doing so will make unnecessary allocations.
|
|
273
272
|
|
|
274
273
|
### JSON
|
|
275
274
|
|
|
276
|
-
Instances can be converted to plain JavaScript object with all the resolved properties and nested attributes of your
|
|
275
|
+
Instances can be converted to plain JavaScript object with all the resolved properties and nested attributes of your struct using `toJson` method:
|
|
277
276
|
|
|
278
277
|
```ts
|
|
279
278
|
personInstance.toJson(); // { name: [ 68, 97, 118, 101 ], age: 24 }
|
|
@@ -282,17 +281,19 @@ personInstance.toJson(); // { name: [ 68, 97, 118, 101 ], age: 24 }
|
|
|
282
281
|
You can serialize directly to a plain JavaScript object from a buffer by using the static method `toJson`:
|
|
283
282
|
|
|
284
283
|
```ts
|
|
285
|
-
|
|
284
|
+
PersonStruct.toJson(Buffer.from("4a616b655a000000", "hex")); // { name: [ 68, 97, 118, 101 ], age: 24 }
|
|
286
285
|
```
|
|
287
286
|
|
|
288
287
|
> **Important**
|
|
289
288
|
>
|
|
290
289
|
> Transformers will also run when serializing JSON.
|
|
291
290
|
|
|
292
|
-
> Prefer the static `toJson` when working with raw buffers; there's no point on doing this:
|
|
291
|
+
> Prefer the static `toJson` method when working with raw buffers; there's no point on doing this:
|
|
293
292
|
>
|
|
294
293
|
> ```ts
|
|
295
|
-
>
|
|
294
|
+
> PersonStruct.toJson(personInstance.data());
|
|
295
|
+
> // Instead
|
|
296
|
+
> personInstance.toJson();
|
|
296
297
|
> ```
|
|
297
298
|
|
|
298
299
|
### Endianness
|
|
@@ -306,6 +307,16 @@ structure({
|
|
|
306
307
|
});
|
|
307
308
|
```
|
|
308
309
|
|
|
310
|
+
> **Note**
|
|
311
|
+
>
|
|
312
|
+
> You can get the `size` of data types with `sizeof`:
|
|
313
|
+
>
|
|
314
|
+
> ```ts
|
|
315
|
+
> console.log(sizeof(DataType.INT16LE)); // 2
|
|
316
|
+
> console.log(sizeof(charDataType(6))); // 6
|
|
317
|
+
> console.log(sizeof(Structure)); // Or Structure.size
|
|
318
|
+
> ```
|
|
319
|
+
|
|
309
320
|
### Floating point (FLOAT32) precision
|
|
310
321
|
|
|
311
322
|
NBSP uses IEEE-754 floating point representations for FLOAT32 and FLOAT64, exactly like C, C++, Rust, Java, etc.
|
|
@@ -344,7 +355,9 @@ NBSP intentionally exposes the real binary value, without rounding or post-proce
|
|
|
344
355
|
|
|
345
356
|
If you need to compare floating point values, never use strict equality:
|
|
346
357
|
|
|
347
|
-
|
|
358
|
+
```ts
|
|
359
|
+
a === b; // ❌ unsafe for floats
|
|
360
|
+
```
|
|
348
361
|
|
|
349
362
|
Instead, compare with a tolerance:
|
|
350
363
|
|
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
export { toString,
|
|
2
|
-
export {
|
|
3
|
-
export { charDataType, DataType, type ArrayDataType, type BigIntDataType, type BindedType, type DataValue, type DomainObject, type NumericArrayDataType, type
|
|
4
|
-
export { type Transformer, type Transformers, type ApplyTransformers, type
|
|
1
|
+
export { toString, toBytes, sizeof } from "./memory.js";
|
|
2
|
+
export { struct, type Struct, type StructConstructor, type StructFields, type StructMethods, type StructReturn, } from "./structure.js";
|
|
3
|
+
export { charDataType, DataType, type ArrayDataType, type BigIntDataType, type BindedType, type DataValue, type DomainObject, type NumericArrayDataType, type StructArrayDataType, type StructDefinitionDataType, type Type, type byte, type bytes, } from "./type.js";
|
|
4
|
+
export { type Transformer, type Transformers, type ApplyTransformers, type PropertyTransformer, } from "./transformer.js";
|
|
5
5
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AACxD,OAAO,EACL,MAAM,EACN,KAAK,MAAM,EACX,KAAK,iBAAiB,EACtB,KAAK,YAAY,EACjB,KAAK,aAAa,EAClB,KAAK,YAAY,GAClB,MAAM,gBAAgB,CAAC;AACxB,OAAO,EACL,YAAY,EACZ,QAAQ,EACR,KAAK,aAAa,EAClB,KAAK,cAAc,EACnB,KAAK,UAAU,EACf,KAAK,SAAS,EACd,KAAK,YAAY,EACjB,KAAK,oBAAoB,EACzB,KAAK,mBAAmB,EACxB,KAAK,wBAAwB,EAC7B,KAAK,IAAI,EACT,KAAK,IAAI,EACT,KAAK,KAAK,GACX,MAAM,WAAW,CAAC;AACnB,OAAO,EACL,KAAK,WAAW,EAChB,KAAK,YAAY,EACjB,KAAK,iBAAiB,EACtB,KAAK,mBAAmB,GACzB,MAAM,kBAAkB,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
export { toString,
|
|
2
|
-
export {
|
|
1
|
+
export { toString, toBytes, sizeof } from "./memory.js";
|
|
2
|
+
export { struct, } from "./structure.js";
|
|
3
3
|
export { charDataType, DataType, } from "./type.js";
|
|
4
4
|
export {} from "./transformer.js";
|
|
5
5
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AACxD,OAAO,EACL,MAAM,GAMP,MAAM,gBAAgB,CAAC;AACxB,OAAO,EACL,YAAY,EACZ,QAAQ,GAYT,MAAM,WAAW,CAAC;AACnB,OAAO,EAKN,MAAM,kBAAkB,CAAC"}
|
package/dist/memory.d.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { type AlignedData, type bytes, type Type } from "./type.js";
|
|
2
|
-
export declare function alloc(s:
|
|
3
|
-
export declare function read(data: AlignedData, buffer: Buffer, offset:
|
|
4
|
-
export declare function write(data: AlignedData, buffer: Buffer, value:
|
|
5
|
-
export declare function sizeof(type: Type):
|
|
6
|
-
export declare function
|
|
1
|
+
import { type AlignedData, type byte, type bytes, type Type } from "./type.js";
|
|
2
|
+
export declare function alloc(s: byte): Buffer<ArrayBuffer>;
|
|
3
|
+
export declare function read(data: AlignedData, buffer: Buffer, offset: byte): number | bigint;
|
|
4
|
+
export declare function write(data: AlignedData, buffer: Buffer, value: byte, offset: byte): void;
|
|
5
|
+
export declare function sizeof(type: Type): byte;
|
|
6
|
+
export declare function toBytes(s: string, hex?: boolean): bytes;
|
|
7
7
|
export declare function toString(n: bytes, hex?: boolean): string;
|
|
8
8
|
//# sourceMappingURL=memory.d.ts.map
|
package/dist/memory.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"memory.d.ts","sourceRoot":"","sources":["../src/memory.ts"],"names":[],"mappings":"AACA,OAAO,EAEL,KAAK,WAAW,EAEhB,KAAK,KAAK,EACV,KAAK,IAAI,EACV,MAAM,WAAW,CAAC;AA8BnB,wBAAgB,KAAK,CAAC,CAAC,EAAE,
|
|
1
|
+
{"version":3,"file":"memory.d.ts","sourceRoot":"","sources":["../src/memory.ts"],"names":[],"mappings":"AACA,OAAO,EAEL,KAAK,WAAW,EAEhB,KAAK,IAAI,EACT,KAAK,KAAK,EACV,KAAK,IAAI,EACV,MAAM,WAAW,CAAC;AA8BnB,wBAAgB,KAAK,CAAC,CAAC,EAAE,IAAI,uBAE5B;AAED,wBAAgB,IAAI,CAAC,IAAI,EAAE,WAAW,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,IAAI,mBAyCnE;AAED,wBAAgB,KAAK,CACnB,IAAI,EAAE,WAAW,EACjB,MAAM,EAAE,MAAM,EACd,KAAK,EAAE,IAAI,EACX,MAAM,EAAE,IAAI,GACX,IAAI,CAqFN;AAsCD,wBAAgB,MAAM,CAAC,IAAI,EAAE,IAAI,GAAG,IAAI,CAQvC;AAsBD,wBAAgB,OAAO,CAAC,CAAC,EAAE,MAAM,EAAE,GAAG,GAAE,OAAe,GAAG,KAAK,CAI9D;AACD,wBAAgB,QAAQ,CAAC,CAAC,EAAE,KAAK,EAAE,GAAG,GAAE,OAAe,GAAG,MAAM,CAK/D"}
|
package/dist/memory.js
CHANGED
|
@@ -19,12 +19,9 @@ function assertBigIntRange(value, min, max, type) {
|
|
|
19
19
|
}
|
|
20
20
|
}
|
|
21
21
|
export function alloc(s) {
|
|
22
|
-
// console.log("Alloc", s);
|
|
23
22
|
return Buffer.alloc(s);
|
|
24
23
|
}
|
|
25
24
|
export function read(data, buffer, offset) {
|
|
26
|
-
// console.log("read", data, offset + data.offset);
|
|
27
|
-
// if (typeof data.type === "number") {
|
|
28
25
|
switch (data.type) {
|
|
29
26
|
case DataType.INT8:
|
|
30
27
|
return buffer.readInt8(offset + data.offset);
|
|
@@ -67,10 +64,6 @@ export function read(data, buffer, offset) {
|
|
|
67
64
|
}
|
|
68
65
|
}
|
|
69
66
|
export function write(data, buffer, value, offset) {
|
|
70
|
-
// console.log("Write", data.offset + offset, value);
|
|
71
|
-
// if (typeof data.type === "number") {
|
|
72
|
-
// if (Array.isArray(value) || typeof value !== "number")
|
|
73
|
-
// throw new Error("Invalid value");
|
|
74
67
|
switch (data.type) {
|
|
75
68
|
case DataType.INT8:
|
|
76
69
|
assertInteger(value, -128, 127, "INT8");
|
|
@@ -207,7 +200,7 @@ function hexToBytes(hex) {
|
|
|
207
200
|
return bytes;
|
|
208
201
|
}
|
|
209
202
|
function bytesToHex(bytes) {
|
|
210
|
-
|
|
203
|
+
const hex = [];
|
|
211
204
|
for (let i = 0; i < bytes.length; i++) {
|
|
212
205
|
const byte = bytes[i];
|
|
213
206
|
if (byte == undefined)
|
|
@@ -218,7 +211,7 @@ function bytesToHex(bytes) {
|
|
|
218
211
|
}
|
|
219
212
|
return hex.join("");
|
|
220
213
|
}
|
|
221
|
-
export function
|
|
214
|
+
export function toBytes(s, hex = false) {
|
|
222
215
|
if (hex)
|
|
223
216
|
return hexToBytes(s);
|
|
224
217
|
if (!encoder)
|
package/dist/memory.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"memory.js","sourceRoot":"","sources":["../src/memory.ts"],"names":[],"mappings":"AACA,OAAO,EACL,QAAQ,
|
|
1
|
+
{"version":3,"file":"memory.js","sourceRoot":"","sources":["../src/memory.ts"],"names":[],"mappings":"AACA,OAAO,EACL,QAAQ,GAMT,MAAM,WAAW,CAAC;AAEnB,IAAI,OAAoB,EAAE,OAAo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tB,CAAC;AAED,MAAM,UAAU,OAAO,CAAC,CAAS,EAAE,MAAe,KAAK;IACrD,IAAI,GAAG;QAAE,OAAO,UAAU,CAAC,CAAC,CAAC,CAAC;IAC9B,IAAI,CAAC,OAAO;QAAE,OAAO,GAAG,IAAI,WAAW,EAAE,CAAC,CAAC,oBAAoB;IAC/D,OAAO,KAAK,CAAC,IAAI,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,CAAC;AACvC,CAAC;AACD,MAAM,UAAU,QAAQ,CAAC,CAAQ,EAAE,MAAe,KAAK;IACrD,4BAA4B;IAC5B,IAAI,GAAG;QAAE,OAAO,UAAU,CAAC,CAAC,CAAC,CAAC;IAC9B,IAAI,CAAC,OAAO;QAAE,OAAO,GAAG,IAAI,WAAW,EAAE,CAAC;IAC1C,OAAO,OAAO,CAAC,MAAM,CAAC,IAAI,UAAU,CAAC,CAAC,CAAC,CAAC,CAAC;AAC3C,CAAC"}
|
package/dist/structure.d.ts
CHANGED
|
@@ -1,75 +1,74 @@
|
|
|
1
1
|
import type { Transformers } from "./transformer.js";
|
|
2
2
|
import { type ApplyTransformers } from "./transformer.js";
|
|
3
|
-
import { type AlignedData, type BindedType, type DomainObject, type
|
|
4
|
-
export type
|
|
3
|
+
import { type AlignedData, type BindedType, type byte, type DomainObject, type StructDefinitionDataType, type Type } from "./type.js";
|
|
4
|
+
export type StructFields<T extends DomainObject> = {
|
|
5
5
|
[K in keyof Record<keyof T, Type>]: AlignedData;
|
|
6
6
|
};
|
|
7
|
-
interface
|
|
7
|
+
interface StructStaticMethods<T extends DomainObject> {
|
|
8
8
|
/**
|
|
9
9
|
* Copys the contents of the buffer. Returns a new Instance.
|
|
10
10
|
* @param buffer
|
|
11
11
|
*/
|
|
12
|
-
from(buffer: Buffer, offset?:
|
|
12
|
+
from(buffer: Buffer, offset?: byte): Struct<T>;
|
|
13
13
|
/**
|
|
14
14
|
* Copys the contents of the instance's buffer. Returns a new instance.
|
|
15
15
|
* @param buffer
|
|
16
16
|
*/
|
|
17
|
-
from(
|
|
17
|
+
from(struct: Struct<BindedType<T>>, offset?: byte, length?: byte): Struct<T>;
|
|
18
18
|
/**
|
|
19
19
|
* Serializes the buffer directly to a plain object
|
|
20
20
|
* @param buffer
|
|
21
21
|
*/
|
|
22
22
|
toJson(buffer: Buffer): T;
|
|
23
23
|
}
|
|
24
|
-
export interface
|
|
24
|
+
export interface StructConstructor<T extends DomainObject = DomainObject> extends StructStaticMethods<T> {
|
|
25
25
|
/**
|
|
26
|
-
* The size of the
|
|
26
|
+
* The size of the struct
|
|
27
27
|
*/
|
|
28
|
-
readonly size:
|
|
28
|
+
readonly size: byte;
|
|
29
29
|
/**
|
|
30
|
-
* The fields of the
|
|
30
|
+
* The fields of the struct
|
|
31
31
|
*/
|
|
32
|
-
readonly fields:
|
|
32
|
+
readonly fields: StructFields<T>;
|
|
33
33
|
/**
|
|
34
34
|
* The transformers
|
|
35
35
|
*/
|
|
36
36
|
readonly transform: Transformers<T>;
|
|
37
|
-
new (args: T):
|
|
37
|
+
new (args: T): Struct<T>;
|
|
38
38
|
}
|
|
39
|
-
export interface
|
|
39
|
+
export interface StructMethods<T extends DomainObject> {
|
|
40
40
|
/**
|
|
41
|
-
*
|
|
42
|
-
* @param buffer
|
|
41
|
+
* Returns the buffer
|
|
43
42
|
*/
|
|
44
|
-
|
|
43
|
+
data(): Buffer;
|
|
45
44
|
/**
|
|
46
|
-
* Copies the contents of the
|
|
45
|
+
* Copies the contents of the buffer
|
|
47
46
|
* @param buffer
|
|
48
47
|
*/
|
|
49
|
-
copy(
|
|
48
|
+
copy(buffer: Buffer, offset?: byte): void;
|
|
50
49
|
/**
|
|
51
|
-
*
|
|
50
|
+
* Copies the contents of the struct buffer
|
|
51
|
+
* @param buffer
|
|
52
52
|
*/
|
|
53
|
-
|
|
53
|
+
copy(struct: Struct<T>, offset?: byte): void;
|
|
54
54
|
/**
|
|
55
55
|
* Sets the contents of the buffer to 0
|
|
56
56
|
*/
|
|
57
57
|
reset(): void;
|
|
58
58
|
/**
|
|
59
|
-
* Returns a plain object with the content of the
|
|
59
|
+
* Returns a plain object with the content of the struct
|
|
60
60
|
*/
|
|
61
61
|
toJson(): T;
|
|
62
62
|
}
|
|
63
|
-
export type
|
|
63
|
+
export type StructOptions<T extends DomainObject, TR extends Transformers<T> | undefined> = TR extends undefined ? {
|
|
64
64
|
packed?: boolean;
|
|
65
|
-
tranform?: undefined;
|
|
66
65
|
} : {
|
|
67
66
|
packed?: boolean;
|
|
68
67
|
transform?: TR;
|
|
69
68
|
};
|
|
70
|
-
export type
|
|
71
|
-
export type
|
|
72
|
-
export declare function
|
|
73
|
-
export declare function
|
|
69
|
+
export type Struct<T extends DomainObject> = T & StructMethods<T>;
|
|
70
|
+
export type StructReturn<T extends DomainObject, TR extends Transformers<T> | undefined> = StructConstructor<ApplyTransformers<T, BindedType<T>, TR>>;
|
|
71
|
+
export declare function struct<T extends DomainObject>(data: StructDefinitionDataType<T>, opts?: StructOptions<T, undefined>): StructConstructor<BindedType<T>>;
|
|
72
|
+
export declare function struct<T extends DomainObject, TR extends Transformers<T>>(data: StructDefinitionDataType<T>, opts?: StructOptions<T, TR>): StructReturn<T, TR>;
|
|
74
73
|
export {};
|
|
75
74
|
//# sourceMappingURL=structure.d.ts.map
|
package/dist/structure.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"structure.d.ts","sourceRoot":"","sources":["../src/structure.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAuB,YAAY,EAAE,MAAM,kBAAkB,CAAC;AAC1E,OAAO,EAAkB,KAAK,iBAAiB,EAAE,MAAM,kBAAkB,CAAC;AAC1E,OAAO,EAIL,KAAK,WAAW,EAEhB,KAAK,UAAU,
|
|
1
|
+
{"version":3,"file":"structure.d.ts","sourceRoot":"","sources":["../src/structure.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAuB,YAAY,EAAE,MAAM,kBAAkB,CAAC;AAC1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AE,aAAa,CAAC,CAAC,EAAE,EAAE,CAAC,GAC1B,YAAY,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC"}
|
package/dist/structure.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { alloc, read, write, sizeof } from "./memory.js";
|
|
2
2
|
import { applyTransform } from "./transformer.js";
|
|
3
|
-
import { DataType, isArrayDataType,
|
|
3
|
+
import { DataType, isArrayDataType, isStructDataType, } from "./type.js";
|
|
4
4
|
function alignUp(n, align) {
|
|
5
5
|
return (n + align - 1) & ~(align - 1);
|
|
6
6
|
}
|
|
@@ -29,7 +29,7 @@ function alignFields(data, packed = false) {
|
|
|
29
29
|
return { fields: Object.freeze(fields), size: structSize };
|
|
30
30
|
}
|
|
31
31
|
function defineProxyProperty(target, key, field, buffer, transformer, offset = 0) {
|
|
32
|
-
const isStructField =
|
|
32
|
+
const isStructField = isStructDataType(field.type);
|
|
33
33
|
const isArrayField = isArrayDataType(field.type);
|
|
34
34
|
Object.defineProperty(target, key, {
|
|
35
35
|
get() {
|
|
@@ -44,7 +44,7 @@ function defineProxyProperty(target, key, field, buffer, transformer, offset = 0
|
|
|
44
44
|
},
|
|
45
45
|
set(v) {
|
|
46
46
|
if (isStructField)
|
|
47
|
-
return
|
|
47
|
+
return writeStruct(field, buffer, applyTransform(transformer?.input, v), offset);
|
|
48
48
|
else if (isArrayField)
|
|
49
49
|
writeArray(field, applyTransform(transformer?.input, v), buffer, offset);
|
|
50
50
|
else
|
|
@@ -52,13 +52,12 @@ function defineProxyProperty(target, key, field, buffer, transformer, offset = 0
|
|
|
52
52
|
},
|
|
53
53
|
});
|
|
54
54
|
}
|
|
55
|
-
function
|
|
56
|
-
console.log("Write structure", data, offset, value);
|
|
55
|
+
function writeStruct(data, buffer, value, offset) {
|
|
57
56
|
for (const [k, field] of Object.entries(data.type.fields)) {
|
|
58
57
|
const transformer = data.type.transform[k];
|
|
59
58
|
const val = applyTransform(transformer?.input, value[k]);
|
|
60
|
-
if (
|
|
61
|
-
|
|
59
|
+
if (isStructDataType(field.type)) {
|
|
60
|
+
writeStruct(field, buffer, val, offset + data.offset);
|
|
62
61
|
}
|
|
63
62
|
else if (Array.isArray(field.type)) {
|
|
64
63
|
writeArray(field, val, buffer, offset + data.offset);
|
|
@@ -69,14 +68,14 @@ function writeStructure(data, buffer, value, offset) {
|
|
|
69
68
|
}
|
|
70
69
|
function writeArray(data, arr, buffer, offset) {
|
|
71
70
|
const [type, length] = data.type;
|
|
72
|
-
const
|
|
71
|
+
const isStruct = isStructDataType(type);
|
|
73
72
|
const size = sizeof(type);
|
|
74
73
|
if (arr.length !== length)
|
|
75
74
|
throw new RangeError("Invalid array length");
|
|
76
75
|
for (let i = 0; i < length; i++) {
|
|
77
76
|
const value = arr[i];
|
|
78
|
-
if (
|
|
79
|
-
|
|
77
|
+
if (isStruct) {
|
|
78
|
+
writeStruct({
|
|
80
79
|
offset: i * size,
|
|
81
80
|
size: size,
|
|
82
81
|
type,
|
|
@@ -102,11 +101,11 @@ function readArray(data, buffer, offset = 0, mutable = true) {
|
|
|
102
101
|
const t = [];
|
|
103
102
|
const [type, length] = data.type;
|
|
104
103
|
const size = sizeof(type);
|
|
105
|
-
const
|
|
104
|
+
const isStruct = isStructDataType(type);
|
|
106
105
|
const isArray = isArrayDataType(type);
|
|
107
106
|
for (let i = 0; i < length; i++) {
|
|
108
|
-
if (
|
|
109
|
-
t.push(
|
|
107
|
+
if (isStruct) {
|
|
108
|
+
t.push(readStruct({
|
|
110
109
|
type,
|
|
111
110
|
offset: i * type.size,
|
|
112
111
|
size: type.size,
|
|
@@ -129,15 +128,15 @@ function readArray(data, buffer, offset = 0, mutable = true) {
|
|
|
129
128
|
}
|
|
130
129
|
return t;
|
|
131
130
|
}
|
|
132
|
-
function
|
|
131
|
+
function readStruct(data, buffer, offset = 0, mutable = true) {
|
|
133
132
|
const t = {};
|
|
134
133
|
for (const [k, field] of Object.entries(data.type.fields)) {
|
|
135
134
|
const transformer = data.type.transform[k];
|
|
136
135
|
if (mutable)
|
|
137
136
|
defineProxyProperty(t, k, field, buffer, data.type.transform[k], data.offset + offset);
|
|
138
137
|
else {
|
|
139
|
-
if (
|
|
140
|
-
t[k] = applyTransform(transformer?.output,
|
|
138
|
+
if (isStructDataType(field.type)) {
|
|
139
|
+
t[k] = applyTransform(transformer?.output, readStruct(field, buffer, data.offset + offset, mutable));
|
|
141
140
|
}
|
|
142
141
|
else if (isArrayDataType(field.type)) {
|
|
143
142
|
t[k] = applyTransform(transformer?.output, readArray(field, buffer, data.offset + offset, mutable));
|
|
@@ -155,7 +154,7 @@ function construct(target, fields, transformers, args, buffer, offset = 0, write
|
|
|
155
154
|
const transformer = transformers[k];
|
|
156
155
|
const val = arg ? applyTransform(transformer?.input, arg) : arg;
|
|
157
156
|
if (writeData) {
|
|
158
|
-
if (
|
|
157
|
+
if (isStructDataType(field.type)) {
|
|
159
158
|
target[k] = {};
|
|
160
159
|
construct(target[k], field.type.fields, field.type.transform, arg ?? {}, buffer, offset + field.offset, writeData);
|
|
161
160
|
continue;
|
|
@@ -168,17 +167,15 @@ function construct(target, fields, transformers, args, buffer, offset = 0, write
|
|
|
168
167
|
write(field, buffer, val, offset);
|
|
169
168
|
}
|
|
170
169
|
}
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
construct(target[k], field.type.fields, field.type.transform, val ?? {}, buffer, offset + field.offset, writeData);
|
|
175
|
-
}
|
|
176
|
-
else
|
|
177
|
-
defineProxyProperty(target, k, field, buffer, transformer, offset);
|
|
170
|
+
if (isStructDataType(field.type)) {
|
|
171
|
+
target[k] = {};
|
|
172
|
+
construct(target[k], field.type.fields, field.type.transform, val ?? {}, buffer, offset + field.offset, writeData);
|
|
178
173
|
}
|
|
174
|
+
else
|
|
175
|
+
defineProxyProperty(target, k, field, buffer, transformer, offset);
|
|
179
176
|
}
|
|
180
177
|
}
|
|
181
|
-
export function
|
|
178
|
+
export function struct(data, opts) {
|
|
182
179
|
const transformers = opts?.transform ?? {};
|
|
183
180
|
const { fields, size } = alignFields(data, opts?.packed);
|
|
184
181
|
let writeData = true;
|
|
@@ -206,7 +203,7 @@ export function structure(data, opts) {
|
|
|
206
203
|
static toJson(buffer) {
|
|
207
204
|
if (buffer.length < size)
|
|
208
205
|
throw new Error("Invalid buffer size");
|
|
209
|
-
return
|
|
206
|
+
return readStruct({
|
|
210
207
|
type: this,
|
|
211
208
|
offset: 0,
|
|
212
209
|
size,
|
|
@@ -231,7 +228,7 @@ export function structure(data, opts) {
|
|
|
231
228
|
this.__buff__.fill(0);
|
|
232
229
|
}
|
|
233
230
|
toJson() {
|
|
234
|
-
return
|
|
231
|
+
return readStruct({
|
|
235
232
|
type: t,
|
|
236
233
|
offset: 0,
|
|
237
234
|
size,
|
package/dist/structure.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"structure.js","sourceRoot":"","sources":["../src/structure.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,IAAI,EAAE,KAAK,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AAEzD,OAAO,EAAE,cAAc,EAA0B,MAAM,kBAAkB,CAAC;AAC1E,OAAO,EACL,QAAQ,EACR,eAAe,EACf,
|
|
1
|
+
{"version":3,"file":"structure.js","sourceRoot":"","sources":["../src/structure.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,IAAI,EAAE,KAAK,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AAEzD,OAAO,EAAE,cAAc,EAA0B,MAAM,kBAAkB,CAAC;AAC1E,OAAO,EACL,QAAQ,EACR,eAAe,EACf,gBAAgB,GASjB,MAAM,WAAW,CAAC;AAiFnB,SAAS,OAAO,CAAC,CAAO,EAAE,KAAW;IACnC,OAAO,CAAC,CAAC,GAAG,KAAK,GAAG,CAAC,CAAC,GAAG,CAAC,CAAC,KAAK,GAAG,CAAC,CAAC,CAAC;AACxC,CAAC;AACD,SAAS,WAAW,CA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IAAI,CAAC;QACnB,CAAC;QAGM,IAAI,CAAC,MAAW,EAAE,SAAe,CAAC;YACvC,IAAI,MAAM,YAAY,MAAM,EAAE,CAAC;gBAC7B,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,QAAQ,EAAE,CAAC,EAAE,MAAM,EAAE,MAAM,GAAG,IAAI,CAAC,CAAC;gBACrD,OAAO;YACT,CAAC;;gBAAM,MAAM,CAAC,IAAI,EAAE,CAAC,IAAI,CAAC,IAAI,CAAC,QAAQ,EAAE,CAAC,EAAE,MAAM,EAAE,MAAM,GAAG,IAAI,CAAC,CAAC;QACrE,CAAC;QACM,IAAI;YACT,OAAO,IAAI,CAAC,QAAQ,CAAC;QACvB,CAAC;QACM,KAAK;YACV,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;QACxB,CAAC;QACM,MAAM;YACX,OAAO,UAAU,CACf;gBACE,IAAI,EAAE,CAAsB;gBAC5B,MAAM,EAAE,CAAC;gBACT,IAAI;aACL,EACD,IAAI,CAAC,QAAQ,EACb,CAAC,EACD,KAAK,CACN,CAAC;QACJ,CAAC;KAC6B,CAAC;IACjC,OAAO,CAAC,CAAC;AACX,CAAC"}
|
package/dist/transformer.d.ts
CHANGED
|
@@ -1,7 +1,5 @@
|
|
|
1
1
|
import type { BindedType, DomainObject } from "./type.js";
|
|
2
2
|
export type Transformer<T, R> = (data: T) => R;
|
|
3
|
-
export type InputTransformer = Transformer<any, any>;
|
|
4
|
-
export type OuputTransformer<T> = Transformer<any, T>;
|
|
5
3
|
export interface PropertyTransformer {
|
|
6
4
|
readonly input?: Transformer<any, any>[];
|
|
7
5
|
readonly output?: Transformer<any, any>[];
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"transformer.d.ts","sourceRoot":"","sources":["../src/transformer.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAa,YAAY,EAAE,MAAM,WAAW,CAAC;AAErE,MAAM,MAAM,WAAW,CAAC,CAAC,EAAE,CAAC,IAAI,CAAC,IAAI,EAAE,CAAC,KAAK,CAAC,CAAC;AAE/C,MAAM,
|
|
1
|
+
{"version":3,"file":"transformer.d.ts","sourceRoot":"","sources":["../src/transformer.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAa,YAAY,EAAE,MAAM,WAAW,CAAC;AAErE,MAAM,MAAM,WAAW,CAAC,CAAC,EAAE,CAAC,IAAI,CAAC,IAAI,EAAE,CAAC,KAAK,CAAC,CAAC;AAE/C,MAAM,WAAW,mBAAmB;IAClC,QAAQ,CAAC,KAAK,CAAC,EAAE,WAAW,CAAC,GAAG,EAAE,GAAG,CAAC,EAAE,CAAC;IACzC,QAAQ,CAAC,MAAM,CAAC,EAAE,WAAW,CAAC,GAAG,EAAE,GAAG,CAAC,EAAE,CAAC;CAC3C;AACD,MAAM,MAAM,YAAY,CAAC,CAAC,SAAS,YAAY,IAAI,OAAO,CAAC;KACxD,CAAC,IAAI,MAAM,CAAC,GAAG,mBAAmB;CACpC,CAAC,CAAC;AAEH,MAAM,MAAM,iBAAiB,CAC3B,CAAC,SAAS,YAAY,EACtB,CAAC,SAAS,UAAU,CAAC,CAAC,CAAC,EACvB,EAAE,SAAS,OAAO,CAAC,YAAY,CAAC,CAAC,CAAC,CAAC,GAAG,SAAS,IAC7C;KACD,CAAC,IAAI,MAAM,CAAC,GAAG,EAAE,SAAS,SAAS,GAChC,CAAC,CAAC,CAAC,CAAC,GACJ,CAAC,SAAS,MAAM,EAAE,GAChB,CAAC,CAAC,CAAC,CAAC,GACJ,CAAC,CAAC,CAAC,CAAC;CACX,CAAC;AASF,wBAAgB,cAAc,CAC5B,WAAW,EAAE,WAAW,CAAC,GAAG,EAAE,GAAG,CAAC,EAAE,GAAG,SAAS,EAChD,CAAC,EAAE,GAAG,OAGP"}
|
package/dist/transformer.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"transformer.js","sourceRoot":"","sources":["../src/transformer.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"transformer.js","sourceRoot":"","sources":["../src/transformer.ts"],"names":[],"mappings":"AAwBA,SAAS,SAAS,CAAC,CAAM,EAAE,YAAqC;IAC9D,IAAI,EAAE,GAAG,CAAC,CAAC;IACX,KAAK,MAAM,CAAC,IAAI,YAAY,EAAE,CAAC;QAC7B,EAAE,GAAG,CAAC,CAAC,EAAE,CAAC,CAAC;IACb,CAAC;IACD,OAAO,EAAE,CAAC;AACZ,CAAC;AACD,MAAM,UAAU,cAAc,CAC5B,WAAgD,EAChD,CAAM;IAEN,OAAO,WAAW,IAAI,WAAW,CAAC,MAAM,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,EAAE,WAAW,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;AAC3E,CAAC"}
|
package/dist/type.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import { type
|
|
2
|
-
export type
|
|
1
|
+
import { type StructConstructor } from "./structure.js";
|
|
2
|
+
export type byte = number;
|
|
3
|
+
export type bytes = byte[];
|
|
3
4
|
export declare enum DataType {
|
|
4
5
|
INT8 = 0,
|
|
5
6
|
UINT8 = 1,
|
|
@@ -21,28 +22,28 @@ export declare enum DataType {
|
|
|
21
22
|
FLOAT64BE = 17
|
|
22
23
|
}
|
|
23
24
|
export type BigIntDataType = DataType.INT64LE | DataType.INT64BE | DataType.UINT64LE | DataType.UINT64BE;
|
|
24
|
-
export type NumericArrayDataType = [type: DataType, size:
|
|
25
|
-
export type
|
|
26
|
-
type:
|
|
27
|
-
size:
|
|
25
|
+
export type NumericArrayDataType = [type: DataType, size: byte];
|
|
26
|
+
export type StructArrayDataType<T extends Record<string, any>> = [
|
|
27
|
+
type: StructConstructor<T>,
|
|
28
|
+
size: byte
|
|
28
29
|
];
|
|
29
30
|
export type DomainObject = Record<string, any>;
|
|
30
|
-
export type InferArray<T extends any> = T extends
|
|
31
|
-
export type ArrayDataType = NumericArrayDataType |
|
|
32
|
-
export type Type
|
|
33
|
-
export type DataValue =
|
|
31
|
+
export type InferArray<T extends any> = T extends byte ? NumericArrayDataType : T extends DomainObject ? StructArrayDataType<T> : never;
|
|
32
|
+
export type ArrayDataType = NumericArrayDataType | StructArrayDataType<DomainObject>;
|
|
33
|
+
export type Type = DataType | ArrayDataType | StructConstructor<any>;
|
|
34
|
+
export type DataValue = byte | bytes | bigint | object;
|
|
34
35
|
export type BindedType<T extends Record<string, any>> = {
|
|
35
36
|
[K in keyof T]: T[K] extends string ? bytes : T[K] extends DomainObject ? BindedType<T[K]> : T[K];
|
|
36
37
|
};
|
|
37
|
-
export type
|
|
38
|
-
[K in keyof T]: T[K] extends readonly (infer P)[] ? InferArray<P> : T[K] extends
|
|
38
|
+
export type StructDefinitionDataType<T extends DomainObject> = {
|
|
39
|
+
[K in keyof T]: T[K] extends readonly (infer P)[] ? InferArray<P> : T[K] extends byte ? DataType : T[K] extends bigint ? BigIntDataType : T[K] extends string ? NumericArrayDataType : T[K] extends DomainObject ? StructConstructor<T[K]> : never;
|
|
39
40
|
};
|
|
40
41
|
export interface AlignedData<T extends Type = Type> {
|
|
41
42
|
readonly type: T;
|
|
42
|
-
readonly offset:
|
|
43
|
-
readonly size:
|
|
43
|
+
readonly offset: byte;
|
|
44
|
+
readonly size: byte;
|
|
44
45
|
}
|
|
45
|
-
export declare function
|
|
46
|
+
export declare function isStructDataType(t: Type): t is StructConstructor;
|
|
46
47
|
export declare function isArrayDataType(t: Type): t is ArrayDataType;
|
|
47
|
-
export declare function charDataType(length:
|
|
48
|
+
export declare function charDataType(length: byte): NumericArrayDataType;
|
|
48
49
|
//# sourceMappingURL=type.d.ts.map
|
package/dist/type.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"type.d.ts","sourceRoot":"","sources":["../src/type.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,
|
|
1
|
+
{"version":3,"file":"type.d.ts","sourceRoot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AAC,EAAE,IAAI,GAAG,CAAC,IAAI,aAAa,CAE3D;AACD,wBAAgB,YAAY,CAAC,MAAM,EAAE,IAAI,GAAG,oBAAoB,CAE/D"}
|
package/dist/type.js
CHANGED
|
@@ -20,7 +20,7 @@ export var DataType;
|
|
|
20
20
|
DataType[DataType["FLOAT64LE"] = 16] = "FLOAT64LE";
|
|
21
21
|
DataType[DataType["FLOAT64BE"] = 17] = "FLOAT64BE";
|
|
22
22
|
})(DataType || (DataType = {}));
|
|
23
|
-
export function
|
|
23
|
+
export function isStructDataType(t) {
|
|
24
24
|
return typeof t === "function";
|
|
25
25
|
}
|
|
26
26
|
export function isArrayDataType(t) {
|
package/dist/type.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"type.js","sourceRoot":"","sources":["../src/type.ts"],"names":[],"mappings":"AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"type.js","sourceRoot":"","sources":["../src/type.ts"],"names":[],"mappings":"AAAA,OAAO,EAA0B,MAAM,gBAAgB,CAAC;AAIxD,MAAM,CAAN,IAAY,QAmBX;AAnBD,WAAY,QAAQ;IAClB,uCAAQ,CAAA;IACR,yCAAK,CAAA;IACL,6CAAO,CAAA;IACP,6CAAO,CAAA;IACP,+CAAQ,CAAA;IACR,+CAAQ,CAAA;IACR,6CAAO,CAAA;IACP,6CAAO,CAAA;IACP,+CAAQ,CAAA;IACR,+CAAQ,CAAA;IACR,8CAAO,CAAA;IACP,8CAAO,CAAA;IACP,gDAAQ,CAAA;IACR,gDAAQ,CAAA;IACR,kDAAS,CAAA;IACT,kDAAS,CAAA;IACT,kDAAS,CAAA;IACT,kDAAS,CAAA;AACX,CAAC,EAnBW,QAAQ,KAAR,QAAQ,QAmBnB;AAmDD,MAAM,UAAU,gBAAgB,CAAC,CAAO;IACtC,OAAO,OAAO,CAAC,KAAK,UAAU,CAAC;AACjC,CAAC;AAED,MAAM,UAAU,eAAe,CAAC,CAAO;IACrC,OAAO,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC;AAC1B,CAAC;AACD,MAAM,UAAU,YAAY,CAAC,MAAY;IACvC,OAAO,CAAC,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC,CAAC;AAClC,CAAC"}
|