@woosh/meep-engine 2.92.19 → 2.92.20
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/package.json +1 -1
- package/src/core/binary/data_view/DataViewStructAccessor.d.ts.map +1 -1
- package/src/core/binary/data_view/DataViewStructAccessor.js +8 -33
- package/src/core/binary/data_view/buildAccessor.d.ts +11 -0
- package/src/core/binary/data_view/buildAccessor.d.ts.map +1 -0
- package/src/core/binary/data_view/buildAccessor.js +61 -0
package/package.json
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"DataViewStructAccessor.d.ts","sourceRoot":"","sources":["../../../../../src/core/binary/data_view/DataViewStructAccessor.js"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"DataViewStructAccessor.d.ts","sourceRoot":"","sources":["../../../../../src/core/binary/data_view/DataViewStructAccessor.js"],"names":[],"mappings":"AAGA;IAiBI;;;;OAIG;IACH,yCAFW,OAAO,EAYjB;IA/BD;;OAEG;IACH,OAFU,QAAQ,CAEZ;IAEN;;OAEG;IACH,SAFU,MAAM,CAEJ;IAEZ;;;OAGG;IACH,4BAFU,MAAM,CAEM;IAmBtB;;;OAGG;IACH,qCAEC;IAED;;;;OAIG;IACH,gBAHW,QAAQ,eACR,MAAM,QAKhB;IAED;;;;OAIG;IACH,yBAHW,QAAQ,SACR,MAAM,QAKhB;CACJ"}
|
|
@@ -1,9 +1,5 @@
|
|
|
1
|
-
import { assert } from "../../assert.js";
|
|
2
|
-
import { FunctionCompiler } from "../../function/FunctionCompiler.js";
|
|
3
1
|
import { BinaryDataType } from "../type/BinaryDataType.js";
|
|
4
|
-
import {
|
|
5
|
-
import { DataType2DataViewReaders } from "./DataType2DataViewReaders.js";
|
|
6
|
-
import { DataType2DataViewWriters } from "./DataType2DataViewWriters.js";
|
|
2
|
+
import { buildAccessor } from "./buildAccessor.js";
|
|
7
3
|
|
|
8
4
|
export class DataViewStructAccessor {
|
|
9
5
|
/**
|
|
@@ -28,36 +24,15 @@ export class DataViewStructAccessor {
|
|
|
28
24
|
* @param {boolean} [little_endian]
|
|
29
25
|
*/
|
|
30
26
|
constructor(schema, little_endian = false) {
|
|
31
|
-
assert.defined(schema, 'schema');
|
|
32
|
-
assert.isBoolean(little_endian, 'little_endian');
|
|
33
27
|
|
|
34
|
-
|
|
35
|
-
|
|
28
|
+
this.$record_byte_size = buildAccessor({
|
|
29
|
+
schema,
|
|
30
|
+
target: this,
|
|
31
|
+
data_variable_name: "this.$data",
|
|
32
|
+
offset_variable_name: "this.$offset",
|
|
33
|
+
little_endian
|
|
34
|
+
});
|
|
36
35
|
|
|
37
|
-
let offset = 0;
|
|
38
|
-
for (let i = 0; i < property_count; i++) {
|
|
39
|
-
const property = props[i];
|
|
40
|
-
const type = schema[property];
|
|
41
|
-
|
|
42
|
-
assert.enum(type, BinaryDataType, "type");
|
|
43
|
-
|
|
44
|
-
assert.arrayHasNo(["bind", "$data", "$offset", "this", "constructor", "get", "set"], property, `Illegal property name ${property}`);
|
|
45
|
-
|
|
46
|
-
//
|
|
47
|
-
Object.defineProperty(this, property, {
|
|
48
|
-
get: FunctionCompiler.INSTANCE.compile({
|
|
49
|
-
code: `return this.$data.${DataType2DataViewReaders[type]}(this.$offset + ${offset}, ${little_endian})`
|
|
50
|
-
}),
|
|
51
|
-
set: FunctionCompiler.INSTANCE.compile({
|
|
52
|
-
args: ["value"],
|
|
53
|
-
code: `this.$data.${DataType2DataViewWriters[type]}(this.$offset + ${offset}, value, ${little_endian})`
|
|
54
|
-
})
|
|
55
|
-
})
|
|
56
|
-
|
|
57
|
-
offset += DataTypeByteSizes[type];
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
this.$record_byte_size = offset;
|
|
61
36
|
}
|
|
62
37
|
|
|
63
38
|
/**
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
*
|
|
3
|
+
* @param {Object<BinaryDataType>} schema
|
|
4
|
+
* @param {Object} target
|
|
5
|
+
* @param {string} [data_variable_name]
|
|
6
|
+
* @param {string} [offset_variable_name]
|
|
7
|
+
* @param {boolean} [little_endian]
|
|
8
|
+
* @return {number}
|
|
9
|
+
*/
|
|
10
|
+
export function buildAccessor({ schema, target, data_variable_name, offset_variable_name, little_endian }: any): number;
|
|
11
|
+
//# sourceMappingURL=buildAccessor.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"buildAccessor.d.ts","sourceRoot":"","sources":["../../../../../src/core/binary/data_view/buildAccessor.js"],"names":[],"mappings":"AAOA;;;;;;;;GAQG;AACH,iHAFY,MAAM,CA8CjB"}
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import { assert } from "../../assert.js";
|
|
2
|
+
import { FunctionCompiler } from "../../function/FunctionCompiler.js";
|
|
3
|
+
import { BinaryDataType } from "../type/BinaryDataType.js";
|
|
4
|
+
import { DataTypeByteSizes } from "../type/DataTypeByteSizes.js";
|
|
5
|
+
import { DataType2DataViewReaders } from "./DataType2DataViewReaders.js";
|
|
6
|
+
import { DataType2DataViewWriters } from "./DataType2DataViewWriters.js";
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
*
|
|
10
|
+
* @param {Object<BinaryDataType>} schema
|
|
11
|
+
* @param {Object} target
|
|
12
|
+
* @param {string} [data_variable_name]
|
|
13
|
+
* @param {string} [offset_variable_name]
|
|
14
|
+
* @param {boolean} [little_endian]
|
|
15
|
+
* @return {number}
|
|
16
|
+
*/
|
|
17
|
+
export function buildAccessor({
|
|
18
|
+
schema,
|
|
19
|
+
target,
|
|
20
|
+
data_variable_name = "this.$data",
|
|
21
|
+
offset_variable_name = "this.$offset",
|
|
22
|
+
little_endian = false
|
|
23
|
+
}) {
|
|
24
|
+
|
|
25
|
+
assert.defined(schema, 'schema');
|
|
26
|
+
assert.isBoolean(little_endian, 'little_endian');
|
|
27
|
+
|
|
28
|
+
assert.isString(data_variable_name, 'data_variable_name')
|
|
29
|
+
assert.isString(offset_variable_name, 'offset_variable_name')
|
|
30
|
+
|
|
31
|
+
assert.defined(target, 'target');
|
|
32
|
+
assert.notNull(target, 'target');
|
|
33
|
+
|
|
34
|
+
const props = Object.keys(schema);
|
|
35
|
+
const property_count = props.length;
|
|
36
|
+
|
|
37
|
+
let offset = 0;
|
|
38
|
+
for (let i = 0; i < property_count; i++) {
|
|
39
|
+
const property = props[i];
|
|
40
|
+
const type = schema[property];
|
|
41
|
+
|
|
42
|
+
assert.enum(type, BinaryDataType, "type");
|
|
43
|
+
|
|
44
|
+
assert.arrayHasNo(["bind", "$data", "$offset", "this", "constructor", "get", "set"], property, `Illegal property name ${property}`);
|
|
45
|
+
|
|
46
|
+
//
|
|
47
|
+
Object.defineProperty(target, property, {
|
|
48
|
+
get: FunctionCompiler.INSTANCE.compile({
|
|
49
|
+
code: `return ${data_variable_name}.${DataType2DataViewReaders[type]}(${offset_variable_name} + ${offset}, ${little_endian})`
|
|
50
|
+
}),
|
|
51
|
+
set: FunctionCompiler.INSTANCE.compile({
|
|
52
|
+
args: ["value"],
|
|
53
|
+
code: `${data_variable_name}.${DataType2DataViewWriters[type]}(${offset_variable_name} + ${offset}, value, ${little_endian})`
|
|
54
|
+
})
|
|
55
|
+
})
|
|
56
|
+
|
|
57
|
+
offset += DataTypeByteSizes[type];
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
return offset;
|
|
61
|
+
}
|