@zzzeros0/nbsp 0.2.1 → 0.4.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 +87 -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 +34 -28
- package/dist/structure.d.ts.map +1 -1
- package/dist/structure.js +49 -53
- 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,96 @@ 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
|
|
96
|
-
|
|
|
97
|
-
| from
|
|
98
|
-
|
|
|
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
|
+
| partial | Same as `new`; creates an instance with partial arguments. | `(args: Partial<T>)` | `Struct<T>` |
|
|
98
|
+
| toJson | Returns a plaing object. | `(target: Buffer, offset: byte = 0)` | T |
|
|
99
99
|
|
|
100
|
-
###
|
|
100
|
+
### Struct methods
|
|
101
101
|
|
|
102
|
-
| Method | Description
|
|
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 \|
|
|
102
|
+
| Method | Description | Arguments | Returned type |
|
|
103
|
+
| ------ | ---------------------------------------- | -------------------------------------------------------------- | ------------- |
|
|
104
|
+
| data | Returns the internal buffer (no copy). | | `Buffer` |
|
|
105
|
+
| reset | Zero the internal buffer content. | | `void` |
|
|
106
|
+
| toJson | Returns a plain object. | | `T` |
|
|
107
|
+
| copy | Copies the buffer's content from target. | `(target: Buffer \| Struct, offset: byte = 0, size: byte = 0)` | `void` |
|
|
108
108
|
|
|
109
|
-
###
|
|
109
|
+
### Struct Options
|
|
110
110
|
|
|
111
|
-
|
|
111
|
+
Options argument for the `struct` function.
|
|
112
112
|
|
|
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.
|
|
113
|
+
| Property | Description | Type | Default |
|
|
114
|
+
| --------- | --------------------------------------------------------------------------------------------------------------------------------------------------------- | ----------------- | ------- |
|
|
115
|
+
| 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` |
|
|
116
|
+
| transform | An object that contains keys from the domain object. Transforms the data obtained/retrieved from the buffer data. | `Transformers<T>` | `{}` |
|
|
117
117
|
|
|
118
118
|
## Usage
|
|
119
119
|
|
|
120
|
-
1. Create a domain interface.
|
|
121
|
-
|
|
122
|
-
- This will represent your data.
|
|
120
|
+
1. Create a domain interface. This will represent your data.
|
|
123
121
|
|
|
124
122
|
```ts
|
|
125
123
|
interface Person {
|
|
126
|
-
age:
|
|
124
|
+
age: byte;
|
|
127
125
|
name: string;
|
|
128
126
|
} // domain Person
|
|
129
127
|
```
|
|
130
128
|
|
|
131
|
-
2. Create a
|
|
129
|
+
2. Create a Struct for your domain interface. Calling `struct` will return a new class; it is not intended to be extended.
|
|
132
130
|
|
|
133
131
|
```ts
|
|
134
|
-
const
|
|
132
|
+
const PersonStruct = struct<Person>({
|
|
135
133
|
age: DataType.UINT8,
|
|
136
134
|
name: charDataType(4), // strings are arrays of UINT8. charDataType(n) is equivalent to [DataType.UINT8, n]
|
|
137
135
|
});
|
|
138
136
|
```
|
|
139
137
|
|
|
140
|
-
3. Now, you can instantiate the
|
|
138
|
+
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
139
|
|
|
142
140
|
```ts
|
|
143
|
-
const person1 = new
|
|
141
|
+
const person1 = new PersonStruct({
|
|
144
142
|
age: 24,
|
|
145
|
-
name:
|
|
143
|
+
name: toBytes("Dave"), // Transform the string to UTF-8 UINT8 array
|
|
146
144
|
});
|
|
147
145
|
console.log("Name: %s, age: %d", toString(person1.name), person1.age); // Name: Dave, age: 24
|
|
148
146
|
|
|
149
|
-
const person2 =
|
|
147
|
+
const person2 = PersonStruct.from(Buffer.from("63000000526f7365", "hex"));
|
|
150
148
|
|
|
151
|
-
console.log("Name: %s, age: %d", toString(person2.name), person2.age); // Name: Rose, age:
|
|
149
|
+
console.log("Name: %s, age: %d", toString(person2.name), person2.age); // Name: Rose, age: 99
|
|
152
150
|
|
|
153
|
-
console.log(person2.data()); // <Buffer 52 6f 73 65
|
|
151
|
+
console.log(person2.data()); // <Buffer 63 00 00 00 52 6f 73 65>
|
|
154
152
|
|
|
155
|
-
console.log(person2.toJson()); // { name: [ 82, 111, 115, 101 ]
|
|
153
|
+
console.log(person2.toJson()); // { age: 99, name: [ 82, 111, 115, 101 ] }
|
|
156
154
|
|
|
157
|
-
const person3 =
|
|
155
|
+
const person3 = PersonStruct.toJson(Buffer.from("5a0000004a616b65", "hex"));
|
|
158
156
|
|
|
159
157
|
console.log("Name: %s, age: %d", toString(person3.name), person3.age); // Name: Jake, age: 90
|
|
158
|
+
```
|
|
160
159
|
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
160
|
+
Transformers help to transform data.
|
|
161
|
+
When a property has transformers, its exposed TypeScript type becomes the transformed type instead of the raw BindedType<T>.
|
|
162
|
+
You can have multiple transforms in input/output; each one will receive the last transformed value.
|
|
164
163
|
|
|
165
|
-
|
|
164
|
+
```ts
|
|
165
|
+
const PersonStruct = struct<Person, { name: PropertyTransform }>(
|
|
166
166
|
{
|
|
167
167
|
age: DataType.UINT8,
|
|
168
168
|
name: charDataType(4),
|
|
@@ -171,14 +171,14 @@ const PersonStructure = structure<Person, { name: PropertyTransform }>(
|
|
|
171
171
|
transform: {
|
|
172
172
|
name: {
|
|
173
173
|
// Executed when data is written to the buffer
|
|
174
|
-
input: [(data: string) =>
|
|
174
|
+
input: [(data: string) => toBytes(data)],
|
|
175
175
|
// Executed when data is retrieved from the buffer
|
|
176
176
|
output: [(data: bytes) => toString(data)],
|
|
177
177
|
},
|
|
178
178
|
},
|
|
179
179
|
},
|
|
180
180
|
);
|
|
181
|
-
const person = new
|
|
181
|
+
const person = new PersonStruct({
|
|
182
182
|
age: 24,
|
|
183
183
|
name: "Dave", // Input transformer
|
|
184
184
|
});
|
|
@@ -188,22 +188,22 @@ console.log(person.name); // "Jack", output transformer
|
|
|
188
188
|
|
|
189
189
|
### Arrays & Nesting
|
|
190
190
|
|
|
191
|
-
`
|
|
191
|
+
`Array` types are defined with a `type` and a fixed `length` of items:
|
|
192
192
|
|
|
193
193
|
```ts
|
|
194
|
-
const
|
|
194
|
+
const PersonStruct = struct<Person>({
|
|
195
195
|
name: [DataType.UINT8, 4], // or charDataType(4)
|
|
196
196
|
});
|
|
197
197
|
```
|
|
198
198
|
|
|
199
|
-
> Strings are represented as a fixed array of `UINT8` if no transformer was applied for that property.
|
|
199
|
+
> Strings are represented as a fixed array of `UINT8` if no transformer was applied for that property. Use the shorthand `charDataType`.
|
|
200
200
|
|
|
201
|
-
You can nest `
|
|
201
|
+
You can nest `Structs`:
|
|
202
202
|
|
|
203
203
|
```ts
|
|
204
204
|
interface DeviceConfig {
|
|
205
|
-
mode:
|
|
206
|
-
factor:
|
|
205
|
+
mode: byte;
|
|
206
|
+
factor: byte;
|
|
207
207
|
} // domain DeviceConfig
|
|
208
208
|
|
|
209
209
|
interface Device {
|
|
@@ -211,45 +211,45 @@ interface Device {
|
|
|
211
211
|
config: DeviceConfig; // Provide the domain type
|
|
212
212
|
} // domain Device
|
|
213
213
|
|
|
214
|
-
const
|
|
214
|
+
const DeviceConfigStruct = struct<DeviceConfig>({
|
|
215
215
|
mode: DataType.UINT8,
|
|
216
216
|
factor: DataType.UINT8,
|
|
217
217
|
});
|
|
218
218
|
|
|
219
|
-
const
|
|
219
|
+
const DeviceStruct = struct<Device>({
|
|
220
220
|
id: charDataType(6),
|
|
221
|
-
config:
|
|
221
|
+
config: DeviceConfigStruct, // Provide the struct as type
|
|
222
222
|
});
|
|
223
223
|
|
|
224
|
-
const instance = new
|
|
224
|
+
const instance = new DeviceStruct({
|
|
225
225
|
id: Array.from(randomBytes(6)),
|
|
226
226
|
config: {
|
|
227
227
|
// Create a plain object
|
|
228
|
-
// DO NOT use
|
|
228
|
+
// DO NOT use DeviceConfigStruct constructor
|
|
229
229
|
// it will cause unnecessary allocations
|
|
230
230
|
mode: 4,
|
|
231
231
|
factor: 8,
|
|
232
232
|
},
|
|
233
233
|
});
|
|
234
234
|
|
|
235
|
-
console.log(instance.config.factor); //
|
|
235
|
+
console.log(instance.config.factor); // 8
|
|
236
236
|
```
|
|
237
237
|
|
|
238
|
-
You can also store `
|
|
238
|
+
You can also store `Structs` or `Arrays` inside of `Arrays`:
|
|
239
239
|
|
|
240
240
|
```ts
|
|
241
241
|
interface Group {
|
|
242
242
|
people: Person[];
|
|
243
243
|
} // domain Group
|
|
244
244
|
|
|
245
|
-
const
|
|
246
|
-
people: [
|
|
245
|
+
const GroupStruct = struct<Group>({
|
|
246
|
+
people: [PersonStruct, 100],
|
|
247
247
|
});
|
|
248
248
|
|
|
249
|
-
const groupInstance = new
|
|
249
|
+
const groupInstance = new GroupStruct({
|
|
250
250
|
people: [
|
|
251
251
|
// Create a plain object
|
|
252
|
-
// DO NOT use
|
|
252
|
+
// DO NOT use PersonStruct constructor
|
|
253
253
|
// it will cause unnecessary allocations
|
|
254
254
|
{
|
|
255
255
|
name: "Jack",
|
|
@@ -269,11 +269,11 @@ console.log(groupInstance.people); // Array<100> [ { name: [Getter/Setter] }, ..
|
|
|
269
269
|
|
|
270
270
|
> **Important**
|
|
271
271
|
>
|
|
272
|
-
>
|
|
272
|
+
> Structs must be instantiated with plain objects when are nested, `do not` use the `Struct's constructor`; doing so will make unnecessary allocations.
|
|
273
273
|
|
|
274
274
|
### JSON
|
|
275
275
|
|
|
276
|
-
Instances can be converted to plain JavaScript object with all the resolved properties and nested attributes of your
|
|
276
|
+
Instances can be converted to plain JavaScript object with all the resolved properties and nested attributes of your struct using `toJson` method:
|
|
277
277
|
|
|
278
278
|
```ts
|
|
279
279
|
personInstance.toJson(); // { name: [ 68, 97, 118, 101 ], age: 24 }
|
|
@@ -282,17 +282,19 @@ personInstance.toJson(); // { name: [ 68, 97, 118, 101 ], age: 24 }
|
|
|
282
282
|
You can serialize directly to a plain JavaScript object from a buffer by using the static method `toJson`:
|
|
283
283
|
|
|
284
284
|
```ts
|
|
285
|
-
|
|
285
|
+
PersonStruct.toJson(Buffer.from("4a616b655a000000", "hex")); // { name: [ 68, 97, 118, 101 ], age: 24 }
|
|
286
286
|
```
|
|
287
287
|
|
|
288
288
|
> **Important**
|
|
289
289
|
>
|
|
290
290
|
> Transformers will also run when serializing JSON.
|
|
291
291
|
|
|
292
|
-
> Prefer the static `toJson` when working with raw buffers; there's no point on doing this:
|
|
292
|
+
> Prefer the static `toJson` method when working with raw buffers; there's no point on doing this:
|
|
293
293
|
>
|
|
294
294
|
> ```ts
|
|
295
|
-
>
|
|
295
|
+
> PersonStruct.toJson(personInstance.data());
|
|
296
|
+
> // Instead
|
|
297
|
+
> personInstance.toJson();
|
|
296
298
|
> ```
|
|
297
299
|
|
|
298
300
|
### Endianness
|
|
@@ -306,6 +308,16 @@ structure({
|
|
|
306
308
|
});
|
|
307
309
|
```
|
|
308
310
|
|
|
311
|
+
> **Note**
|
|
312
|
+
>
|
|
313
|
+
> You can get the `size` of data types with `sizeof`:
|
|
314
|
+
>
|
|
315
|
+
> ```ts
|
|
316
|
+
> console.log(sizeof(DataType.INT16LE)); // 2
|
|
317
|
+
> console.log(sizeof(charDataType(6))); // 6
|
|
318
|
+
> console.log(sizeof(Structure)); // Or Structure.size
|
|
319
|
+
> ```
|
|
320
|
+
|
|
309
321
|
### Floating point (FLOAT32) precision
|
|
310
322
|
|
|
311
323
|
NBSP uses IEEE-754 floating point representations for FLOAT32 and FLOAT64, exactly like C, C++, Rust, Java, etc.
|
|
@@ -344,7 +356,9 @@ NBSP intentionally exposes the real binary value, without rounding or post-proce
|
|
|
344
356
|
|
|
345
357
|
If you need to compare floating point values, never use strict equality:
|
|
346
358
|
|
|
347
|
-
|
|
359
|
+
```ts
|
|
360
|
+
a === b; // ❌ unsafe for floats
|
|
361
|
+
```
|
|
348
362
|
|
|
349
363
|
Instead, compare with a tolerance:
|
|
350
364
|
|
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,OAAoB,CAAC;AAE/C,SAAS,aAAa,CAAC,KAAW,E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AS,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,81 @@
|
|
|
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
|
-
|
|
7
|
+
type InferedStruct<T extends DomainObject, TR extends Transformers<T> | undefined> = TR extends undefined ? Struct<BindedType<T>, TR> : Struct<T, TR>;
|
|
8
|
+
type InferedDomainObject<T extends DomainObject, TR extends Transformers<T> | undefined> = TR extends undefined ? BindedType<T> : T;
|
|
9
|
+
interface StructStaticMethods<T extends DomainObject, TR extends Transformers<T> | undefined = undefined> {
|
|
8
10
|
/**
|
|
9
11
|
* Copys the contents of the buffer. Returns a new Instance.
|
|
10
12
|
* @param buffer
|
|
11
13
|
*/
|
|
12
|
-
from(buffer: Buffer, offset?:
|
|
14
|
+
from(buffer: Buffer, offset?: byte): InferedStruct<T, TR>;
|
|
13
15
|
/**
|
|
14
16
|
* Copys the contents of the instance's buffer. Returns a new instance.
|
|
15
17
|
* @param buffer
|
|
16
18
|
*/
|
|
17
|
-
from(
|
|
19
|
+
from(struct: InferedStruct<T, TR>, offset?: byte, length?: byte): InferedStruct<T, TR>;
|
|
18
20
|
/**
|
|
19
21
|
* Serializes the buffer directly to a plain object
|
|
20
22
|
* @param buffer
|
|
21
23
|
*/
|
|
22
|
-
toJson(buffer: Buffer): T
|
|
24
|
+
toJson(buffer: Buffer): InferedDomainObject<T, TR>;
|
|
25
|
+
partial(args?: Partial<T>): InferedStruct<T, TR>;
|
|
23
26
|
}
|
|
24
|
-
export interface
|
|
27
|
+
export interface StructConstructor<T extends DomainObject = DomainObject, TR extends Transformers<T> | undefined = undefined> extends StructStaticMethods<T, TR> {
|
|
25
28
|
/**
|
|
26
|
-
* The size of the
|
|
29
|
+
* The size of the struct
|
|
27
30
|
*/
|
|
28
|
-
readonly size:
|
|
31
|
+
readonly size: byte;
|
|
29
32
|
/**
|
|
30
|
-
* The fields of the
|
|
33
|
+
* The fields of the struct
|
|
31
34
|
*/
|
|
32
|
-
readonly fields:
|
|
35
|
+
readonly fields: StructFields<T>;
|
|
33
36
|
/**
|
|
34
37
|
* The transformers
|
|
35
38
|
*/
|
|
36
39
|
readonly transform: Transformers<T>;
|
|
37
|
-
new (args: T):
|
|
40
|
+
new (args: T): Struct<T, TR>;
|
|
38
41
|
}
|
|
39
|
-
export interface
|
|
42
|
+
export interface StructMethods<T extends DomainObject, TR extends Transformers<T> | undefined> {
|
|
40
43
|
/**
|
|
41
|
-
*
|
|
42
|
-
* @param buffer
|
|
44
|
+
* Returns the buffer
|
|
43
45
|
*/
|
|
44
|
-
|
|
46
|
+
data(): Buffer;
|
|
45
47
|
/**
|
|
46
|
-
* Copies the
|
|
48
|
+
* Copies the content of buffer
|
|
47
49
|
* @param buffer
|
|
50
|
+
* @param offset
|
|
51
|
+
* @param size Defaults to struct.size
|
|
48
52
|
*/
|
|
49
|
-
copy(
|
|
53
|
+
copy(buffer: Buffer, offset?: byte, size?: byte): void;
|
|
50
54
|
/**
|
|
51
|
-
*
|
|
55
|
+
* Copies the content of struct's buffer
|
|
56
|
+
* @param buffer
|
|
57
|
+
* @param offset
|
|
58
|
+
* @param size Defaults to struct.size
|
|
52
59
|
*/
|
|
53
|
-
|
|
60
|
+
copy(struct: InferedStruct<T, TR>, offset?: byte, size?: byte): void;
|
|
54
61
|
/**
|
|
55
62
|
* Sets the contents of the buffer to 0
|
|
56
63
|
*/
|
|
57
64
|
reset(): void;
|
|
58
65
|
/**
|
|
59
|
-
* Returns a plain object with the content of the
|
|
66
|
+
* Returns a plain object with the content of the struct
|
|
60
67
|
*/
|
|
61
|
-
toJson(): T
|
|
68
|
+
toJson(): InferedDomainObject<T, TR>;
|
|
62
69
|
}
|
|
63
|
-
export type
|
|
70
|
+
export type StructOptions<T extends DomainObject, TR extends Transformers<T> | undefined> = TR extends undefined ? {
|
|
64
71
|
packed?: boolean;
|
|
65
|
-
tranform?: undefined;
|
|
66
72
|
} : {
|
|
67
73
|
packed?: boolean;
|
|
68
74
|
transform?: TR;
|
|
69
75
|
};
|
|
70
|
-
export type
|
|
71
|
-
export type
|
|
72
|
-
export declare function
|
|
73
|
-
export declare function
|
|
76
|
+
export type Struct<T extends DomainObject, TR extends Transformers<T> | undefined> = T & StructMethods<T, TR>;
|
|
77
|
+
export type StructReturn<T extends DomainObject, TR extends Transformers<T> | undefined> = StructConstructor<ApplyTransformers<T, BindedType<T>, TR>>;
|
|
78
|
+
export declare function struct<T extends DomainObject>(data: StructDefinitionDataType<T>, opts?: StructOptions<T, undefined>): StructConstructor<BindedType<T>>;
|
|
79
|
+
export declare function struct<T extends DomainObject, TR extends Transformers<T>>(data: StructDefinitionDataType<T>, opts?: StructOptions<T, TR>): StructReturn<T, TR>;
|
|
74
80
|
export {};
|
|
75
81
|
//# 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;AAC1E,OAAO,EAAkB,KAAK,iBAAiB,EAAE,MAAM,kBAAkB,CAAC;AAC1E,OAAO,EAIL,KAAK,WAAW,EAEhB,KAAK,UAAU,EACf,KAAK,IAAI,EAET,KAAK,YAAY,EACjB,KAAK,wBAAwB,EAC7B,KAAK,IAAI,EACV,MAAM,WAAW,CAAC;AAEnB,MAAM,MAAM,YAAY,CAAC,CAAC,SAAS,YAAY,IAAI;KAChD,CAAC,IAAI,MAAM,MAAM,CAAC,MAAM,CAAC,EAAE,IAAI,CAAC,GAAG,WAAW;CAChD,CAAC;AAEF,KAAK,aAAa,CAChB,CAAC,SAAS,YAAY,EACtB,EAAE,SAAS,YAAY,CAAC,CAAC,CAAC,GAAG,SAAS,IACpC,EAAE,SAAS,SAAS,GAAG,MAAM,CAAC,UAAU,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,GAAG,MAAM,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC;AACrE,KAAK,mBAAmB,CACtB,CAAC,SAAS,YAAY,EACtB,EAAE,SAAS,YAAY,CAAC,CAAC,CAAC,GAAG,SAAS,IACpC,EAAE,SAAS,SAAS,GAAG,UAAU,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC;AAE7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AC,UAAU,CAAC,CAAC,CAAC,CAAC,CAAC;AAEpC,wBAAgB,MAAM,CAAC,CAAC,SAAS,YAAY,EAAE,EAAE,SAAS,YAAY,CAAC,CAAC,CAAC,EACvE,IAAI,EAAE,wBAAwB,CAAC,CAAC,CAAC,EACjC,IAAI,CAAC,EAAE,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,30 +154,28 @@ 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;
|
|
162
161
|
}
|
|
163
|
-
if (
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
162
|
+
if (val)
|
|
163
|
+
if (Array.isArray(field.type)) {
|
|
164
|
+
writeArray(field, val, buffer, offset);
|
|
165
|
+
}
|
|
166
|
+
else {
|
|
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;
|
|
@@ -189,40 +186,39 @@ export function structure(data, opts) {
|
|
|
189
186
|
__buff__ = alloc(size);
|
|
190
187
|
static from(arg, offset = 0) {
|
|
191
188
|
writeData = false;
|
|
192
|
-
const
|
|
193
|
-
|
|
189
|
+
const source = arg instanceof Buffer ? arg : arg.data();
|
|
190
|
+
const length = source.length;
|
|
191
|
+
if (size > length)
|
|
194
192
|
throw new Error("Invalid buffer size");
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
return inst;
|
|
199
|
-
}
|
|
200
|
-
else {
|
|
201
|
-
const inst = new this({});
|
|
202
|
-
arg.data().copy(inst.data(), 0, offset, offset + size);
|
|
203
|
-
return inst;
|
|
204
|
-
}
|
|
193
|
+
const inst = new this({});
|
|
194
|
+
source.copy(inst.data(), offset, 0, size);
|
|
195
|
+
return inst;
|
|
205
196
|
}
|
|
206
197
|
static toJson(buffer) {
|
|
207
198
|
if (buffer.length < size)
|
|
208
199
|
throw new Error("Invalid buffer size");
|
|
209
|
-
return
|
|
210
|
-
type:
|
|
200
|
+
return readStruct({
|
|
201
|
+
type: t,
|
|
211
202
|
offset: 0,
|
|
212
203
|
size,
|
|
213
204
|
}, buffer, 0, false);
|
|
214
205
|
}
|
|
206
|
+
static partial(args) {
|
|
207
|
+
writeData = true;
|
|
208
|
+
const targs = args ?? {};
|
|
209
|
+
return new this(targs);
|
|
210
|
+
}
|
|
215
211
|
constructor(args) {
|
|
216
212
|
construct(this, fields, transformers, args, this.__buff__, 0, writeData);
|
|
217
213
|
writeData = true;
|
|
218
214
|
}
|
|
219
|
-
copy(target, offset = 0) {
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
215
|
+
copy(target, offset = 0, s = 0) {
|
|
216
|
+
const source = target instanceof Buffer ? target : target.data();
|
|
217
|
+
const length = source.length;
|
|
218
|
+
if (s > length)
|
|
219
|
+
throw new Error("Invalid buffer size");
|
|
220
|
+
const _size = s || length;
|
|
221
|
+
source.copy(this.__buff__, offset, 0, _size);
|
|
226
222
|
}
|
|
227
223
|
data() {
|
|
228
224
|
return this.__buff__;
|
|
@@ -231,7 +227,7 @@ export function structure(data, opts) {
|
|
|
231
227
|
this.__buff__.fill(0);
|
|
232
228
|
}
|
|
233
229
|
toJson() {
|
|
234
|
-
return
|
|
230
|
+
return readStruct({
|
|
235
231
|
type: t,
|
|
236
232
|
offset: 0,
|
|
237
233
|
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,eA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C,IAAI,EAAE,MAAM,EAAE,YAAY,EAAE,IAAI,EAAE,IAAI,CAAC,QAAQ,EAAE,CAAC,EAAE,SAAS,CAAC,CAAC;YACzE,SAAS,GAAG,IAAI,CAAC;QACnB,CAAC;QAGM,IAAI,CAAC,MAAW,EAAE,SAAe,CAAC,EAAE,IAAU,CAAC;YACpD,MAAM,MAAM,GAAW,MAAM,YAAY,MAAM,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,MAAM,CAAC,IAAI,EAAE,CAAC;YACzE,MAAM,MAAM,GAAG,MAAM,CAAC,MAAM,CAAC;YAC7B,IAAI,CAAC,GAAG,MAAM;gBAAE,MAAM,IAAI,KAAK,CAAC,qBAAqB,CAAC,CAAC;YACvD,MAAM,KAAK,GAAG,CAAC,IAAI,MAAM,CAAC;YAC1B,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,QAAQ,EAAE,MAAM,EAAE,CAAC,EAAE,KAAK,CAAC,CAAC;QAC/C,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,CAAgC;gBACtC,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, 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":"","sources":["../src/type.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,iBAAiB,EAAE,MAAM,gBAAgB,CAAC;AACxD,MAAM,MAAM,IAAI,GAAG,MAAM,CAAC;AAC1B,MAAM,MAAM,KAAK,GAAG,IAAI,EAAE,CAAC;AAE3B,oBAAY,QAAQ;IAClB,IAAI,IAAI;IACR,KAAK,IAAA;IACL,OAAO,IAAA;IACP,OAAO,IAAA;IACP,QAAQ,IAAA;IACR,QAAQ,IAAA;IACR,OAAO,IAAA;IACP,OAAO,IAAA;IACP,QAAQ,IAAA;IACR,QAAQ,IAAA;IACR,OAAO,KAAA;IACP,OAAO,KAAA;IACP,QAAQ,KAAA;IACR,QAAQ,KAAA;IACR,SAAS,KAAA;IACT,SAAS,KAAA;IACT,SAAS,KAAA;IACT,SAAS,KAAA;CACV;AACD,MAAM,MAAM,cAAc,GACtB,QAAQ,CAAC,OAAO,GAChB,QAAQ,CAAC,OAAO,GAChB,QAAQ,CAAC,QAAQ,GACjB,QAAQ,CAAC,QAAQ,CAAC;AACtB,MAAM,MAAM,oBAAoB,GAAG,CAAC,IAAI,EAAE,QAAQ,EAAE,IAAI,EAAE,IAAI,CAAC,CAAC;AAChE,MAAM,MAAM,mBAAmB,CAAC,CAAC,SAAS,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,IAAI;IAC/D,IAAI,EAAE,iBAAiB,CAAC,CAAC,CAAC;IAC1B,IAAI,EAAE,IAAI;CACX,CAAC;AAEF,MAAM,MAAM,YAAY,GAAG,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;AAC/C,MAAM,MA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IAChD,QAAQ,CAAC,IAAI,EAAE,CAAC,CAAC;IACjB,QAAQ,CAAC,MAAM,EAAE,IAAI,CAAC;IACtB,QAAQ,CAAC,IAAI,EAAE,IAAI,CAAC;CACrB;AACD,wBAAgB,gBAAgB,CAAC,CAAC,EAAE,IAAI,GAAG,CAAC,IAAI,iBAAiB,CAEhE;AAED,wBAAgB,eAAe,CAAC,CAAC,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"}
|