@amodx/binary 0.0.11 → 0.0.13
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/Arrays/BitArray.d.ts +13 -0
- package/Arrays/BitArray.js +63 -0
- package/Arrays/HalfNibbleArray.d.ts +13 -0
- package/Arrays/HalfNibbleArray.js +63 -0
- package/Arrays/NibbleArray.d.ts +13 -0
- package/Arrays/NibbleArray.js +63 -0
- package/Object/BinaryObject.d.ts +2 -2
- package/Object/Functions/BufferToObject.d.ts +3 -3
- package/Struct/Classes/BinaryStruct.d.ts +4 -5
- package/Struct/Classes/BinaryStruct.js +11 -158
- package/Struct/Classes/BinraryStructBase.d.ts +5 -5
- package/Struct/Classes/BinraryStructBase.js +33 -148
- package/Struct/Classes/InstantiatedStruct.d.ts +7 -3
- package/Struct/Classes/InstantiatedStruct.js +18 -6
- package/Struct/Classes/RemoteBinaryStruct.d.ts +2 -3
- package/Struct/Classes/RemoteBinaryStruct.js +2 -3
- package/Struct/Constants/StructPropertyTypes.d.ts +4 -1
- package/Struct/Constants/StructPropertyTypes.js +3 -0
- package/Struct/Functions/CreateIndex.d.ts +3 -0
- package/Struct/Functions/CreateIndex.js +217 -0
- package/Struct/Functions/CreateInstance.d.ts +3 -0
- package/Struct/Functions/CreateInstance.js +323 -0
- package/Struct/Functions/GetIndexData.d.ts +2 -0
- package/Struct/Functions/GetIndexData.js +29 -0
- package/Struct/Types/{RemoveBinaryStructData.types.d.ts → BinaryStructData.types.d.ts} +4 -3
- package/Struct/Types/BinaryStructSchema.types.d.ts +37 -1
- package/Struct/Types/index.d.ts +1 -1
- package/Struct/Types/index.js +1 -1
- package/Util/BinaryArrays.d.ts +8 -0
- package/Util/BinaryArrays.js +39 -0
- package/Util/BinaryUtil.d.ts +2 -4
- package/Util/BinaryUtil.js +4 -18
- package/package.json +1 -1
- /package/Struct/Types/{RemoveBinaryStructData.types.js → BinaryStructData.types.js} +0 -0
|
@@ -1,36 +1,25 @@
|
|
|
1
1
|
import { BinaryUtil } from "../../Util/BinaryUtil.js";
|
|
2
|
-
import { BinaryNumberTypes } from "../../Constants/BinaryTypes.js";
|
|
3
2
|
import { StructPropertyTypes } from "../Constants/StructPropertyTypes.js";
|
|
4
|
-
import {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
StuctIndexData[0] = data.getUint32(indexBufferIndex);
|
|
8
|
-
indexBufferIndex += BinaryUtil.getTypedSize(BinaryNumberTypes.Uint32);
|
|
9
|
-
StuctIndexData[1] = data.getUint8(indexBufferIndex);
|
|
10
|
-
indexBufferIndex += BinaryUtil.getTypedSize(BinaryNumberTypes.Uint8);
|
|
11
|
-
StuctIndexData[2] = data.getUint8(indexBufferIndex);
|
|
12
|
-
indexBufferIndex += BinaryUtil.getTypedSize(BinaryNumberTypes.Uint8);
|
|
13
|
-
StuctIndexData[3] = data.getUint8(indexBufferIndex);
|
|
14
|
-
indexBufferIndex += BinaryUtil.getTypedSize(BinaryNumberTypes.Uint8);
|
|
15
|
-
return StuctIndexData;
|
|
16
|
-
};
|
|
3
|
+
import { GetIndexData } from "../../Struct/Functions/GetIndexData.js";
|
|
4
|
+
import { CreateInstance } from "../Functions/CreateInstance.js";
|
|
5
|
+
import { BinaryArrays } from "../../Util/BinaryArrays.js";
|
|
17
6
|
export class BinraryStructBase {
|
|
18
7
|
id;
|
|
19
8
|
byteOffSet = 0;
|
|
20
9
|
structSize = 0;
|
|
21
10
|
structArrayIndexes = 0;
|
|
22
11
|
structArrayIndex = 0;
|
|
12
|
+
structData;
|
|
23
13
|
data = new DataView(new ArrayBuffer(0));
|
|
24
|
-
indexMap =
|
|
14
|
+
indexMap = {};
|
|
25
15
|
index = new DataView(new ArrayBuffer(0));
|
|
26
16
|
constructor(id) {
|
|
27
17
|
this.id = id;
|
|
28
18
|
}
|
|
19
|
+
setData(data) {
|
|
20
|
+
this.data = data;
|
|
21
|
+
}
|
|
29
22
|
setBuffer(data) {
|
|
30
|
-
if (data instanceof DataView) {
|
|
31
|
-
this.data = data;
|
|
32
|
-
return;
|
|
33
|
-
}
|
|
34
23
|
this.data = new DataView(data);
|
|
35
24
|
}
|
|
36
25
|
getBuffer() {
|
|
@@ -44,48 +33,48 @@ export class BinraryStructBase {
|
|
|
44
33
|
this.byteOffSet = index * this.structSize;
|
|
45
34
|
}
|
|
46
35
|
getProperty(id) {
|
|
47
|
-
const byteIndex = this.indexMap
|
|
36
|
+
const byteIndex = this.indexMap[id];
|
|
48
37
|
if (byteIndex === undefined) {
|
|
49
38
|
throw new Error(`Tag with id: ${id} does not exist.`);
|
|
50
39
|
}
|
|
51
|
-
const indexData =
|
|
52
|
-
if (indexData[
|
|
40
|
+
const indexData = GetIndexData(this.index, byteIndex);
|
|
41
|
+
if (indexData[4] == StructPropertyTypes.Boolean) {
|
|
53
42
|
return BinaryUtil.getBitValue(this.data.getUint8(indexData[0] + this.byteOffSet), indexData[1], indexData[2]);
|
|
54
43
|
}
|
|
55
|
-
if (indexData[
|
|
44
|
+
if (indexData[4] == StructPropertyTypes.TypedNumber) {
|
|
56
45
|
return BinaryUtil.getTypedNumber(this.data, indexData[0] + this.byteOffSet, indexData[2]);
|
|
57
46
|
}
|
|
58
47
|
return -Infinity;
|
|
59
48
|
}
|
|
60
49
|
setProperty(id, value) {
|
|
61
|
-
const byteIndex = this.indexMap
|
|
50
|
+
const byteIndex = this.indexMap[id];
|
|
62
51
|
if (byteIndex === undefined) {
|
|
63
52
|
throw new Error(`Tag with id: ${id} does not exist.`);
|
|
64
53
|
}
|
|
65
|
-
const indexData =
|
|
66
|
-
if (indexData[
|
|
54
|
+
const indexData = GetIndexData(this.index, byteIndex);
|
|
55
|
+
if (indexData[4] == StructPropertyTypes.Boolean) {
|
|
67
56
|
this.data.setUint8(indexData[0] + this.byteOffSet, BinaryUtil.setBitValue(this.data.getUint8(indexData[0] + this.byteOffSet), indexData[1], value, indexData[2]));
|
|
68
57
|
return true;
|
|
69
58
|
}
|
|
70
|
-
if (indexData[
|
|
59
|
+
if (indexData[4] == StructPropertyTypes.TypedNumber) {
|
|
71
60
|
BinaryUtil.setTypedNumber(this.data, indexData[0] + this.byteOffSet, indexData[2], value);
|
|
72
61
|
return true;
|
|
73
62
|
}
|
|
74
63
|
return false;
|
|
75
64
|
}
|
|
76
65
|
getArrayPropertyValue(id, index) {
|
|
77
|
-
const byteIndex = this.indexMap
|
|
66
|
+
const byteIndex = this.indexMap[id];
|
|
78
67
|
if (byteIndex === undefined) {
|
|
79
68
|
throw new Error(`Tag with id: ${id} does not exist.`);
|
|
80
69
|
}
|
|
81
|
-
const indexData =
|
|
82
|
-
if (indexData[
|
|
70
|
+
const indexData = GetIndexData(this.index, byteIndex);
|
|
71
|
+
if (indexData[4] == StructPropertyTypes.TypedNumberArray) {
|
|
83
72
|
return BinaryUtil.getTypedNumber(this.data, indexData[0] +
|
|
84
73
|
this.byteOffSet +
|
|
85
74
|
index * BinaryUtil.getTypedSize(indexData[2]), indexData[2]);
|
|
86
75
|
}
|
|
87
|
-
if (indexData[
|
|
88
|
-
return
|
|
76
|
+
if (indexData[4] == StructPropertyTypes.BitArray) {
|
|
77
|
+
return BinaryArrays.getBitArrayIndex(this.data, indexData[0] + this.byteOffSet, index);
|
|
89
78
|
}
|
|
90
79
|
throw new Error(`Tag with id: ${id} is not an array.`);
|
|
91
80
|
}
|
|
@@ -96,12 +85,12 @@ export class BinraryStructBase {
|
|
|
96
85
|
* @returns
|
|
97
86
|
*/
|
|
98
87
|
getArrayPropertyByteIndex(id, index) {
|
|
99
|
-
const byteIndex = this.indexMap
|
|
88
|
+
const byteIndex = this.indexMap[id];
|
|
100
89
|
if (byteIndex === undefined) {
|
|
101
90
|
throw new Error(`Tag with id: ${id} does not exist.`);
|
|
102
91
|
}
|
|
103
|
-
const indexData =
|
|
104
|
-
if (indexData[
|
|
92
|
+
const indexData = GetIndexData(this.index, byteIndex);
|
|
93
|
+
if (indexData[4] == StructPropertyTypes.TypedNumberArray) {
|
|
105
94
|
return (indexData[0] +
|
|
106
95
|
this.byteOffSet +
|
|
107
96
|
index * BinaryUtil.getTypedSize(indexData[2]));
|
|
@@ -109,134 +98,30 @@ export class BinraryStructBase {
|
|
|
109
98
|
return -Infinity;
|
|
110
99
|
}
|
|
111
100
|
setArrayPropertyValue(id, index, value) {
|
|
112
|
-
const byteIndex = this.indexMap
|
|
101
|
+
const byteIndex = this.indexMap[id];
|
|
113
102
|
if (byteIndex === undefined) {
|
|
114
103
|
throw new Error(`Tag with id: ${id} does not exist.`);
|
|
115
104
|
}
|
|
116
|
-
const indexData =
|
|
117
|
-
if (indexData[
|
|
105
|
+
const indexData = GetIndexData(this.index, byteIndex);
|
|
106
|
+
if (indexData[4] == StructPropertyTypes.TypedNumberArray) {
|
|
118
107
|
return BinaryUtil.setTypedNumber(this.data, indexData[0] +
|
|
119
108
|
this.byteOffSet +
|
|
120
109
|
index * BinaryUtil.getTypedSize(indexData[2]), indexData[2], value);
|
|
121
110
|
}
|
|
122
|
-
if (indexData[
|
|
123
|
-
return
|
|
111
|
+
if (indexData[4] == StructPropertyTypes.BitArray) {
|
|
112
|
+
return BinaryArrays.setBitArrayIndex(this.data, indexData[0] + this.byteOffSet, index, value);
|
|
124
113
|
}
|
|
125
114
|
return -Infinity;
|
|
126
115
|
}
|
|
127
|
-
loopThroughProperties(run) {
|
|
128
|
-
this.indexMap.forEach((i, id) => {
|
|
129
|
-
run(id, this.getProperty(id));
|
|
130
|
-
});
|
|
131
|
-
}
|
|
132
|
-
loopThroughIndex(run) {
|
|
133
|
-
this.indexMap.forEach((index, id) => {
|
|
134
|
-
const indexData = getIndexData(this.index, index);
|
|
135
|
-
run(indexData);
|
|
136
|
-
});
|
|
137
|
-
}
|
|
138
|
-
loopThroughAllIndexAndProperties(run) {
|
|
139
|
-
for (let index = 0; index < this.structArrayIndexes; index++) {
|
|
140
|
-
this.setStructArrayIndex(index);
|
|
141
|
-
this.indexMap.forEach((i, id) => {
|
|
142
|
-
run(id, this.getProperty(id), index);
|
|
143
|
-
});
|
|
144
|
-
}
|
|
145
|
-
}
|
|
146
116
|
/**## instantiate
|
|
147
117
|
* Creates an object to read/write to the struct buffer.
|
|
148
118
|
* @param structArrayIndex - Default is the current index.
|
|
149
119
|
* @returns
|
|
150
120
|
*/
|
|
151
121
|
instantiate() {
|
|
152
|
-
const
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
this.setBuffer(self.getBuffer());
|
|
157
|
-
this.setIndex(self.structArrayIndex);
|
|
158
|
-
this.structSize = self.structSize;
|
|
159
|
-
this.structArrayIndexes = self.structArrayIndexes;
|
|
160
|
-
}
|
|
161
|
-
_bitArrays = new Map();
|
|
162
|
-
_typedArrays = new Map();
|
|
163
|
-
};
|
|
164
|
-
const cloneClass = () => {
|
|
165
|
-
return new GeneratedClass();
|
|
166
|
-
};
|
|
167
|
-
Object.defineProperty(GeneratedClass.prototype, "clone", {
|
|
168
|
-
get() {
|
|
169
|
-
return cloneClass;
|
|
170
|
-
},
|
|
171
|
-
});
|
|
172
|
-
for (const [key, propertyByteIndex] of this.indexMap) {
|
|
173
|
-
const [byteIndex, bitOffSet, bitSize, type] = getIndexData(this.index, propertyByteIndex);
|
|
174
|
-
if (type == StructPropertyTypes.Boolean) {
|
|
175
|
-
Object.defineProperty(GeneratedClass.prototype, key, {
|
|
176
|
-
get() {
|
|
177
|
-
return BinaryUtil.getBitValue(this.data.getUint8(byteIndex + this.byteOffSet), bitOffSet, bitSize);
|
|
178
|
-
},
|
|
179
|
-
set(value) {
|
|
180
|
-
this.data.setUint8(byteIndex + this.byteOffSet, BinaryUtil.setBitValue(this.data.getUint8(byteIndex + this.byteOffSet), bitOffSet, value, bitSize));
|
|
181
|
-
},
|
|
182
|
-
});
|
|
183
|
-
}
|
|
184
|
-
if (type == StructPropertyTypes.TypedNumber) {
|
|
185
|
-
Object.defineProperty(GeneratedClass.prototype, key, {
|
|
186
|
-
get() {
|
|
187
|
-
return BinaryUtil.getTypedNumber(this.data, byteIndex + this.byteOffSet, bitSize);
|
|
188
|
-
},
|
|
189
|
-
set(value) {
|
|
190
|
-
BinaryUtil.setTypedNumber(this.data, byteIndex + this.byteOffSet, bitSize, value);
|
|
191
|
-
},
|
|
192
|
-
});
|
|
193
|
-
}
|
|
194
|
-
if (type == StructPropertyTypes.BitArray) {
|
|
195
|
-
Object.defineProperty(GeneratedClass.prototype, key, {
|
|
196
|
-
get() {
|
|
197
|
-
const self = this;
|
|
198
|
-
if (!self._bitArrays.has(key)) {
|
|
199
|
-
const proxy = new Proxy([], {
|
|
200
|
-
get(target, index) {
|
|
201
|
-
return BinaryUtil.getBitArrayIndex(self.data, byteIndex + self.byteOffSet, +index);
|
|
202
|
-
},
|
|
203
|
-
set(target, index, value) {
|
|
204
|
-
BinaryUtil.setBitArrayIndex(self.data, byteIndex + self.byteOffSet, +index, value);
|
|
205
|
-
return true;
|
|
206
|
-
},
|
|
207
|
-
});
|
|
208
|
-
self._bitArrays.set(key, proxy);
|
|
209
|
-
}
|
|
210
|
-
return self._bitArrays.get(key);
|
|
211
|
-
},
|
|
212
|
-
});
|
|
213
|
-
}
|
|
214
|
-
if (type == StructPropertyTypes.TypedNumberArray) {
|
|
215
|
-
const typedNumberSize = BinaryUtil.getTypedSize(bitSize);
|
|
216
|
-
Object.defineProperty(GeneratedClass.prototype, key, {
|
|
217
|
-
get() {
|
|
218
|
-
const self = this;
|
|
219
|
-
if (!self._typedArrays.has(key)) {
|
|
220
|
-
const proxy = new Proxy([], {
|
|
221
|
-
get(target, index) {
|
|
222
|
-
return BinaryUtil.getTypedNumber(self.data, byteIndex +
|
|
223
|
-
self.byteOffSet +
|
|
224
|
-
+index * typedNumberSize, bitSize);
|
|
225
|
-
},
|
|
226
|
-
set(target, index, value) {
|
|
227
|
-
BinaryUtil.setTypedNumber(self.data, byteIndex +
|
|
228
|
-
self.byteOffSet +
|
|
229
|
-
+index * typedNumberSize, bitSize, value);
|
|
230
|
-
return true;
|
|
231
|
-
},
|
|
232
|
-
});
|
|
233
|
-
self._typedArrays.set(key, proxy);
|
|
234
|
-
}
|
|
235
|
-
return self._typedArrays.get(key);
|
|
236
|
-
},
|
|
237
|
-
});
|
|
238
|
-
}
|
|
239
|
-
}
|
|
240
|
-
return new GeneratedClass();
|
|
122
|
+
const instance = CreateInstance(this.structData);
|
|
123
|
+
instance.setBuffer(this.getBuffer());
|
|
124
|
+
instance.setIndex(this.structArrayIndex);
|
|
125
|
+
return instance;
|
|
241
126
|
}
|
|
242
127
|
}
|
|
@@ -1,13 +1,17 @@
|
|
|
1
1
|
export interface InstantiatedStruct<Properties> {
|
|
2
2
|
}
|
|
3
3
|
export declare class InstantiatedStruct<Properties> {
|
|
4
|
-
|
|
4
|
+
structByteOffSet: number;
|
|
5
5
|
structSize: number;
|
|
6
6
|
structArrayIndexes: number;
|
|
7
7
|
structArrayIndex: number;
|
|
8
|
-
|
|
8
|
+
structData: DataView;
|
|
9
9
|
setData(view: DataView): void;
|
|
10
10
|
setBuffer(buffer: ArrayBuffer | SharedArrayBuffer): void;
|
|
11
11
|
setIndex(index: number): void;
|
|
12
|
-
|
|
12
|
+
serialize(): Properties;
|
|
13
|
+
deserialize(data: Properties): void;
|
|
14
|
+
createClone(): InstantiatedStruct<Properties> & Properties;
|
|
15
|
+
setDefaults(): void;
|
|
16
|
+
getKeys(): string[];
|
|
13
17
|
}
|
|
@@ -1,20 +1,32 @@
|
|
|
1
1
|
export class InstantiatedStruct {
|
|
2
|
-
|
|
2
|
+
structByteOffSet = 0;
|
|
3
3
|
structSize = 0;
|
|
4
4
|
structArrayIndexes = 0;
|
|
5
5
|
structArrayIndex = 0;
|
|
6
|
-
|
|
6
|
+
structData;
|
|
7
7
|
setData(view) {
|
|
8
|
-
this.
|
|
8
|
+
this.structData = view;
|
|
9
9
|
}
|
|
10
10
|
setBuffer(buffer) {
|
|
11
|
-
this.
|
|
11
|
+
this.structData = new DataView(buffer);
|
|
12
12
|
}
|
|
13
13
|
setIndex(index) {
|
|
14
14
|
this.structArrayIndex = index;
|
|
15
|
-
this.
|
|
15
|
+
this.structByteOffSet = index * this.structSize;
|
|
16
16
|
}
|
|
17
|
-
|
|
17
|
+
serialize() {
|
|
18
|
+
throw new Error("Not implemented");
|
|
19
|
+
}
|
|
20
|
+
deserialize(data) {
|
|
21
|
+
throw new Error("Not implemented");
|
|
22
|
+
}
|
|
23
|
+
createClone() {
|
|
24
|
+
throw new Error("Not implemented");
|
|
25
|
+
}
|
|
26
|
+
setDefaults() {
|
|
27
|
+
throw new Error("Not implemented");
|
|
28
|
+
}
|
|
29
|
+
getKeys() {
|
|
18
30
|
throw new Error("Not implemented");
|
|
19
31
|
}
|
|
20
32
|
}
|
|
@@ -1,8 +1,7 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { BinaryStructData } from "../Types/BinaryStructData.types.js";
|
|
2
2
|
import { BinraryStructBase } from "./BinraryStructBase.js";
|
|
3
3
|
export declare class RemoteBinaryStruct extends BinraryStructBase {
|
|
4
4
|
id: string;
|
|
5
|
-
initData: RemoteBinaryStructData;
|
|
6
5
|
constructor(id: string);
|
|
7
|
-
init(data:
|
|
6
|
+
init(data: BinaryStructData): void;
|
|
8
7
|
}
|
|
@@ -1,17 +1,16 @@
|
|
|
1
1
|
import { BinraryStructBase } from "./BinraryStructBase.js";
|
|
2
2
|
export class RemoteBinaryStruct extends BinraryStructBase {
|
|
3
3
|
id;
|
|
4
|
-
initData;
|
|
5
4
|
constructor(id) {
|
|
6
5
|
super(id);
|
|
7
6
|
this.id = id;
|
|
8
7
|
}
|
|
9
8
|
init(data) {
|
|
9
|
+
this.structData = data;
|
|
10
10
|
this.data = new DataView(data.buffer);
|
|
11
11
|
this.index = new DataView(data.indexBuffer);
|
|
12
12
|
this.indexMap = data.indexMap;
|
|
13
|
-
this.structArrayIndexes = data.
|
|
13
|
+
this.structArrayIndexes = data.structArrayIndexes;
|
|
14
14
|
this.structSize = data.structSize;
|
|
15
|
-
this.initData = data;
|
|
16
15
|
}
|
|
17
16
|
}
|
|
@@ -4,4 +4,7 @@ export var StructPropertyTypes;
|
|
|
4
4
|
StructPropertyTypes[StructPropertyTypes["TypedNumber"] = 1] = "TypedNumber";
|
|
5
5
|
StructPropertyTypes[StructPropertyTypes["TypedNumberArray"] = 2] = "TypedNumberArray";
|
|
6
6
|
StructPropertyTypes[StructPropertyTypes["BitArray"] = 3] = "BitArray";
|
|
7
|
+
StructPropertyTypes[StructPropertyTypes["Vector2"] = 4] = "Vector2";
|
|
8
|
+
StructPropertyTypes[StructPropertyTypes["Vector3"] = 5] = "Vector3";
|
|
9
|
+
StructPropertyTypes[StructPropertyTypes["Vector4"] = 6] = "Vector4";
|
|
7
10
|
})(StructPropertyTypes || (StructPropertyTypes = {}));
|
|
@@ -0,0 +1,217 @@
|
|
|
1
|
+
import { BinaryUtil } from "../../Util/BinaryUtil.js";
|
|
2
|
+
import { ByteCounts } from "../../Constants/BinaryTypes";
|
|
3
|
+
import { StructPropertyTypes } from "../Constants/StructPropertyTypes";
|
|
4
|
+
import { SetIndexData } from "./GetIndexData";
|
|
5
|
+
const PropertyIndexSize = ByteCounts.Uint32 * 2 + ByteCounts.Uint8 * 3;
|
|
6
|
+
export function CreateIndex(schemaNodes, structArrayIndexes = 1, shared = false) {
|
|
7
|
+
const schema = new Map();
|
|
8
|
+
for (const node of schemaNodes) {
|
|
9
|
+
schema.set(node.id, node);
|
|
10
|
+
}
|
|
11
|
+
const propertyDefaults = {};
|
|
12
|
+
/*
|
|
13
|
+
[Process properties]
|
|
14
|
+
*/
|
|
15
|
+
const headers = new Map();
|
|
16
|
+
const booleans = [];
|
|
17
|
+
const numbers = [];
|
|
18
|
+
const typedNumbers = new Map();
|
|
19
|
+
const typedNumbersArrays = new Map();
|
|
20
|
+
const vector2s = new Map();
|
|
21
|
+
const vector3s = new Map();
|
|
22
|
+
const vector4s = new Map();
|
|
23
|
+
const bitArrays = [];
|
|
24
|
+
schema.forEach((property) => {
|
|
25
|
+
if (property.default)
|
|
26
|
+
propertyDefaults[property.id] = property.default;
|
|
27
|
+
if (property.type == "header") {
|
|
28
|
+
let properties = headers.get(property.numberType);
|
|
29
|
+
if (!properties) {
|
|
30
|
+
properties = [];
|
|
31
|
+
headers.set(property.numberType, properties);
|
|
32
|
+
}
|
|
33
|
+
properties.push(property);
|
|
34
|
+
}
|
|
35
|
+
if (property.type == "boolean") {
|
|
36
|
+
booleans.push(property);
|
|
37
|
+
}
|
|
38
|
+
if (property.type == "number") {
|
|
39
|
+
const range = property.range;
|
|
40
|
+
const bitSize = BinaryUtil.calculateBitsNeeded(range[0], range[1]);
|
|
41
|
+
numbers[bitSize] ??= [];
|
|
42
|
+
numbers[bitSize].push(property);
|
|
43
|
+
}
|
|
44
|
+
if (property.type == "typed-number") {
|
|
45
|
+
let properties = typedNumbers.get(property.numberType);
|
|
46
|
+
if (!properties) {
|
|
47
|
+
properties = [];
|
|
48
|
+
typedNumbers.set(property.numberType, properties);
|
|
49
|
+
}
|
|
50
|
+
properties.push(property);
|
|
51
|
+
}
|
|
52
|
+
if (property.type == "typed-number-array") {
|
|
53
|
+
let arrayproperties = typedNumbersArrays.get(property.numberType);
|
|
54
|
+
if (!arrayproperties) {
|
|
55
|
+
arrayproperties = [];
|
|
56
|
+
typedNumbersArrays.set(property.numberType, arrayproperties);
|
|
57
|
+
}
|
|
58
|
+
arrayproperties.push(property);
|
|
59
|
+
}
|
|
60
|
+
if (property.type == "vector-2") {
|
|
61
|
+
let vectorProperties = vector2s.get(property.numberType);
|
|
62
|
+
if (!vectorProperties) {
|
|
63
|
+
vectorProperties = [];
|
|
64
|
+
vector2s.set(property.numberType, vectorProperties);
|
|
65
|
+
}
|
|
66
|
+
vectorProperties.push(property);
|
|
67
|
+
}
|
|
68
|
+
if (property.type == "vector-3") {
|
|
69
|
+
let vectorProperties = vector3s.get(property.numberType);
|
|
70
|
+
if (!vectorProperties) {
|
|
71
|
+
vectorProperties = [];
|
|
72
|
+
vector3s.set(property.numberType, vectorProperties);
|
|
73
|
+
}
|
|
74
|
+
vectorProperties.push(property);
|
|
75
|
+
}
|
|
76
|
+
if (property.type == "vector-4") {
|
|
77
|
+
let vectorProperties = vector4s.get(property.numberType);
|
|
78
|
+
if (!vectorProperties) {
|
|
79
|
+
vectorProperties = [];
|
|
80
|
+
vector4s.set(property.numberType, vectorProperties);
|
|
81
|
+
}
|
|
82
|
+
vectorProperties.push(property);
|
|
83
|
+
}
|
|
84
|
+
if (property.type == "bit-array") {
|
|
85
|
+
bitArrays.push(property);
|
|
86
|
+
}
|
|
87
|
+
});
|
|
88
|
+
/*
|
|
89
|
+
[Build Index]
|
|
90
|
+
*/
|
|
91
|
+
const indexSize = schema.size * PropertyIndexSize;
|
|
92
|
+
let indexBuffer = new ArrayBuffer(indexSize);
|
|
93
|
+
if (shared) {
|
|
94
|
+
indexBuffer = new SharedArrayBuffer(indexSize);
|
|
95
|
+
}
|
|
96
|
+
const indexMap = {};
|
|
97
|
+
const index = new DataView(indexBuffer);
|
|
98
|
+
let indexBufferIndex = 0;
|
|
99
|
+
let structSize = 0;
|
|
100
|
+
let bitIndex = 0;
|
|
101
|
+
let bitSize = 1;
|
|
102
|
+
/*
|
|
103
|
+
[Headers]
|
|
104
|
+
*/
|
|
105
|
+
headers.forEach((structProperties, type) => {
|
|
106
|
+
const byteSise = BinaryUtil.getTypedSize(type);
|
|
107
|
+
for (let i = 0; i < structProperties.length; i++) {
|
|
108
|
+
const headerProperties = structProperties[i];
|
|
109
|
+
indexMap[headerProperties.id] = indexBufferIndex;
|
|
110
|
+
indexBufferIndex = SetIndexData(index, indexBufferIndex, structSize, 0, headerProperties.numberType, 0, StructPropertyTypes.TypedNumber);
|
|
111
|
+
structSize += byteSise;
|
|
112
|
+
}
|
|
113
|
+
});
|
|
114
|
+
/*
|
|
115
|
+
[Booleans]
|
|
116
|
+
*/
|
|
117
|
+
bitSize = 1;
|
|
118
|
+
for (let i = 0; i < booleans.length; i++) {
|
|
119
|
+
const booleanProperty = booleans[i];
|
|
120
|
+
indexMap[booleanProperty.id] = indexBufferIndex;
|
|
121
|
+
indexBufferIndex = SetIndexData(index, indexBufferIndex, structSize, bitIndex, bitSize, 0, StructPropertyTypes.Boolean);
|
|
122
|
+
bitIndex++;
|
|
123
|
+
if (bitIndex >= 8) {
|
|
124
|
+
structSize++;
|
|
125
|
+
bitIndex = 0;
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
/*
|
|
129
|
+
[Typed Numbers]
|
|
130
|
+
*/
|
|
131
|
+
bitIndex = 0;
|
|
132
|
+
structSize++;
|
|
133
|
+
typedNumbers.forEach((properties, type) => {
|
|
134
|
+
const byteSise = BinaryUtil.getTypedSize(type);
|
|
135
|
+
for (let i = 0; i < properties.length; i++) {
|
|
136
|
+
const typedNumberProperty = properties[i];
|
|
137
|
+
indexMap[typedNumberProperty.id] = indexBufferIndex;
|
|
138
|
+
indexBufferIndex = SetIndexData(index, indexBufferIndex, structSize, 0, typedNumberProperty.numberType, 0, StructPropertyTypes.TypedNumber);
|
|
139
|
+
structSize += byteSise;
|
|
140
|
+
}
|
|
141
|
+
});
|
|
142
|
+
/*
|
|
143
|
+
[Typed Numbers Arrays]
|
|
144
|
+
*/
|
|
145
|
+
structSize++;
|
|
146
|
+
typedNumbersArrays.forEach((properties, type) => {
|
|
147
|
+
const byteSise = BinaryUtil.getTypedSize(type);
|
|
148
|
+
for (let i = 0; i < properties.length; i++) {
|
|
149
|
+
const typedNumberArrayProperty = properties[i];
|
|
150
|
+
indexMap[typedNumberArrayProperty.id] = indexBufferIndex;
|
|
151
|
+
indexBufferIndex = SetIndexData(index, indexBufferIndex, structSize, 0, typedNumberArrayProperty.numberType, typedNumberArrayProperty.length, StructPropertyTypes.TypedNumberArray);
|
|
152
|
+
structSize += byteSise * typedNumberArrayProperty.length;
|
|
153
|
+
}
|
|
154
|
+
});
|
|
155
|
+
/*
|
|
156
|
+
[vector 2s]
|
|
157
|
+
*/
|
|
158
|
+
structSize++;
|
|
159
|
+
vector2s.forEach((properties, type) => {
|
|
160
|
+
const byteSise = BinaryUtil.getTypedSize(type);
|
|
161
|
+
for (let i = 0; i < properties.length; i++) {
|
|
162
|
+
const vector2Propeerty = properties[i];
|
|
163
|
+
indexMap[vector2Propeerty.id] = indexBufferIndex;
|
|
164
|
+
indexBufferIndex = SetIndexData(index, indexBufferIndex, structSize, 0, vector2Propeerty.numberType, 2, StructPropertyTypes.Vector2);
|
|
165
|
+
structSize += byteSise * 2;
|
|
166
|
+
}
|
|
167
|
+
});
|
|
168
|
+
/*
|
|
169
|
+
[vector 3s]
|
|
170
|
+
*/
|
|
171
|
+
structSize++;
|
|
172
|
+
vector3s.forEach((properties, type) => {
|
|
173
|
+
const byteSise = BinaryUtil.getTypedSize(type);
|
|
174
|
+
for (let i = 0; i < properties.length; i++) {
|
|
175
|
+
const Property = properties[i];
|
|
176
|
+
indexMap[Property.id] = indexBufferIndex;
|
|
177
|
+
indexBufferIndex = SetIndexData(index, indexBufferIndex, structSize, 0, Property.numberType, 3, StructPropertyTypes.Vector3);
|
|
178
|
+
structSize += byteSise * 3;
|
|
179
|
+
}
|
|
180
|
+
});
|
|
181
|
+
/*
|
|
182
|
+
[vector 4s]
|
|
183
|
+
*/
|
|
184
|
+
structSize++;
|
|
185
|
+
vector4s.forEach((properties, type) => {
|
|
186
|
+
const byteSise = BinaryUtil.getTypedSize(type);
|
|
187
|
+
for (let i = 0; i < properties.length; i++) {
|
|
188
|
+
const Property = properties[i];
|
|
189
|
+
indexMap[Property.id] = indexBufferIndex;
|
|
190
|
+
indexBufferIndex = SetIndexData(index, indexBufferIndex, structSize, 0, Property.numberType, 4, StructPropertyTypes.Vector4);
|
|
191
|
+
structSize += byteSise * 4;
|
|
192
|
+
}
|
|
193
|
+
});
|
|
194
|
+
/*
|
|
195
|
+
[bit arrays]
|
|
196
|
+
*/
|
|
197
|
+
structSize++;
|
|
198
|
+
bitArrays.forEach((properties) => {
|
|
199
|
+
const byteSise = Math.ceil(properties.length / 8) + 1;
|
|
200
|
+
indexMap[properties.id] = indexBufferIndex;
|
|
201
|
+
indexBufferIndex = SetIndexData(index, indexBufferIndex, structSize, 0, byteSise, properties.length, StructPropertyTypes.BitArray);
|
|
202
|
+
structSize += byteSise;
|
|
203
|
+
});
|
|
204
|
+
/*
|
|
205
|
+
[Create Remote Property Manager Data]
|
|
206
|
+
*/
|
|
207
|
+
const remoteData = {
|
|
208
|
+
bufferSize: structSize * structArrayIndexes,
|
|
209
|
+
buffer: new ArrayBuffer(0),
|
|
210
|
+
indexBuffer,
|
|
211
|
+
indexMap,
|
|
212
|
+
propertyDefaults,
|
|
213
|
+
structSize,
|
|
214
|
+
structArrayIndexes,
|
|
215
|
+
};
|
|
216
|
+
return remoteData;
|
|
217
|
+
}
|