mcbe-ipc 3.0.4 → 3.1.4
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 +18 -12
- package/dist/ipc.d.ts +21 -17
- package/dist/ipc.js +74 -67
- package/package.json +5 -5
- package/dist/direct.ipc.d.ts +0 -61
- package/dist/direct.ipc.js +0 -369
- package/dist/proto.d.ts +0 -84
- package/dist/proto.js +0 -408
package/dist/proto.js
DELETED
|
@@ -1,408 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @license
|
|
3
|
-
* MIT License
|
|
4
|
-
*
|
|
5
|
-
* Copyright (c) 2025 OmniacDev
|
|
6
|
-
*
|
|
7
|
-
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
8
|
-
* of this software and associated documentation files (the "Software"), to deal
|
|
9
|
-
* in the Software without restriction, including without limitation the rights
|
|
10
|
-
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
11
|
-
* copies of the Software, and to permit persons to whom the Software is
|
|
12
|
-
* furnished to do so, subject to the following conditions:
|
|
13
|
-
*
|
|
14
|
-
* The above copyright notice and this permission notice shall be included in all
|
|
15
|
-
* copies or substantial portions of the Software.
|
|
16
|
-
*
|
|
17
|
-
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
18
|
-
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
19
|
-
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
20
|
-
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
21
|
-
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
22
|
-
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
23
|
-
* SOFTWARE.
|
|
24
|
-
*/
|
|
25
|
-
export var PROTO;
|
|
26
|
-
(function (PROTO) {
|
|
27
|
-
class ByteQueue {
|
|
28
|
-
get end() {
|
|
29
|
-
return this._length + this._offset;
|
|
30
|
-
}
|
|
31
|
-
get front() {
|
|
32
|
-
return this._offset;
|
|
33
|
-
}
|
|
34
|
-
get data_view() {
|
|
35
|
-
return this._data_view;
|
|
36
|
-
}
|
|
37
|
-
constructor(size = 256) {
|
|
38
|
-
this._buffer = new Uint8Array(size);
|
|
39
|
-
this._data_view = new DataView(this._buffer.buffer);
|
|
40
|
-
this._length = 0;
|
|
41
|
-
this._offset = 0;
|
|
42
|
-
}
|
|
43
|
-
write(...values) {
|
|
44
|
-
this.ensure_capacity(values.length);
|
|
45
|
-
this._buffer.set(values, this.end);
|
|
46
|
-
this._length += values.length;
|
|
47
|
-
}
|
|
48
|
-
read(amount = 1) {
|
|
49
|
-
if (this._length > 0) {
|
|
50
|
-
const max_amount = amount > this._length ? this._length : amount;
|
|
51
|
-
const values = this._buffer.subarray(this._offset, this._offset + max_amount);
|
|
52
|
-
this._length -= max_amount;
|
|
53
|
-
this._offset += max_amount;
|
|
54
|
-
return globalThis.Array.from(values);
|
|
55
|
-
}
|
|
56
|
-
return [];
|
|
57
|
-
}
|
|
58
|
-
ensure_capacity(size) {
|
|
59
|
-
if (this.end + size > this._buffer.length) {
|
|
60
|
-
const larger_buffer = new Uint8Array((this.end + size) * 2);
|
|
61
|
-
larger_buffer.set(this._buffer.subarray(this._offset, this.end), 0);
|
|
62
|
-
this._buffer = larger_buffer;
|
|
63
|
-
this._offset = 0;
|
|
64
|
-
this._data_view = new DataView(this._buffer.buffer);
|
|
65
|
-
}
|
|
66
|
-
}
|
|
67
|
-
static from_uint8array(array) {
|
|
68
|
-
const byte_queue = new ByteQueue();
|
|
69
|
-
byte_queue._buffer = array;
|
|
70
|
-
byte_queue._length = array.length;
|
|
71
|
-
byte_queue._offset = 0;
|
|
72
|
-
byte_queue._data_view = new DataView(array.buffer);
|
|
73
|
-
return byte_queue;
|
|
74
|
-
}
|
|
75
|
-
to_uint8array() {
|
|
76
|
-
return this._buffer.subarray(this._offset, this.end);
|
|
77
|
-
}
|
|
78
|
-
}
|
|
79
|
-
PROTO.ByteQueue = ByteQueue;
|
|
80
|
-
let MIPS;
|
|
81
|
-
(function (MIPS) {
|
|
82
|
-
function* serialize(byte_queue) {
|
|
83
|
-
const uint8array = byte_queue.to_uint8array();
|
|
84
|
-
let str = '(0x';
|
|
85
|
-
for (let i = 0; i < uint8array.length; i++) {
|
|
86
|
-
const hex = uint8array[i].toString(16).padStart(2, '0').toUpperCase();
|
|
87
|
-
str += hex;
|
|
88
|
-
yield;
|
|
89
|
-
}
|
|
90
|
-
str += ')';
|
|
91
|
-
return str;
|
|
92
|
-
}
|
|
93
|
-
MIPS.serialize = serialize;
|
|
94
|
-
function* deserialize(str) {
|
|
95
|
-
if (str.startsWith('(0x') && str.endsWith(')')) {
|
|
96
|
-
const result = [];
|
|
97
|
-
const hex_str = str.slice(3, str.length - 1);
|
|
98
|
-
for (let i = 0; i < hex_str.length; i++) {
|
|
99
|
-
const hex = hex_str[i] + hex_str[++i];
|
|
100
|
-
result.push(parseInt(hex, 16));
|
|
101
|
-
yield;
|
|
102
|
-
}
|
|
103
|
-
return ByteQueue.from_uint8array(new Uint8Array(result));
|
|
104
|
-
}
|
|
105
|
-
return new ByteQueue();
|
|
106
|
-
}
|
|
107
|
-
MIPS.deserialize = deserialize;
|
|
108
|
-
})(MIPS = PROTO.MIPS || (PROTO.MIPS = {}));
|
|
109
|
-
PROTO.Void = {
|
|
110
|
-
*serialize() { },
|
|
111
|
-
*deserialize() { }
|
|
112
|
-
};
|
|
113
|
-
PROTO.Null = {
|
|
114
|
-
*serialize() { },
|
|
115
|
-
*deserialize() {
|
|
116
|
-
return null;
|
|
117
|
-
}
|
|
118
|
-
};
|
|
119
|
-
PROTO.Undefined = {
|
|
120
|
-
*serialize() { },
|
|
121
|
-
*deserialize() {
|
|
122
|
-
return undefined;
|
|
123
|
-
}
|
|
124
|
-
};
|
|
125
|
-
PROTO.Int8 = {
|
|
126
|
-
*serialize(value, stream) {
|
|
127
|
-
const length = 1;
|
|
128
|
-
stream.write(...globalThis.Array(length).fill(0));
|
|
129
|
-
stream.data_view.setInt8(stream.end - length, value);
|
|
130
|
-
},
|
|
131
|
-
*deserialize(stream) {
|
|
132
|
-
const value = stream.data_view.getInt8(stream.front);
|
|
133
|
-
stream.read(1);
|
|
134
|
-
return value;
|
|
135
|
-
}
|
|
136
|
-
};
|
|
137
|
-
PROTO.Int16 = {
|
|
138
|
-
*serialize(value, stream) {
|
|
139
|
-
const length = 2;
|
|
140
|
-
stream.write(...globalThis.Array(length).fill(0));
|
|
141
|
-
stream.data_view.setInt16(stream.end - length, value);
|
|
142
|
-
},
|
|
143
|
-
*deserialize(stream) {
|
|
144
|
-
const value = stream.data_view.getInt16(stream.front);
|
|
145
|
-
stream.read(2);
|
|
146
|
-
return value;
|
|
147
|
-
}
|
|
148
|
-
};
|
|
149
|
-
PROTO.Int32 = {
|
|
150
|
-
*serialize(value, stream) {
|
|
151
|
-
const length = 4;
|
|
152
|
-
stream.write(...globalThis.Array(length).fill(0));
|
|
153
|
-
stream.data_view.setInt32(stream.end - length, value);
|
|
154
|
-
},
|
|
155
|
-
*deserialize(stream) {
|
|
156
|
-
const value = stream.data_view.getInt32(stream.front);
|
|
157
|
-
stream.read(4);
|
|
158
|
-
return value;
|
|
159
|
-
}
|
|
160
|
-
};
|
|
161
|
-
PROTO.UInt8 = {
|
|
162
|
-
*serialize(value, stream) {
|
|
163
|
-
const length = 1;
|
|
164
|
-
stream.write(...globalThis.Array(length).fill(0));
|
|
165
|
-
stream.data_view.setUint8(stream.end - length, value);
|
|
166
|
-
},
|
|
167
|
-
*deserialize(stream) {
|
|
168
|
-
const value = stream.data_view.getUint8(stream.front);
|
|
169
|
-
stream.read(1);
|
|
170
|
-
return value;
|
|
171
|
-
}
|
|
172
|
-
};
|
|
173
|
-
PROTO.UInt16 = {
|
|
174
|
-
*serialize(value, stream) {
|
|
175
|
-
const length = 2;
|
|
176
|
-
stream.write(...globalThis.Array(length).fill(0));
|
|
177
|
-
stream.data_view.setUint16(stream.end - length, value);
|
|
178
|
-
},
|
|
179
|
-
*deserialize(stream) {
|
|
180
|
-
const value = stream.data_view.getUint16(stream.front);
|
|
181
|
-
stream.read(2);
|
|
182
|
-
return value;
|
|
183
|
-
}
|
|
184
|
-
};
|
|
185
|
-
PROTO.UInt32 = {
|
|
186
|
-
*serialize(value, stream) {
|
|
187
|
-
const length = 4;
|
|
188
|
-
stream.write(...globalThis.Array(length).fill(0));
|
|
189
|
-
stream.data_view.setUint32(stream.end - length, value);
|
|
190
|
-
},
|
|
191
|
-
*deserialize(stream) {
|
|
192
|
-
const value = stream.data_view.getUint32(stream.front);
|
|
193
|
-
stream.read(4);
|
|
194
|
-
return value;
|
|
195
|
-
}
|
|
196
|
-
};
|
|
197
|
-
PROTO.UVarInt32 = {
|
|
198
|
-
*serialize(value, stream) {
|
|
199
|
-
while (value >= 0x80) {
|
|
200
|
-
stream.write((value & 0x7f) | 0x80);
|
|
201
|
-
value >>= 7;
|
|
202
|
-
yield;
|
|
203
|
-
}
|
|
204
|
-
stream.write(value);
|
|
205
|
-
},
|
|
206
|
-
*deserialize(stream) {
|
|
207
|
-
let value = 0;
|
|
208
|
-
let size = 0;
|
|
209
|
-
let byte;
|
|
210
|
-
do {
|
|
211
|
-
byte = stream.read()[0];
|
|
212
|
-
value |= (byte & 0x7f) << (size * 7);
|
|
213
|
-
size += 1;
|
|
214
|
-
yield;
|
|
215
|
-
} while ((byte & 0x80) !== 0 && size < 10);
|
|
216
|
-
return value;
|
|
217
|
-
}
|
|
218
|
-
};
|
|
219
|
-
PROTO.Float32 = {
|
|
220
|
-
*serialize(value, stream) {
|
|
221
|
-
const length = 4;
|
|
222
|
-
stream.write(...globalThis.Array(length).fill(0));
|
|
223
|
-
stream.data_view.setFloat32(stream.end - length, value);
|
|
224
|
-
},
|
|
225
|
-
*deserialize(stream) {
|
|
226
|
-
const value = stream.data_view.getFloat32(stream.front);
|
|
227
|
-
stream.read(4);
|
|
228
|
-
return value;
|
|
229
|
-
}
|
|
230
|
-
};
|
|
231
|
-
PROTO.Float64 = {
|
|
232
|
-
*serialize(value, stream) {
|
|
233
|
-
const length = 8;
|
|
234
|
-
stream.write(...globalThis.Array(length).fill(0));
|
|
235
|
-
stream.data_view.setFloat64(stream.end - length, value);
|
|
236
|
-
},
|
|
237
|
-
*deserialize(stream) {
|
|
238
|
-
const value = stream.data_view.getFloat64(stream.front);
|
|
239
|
-
stream.read(8);
|
|
240
|
-
return value;
|
|
241
|
-
}
|
|
242
|
-
};
|
|
243
|
-
PROTO.String = {
|
|
244
|
-
*serialize(value, stream) {
|
|
245
|
-
yield* PROTO.UVarInt32.serialize(value.length, stream);
|
|
246
|
-
for (let i = 0; i < value.length; i++) {
|
|
247
|
-
const code = value.charCodeAt(i);
|
|
248
|
-
yield* PROTO.UVarInt32.serialize(code, stream);
|
|
249
|
-
}
|
|
250
|
-
},
|
|
251
|
-
*deserialize(stream) {
|
|
252
|
-
const length = yield* PROTO.UVarInt32.deserialize(stream);
|
|
253
|
-
let value = '';
|
|
254
|
-
for (let i = 0; i < length; i++) {
|
|
255
|
-
const code = yield* PROTO.UVarInt32.deserialize(stream);
|
|
256
|
-
value += globalThis.String.fromCharCode(code);
|
|
257
|
-
}
|
|
258
|
-
return value;
|
|
259
|
-
}
|
|
260
|
-
};
|
|
261
|
-
PROTO.Boolean = {
|
|
262
|
-
*serialize(value, stream) {
|
|
263
|
-
stream.write(value ? 1 : 0);
|
|
264
|
-
},
|
|
265
|
-
*deserialize(stream) {
|
|
266
|
-
const value = stream.read()[0];
|
|
267
|
-
return value === 1;
|
|
268
|
-
}
|
|
269
|
-
};
|
|
270
|
-
PROTO.UInt8Array = {
|
|
271
|
-
*serialize(value, stream) {
|
|
272
|
-
yield* PROTO.UVarInt32.serialize(value.length, stream);
|
|
273
|
-
stream.write(...value);
|
|
274
|
-
},
|
|
275
|
-
*deserialize(stream) {
|
|
276
|
-
const length = yield* PROTO.UVarInt32.deserialize(stream);
|
|
277
|
-
return new Uint8Array(stream.read(length));
|
|
278
|
-
}
|
|
279
|
-
};
|
|
280
|
-
PROTO.Date = {
|
|
281
|
-
*serialize(value, stream) {
|
|
282
|
-
yield* PROTO.Float64.serialize(value.getTime(), stream);
|
|
283
|
-
},
|
|
284
|
-
*deserialize(stream) {
|
|
285
|
-
return new globalThis.Date(yield* PROTO.Float64.deserialize(stream));
|
|
286
|
-
}
|
|
287
|
-
};
|
|
288
|
-
function Object(obj) {
|
|
289
|
-
return {
|
|
290
|
-
*serialize(value, stream) {
|
|
291
|
-
for (const key in obj) {
|
|
292
|
-
yield* obj[key].serialize(value[key], stream);
|
|
293
|
-
}
|
|
294
|
-
},
|
|
295
|
-
*deserialize(stream) {
|
|
296
|
-
const result = {};
|
|
297
|
-
for (const key in obj) {
|
|
298
|
-
result[key] = yield* obj[key].deserialize(stream);
|
|
299
|
-
}
|
|
300
|
-
return result;
|
|
301
|
-
}
|
|
302
|
-
};
|
|
303
|
-
}
|
|
304
|
-
PROTO.Object = Object;
|
|
305
|
-
function Array(value) {
|
|
306
|
-
return {
|
|
307
|
-
*serialize(array, stream) {
|
|
308
|
-
yield* PROTO.UVarInt32.serialize(array.length, stream);
|
|
309
|
-
for (const item of array) {
|
|
310
|
-
yield* value.serialize(item, stream);
|
|
311
|
-
}
|
|
312
|
-
},
|
|
313
|
-
*deserialize(stream) {
|
|
314
|
-
const result = [];
|
|
315
|
-
const length = yield* PROTO.UVarInt32.deserialize(stream);
|
|
316
|
-
for (let i = 0; i < length; i++) {
|
|
317
|
-
result[i] = yield* value.deserialize(stream);
|
|
318
|
-
}
|
|
319
|
-
return result;
|
|
320
|
-
}
|
|
321
|
-
};
|
|
322
|
-
}
|
|
323
|
-
PROTO.Array = Array;
|
|
324
|
-
function Tuple(...values) {
|
|
325
|
-
return {
|
|
326
|
-
*serialize(tuple, stream) {
|
|
327
|
-
for (let i = 0; i < values.length; i++) {
|
|
328
|
-
yield* values[i].serialize(tuple[i], stream);
|
|
329
|
-
}
|
|
330
|
-
},
|
|
331
|
-
*deserialize(stream) {
|
|
332
|
-
const result = [];
|
|
333
|
-
for (let i = 0; i < values.length; i++) {
|
|
334
|
-
result[i] = yield* values[i].deserialize(stream);
|
|
335
|
-
}
|
|
336
|
-
return result;
|
|
337
|
-
}
|
|
338
|
-
};
|
|
339
|
-
}
|
|
340
|
-
PROTO.Tuple = Tuple;
|
|
341
|
-
function Optional(value) {
|
|
342
|
-
return {
|
|
343
|
-
*serialize(optional, stream) {
|
|
344
|
-
yield* PROTO.Boolean.serialize(optional !== undefined, stream);
|
|
345
|
-
if (optional !== undefined) {
|
|
346
|
-
yield* value.serialize(optional, stream);
|
|
347
|
-
}
|
|
348
|
-
},
|
|
349
|
-
*deserialize(stream) {
|
|
350
|
-
const defined = yield* PROTO.Boolean.deserialize(stream);
|
|
351
|
-
if (defined) {
|
|
352
|
-
return yield* value.deserialize(stream);
|
|
353
|
-
}
|
|
354
|
-
return undefined;
|
|
355
|
-
}
|
|
356
|
-
};
|
|
357
|
-
}
|
|
358
|
-
PROTO.Optional = Optional;
|
|
359
|
-
function Map(key, value) {
|
|
360
|
-
return {
|
|
361
|
-
*serialize(map, stream) {
|
|
362
|
-
yield* PROTO.UVarInt32.serialize(map.size, stream);
|
|
363
|
-
for (const [k, v] of map.entries()) {
|
|
364
|
-
yield* key.serialize(k, stream);
|
|
365
|
-
yield* value.serialize(v, stream);
|
|
366
|
-
}
|
|
367
|
-
},
|
|
368
|
-
*deserialize(stream) {
|
|
369
|
-
const size = yield* PROTO.UVarInt32.deserialize(stream);
|
|
370
|
-
const result = new globalThis.Map();
|
|
371
|
-
for (let i = 0; i < size; i++) {
|
|
372
|
-
const k = yield* key.deserialize(stream);
|
|
373
|
-
const v = yield* value.deserialize(stream);
|
|
374
|
-
result.set(k, v);
|
|
375
|
-
}
|
|
376
|
-
return result;
|
|
377
|
-
}
|
|
378
|
-
};
|
|
379
|
-
}
|
|
380
|
-
PROTO.Map = Map;
|
|
381
|
-
function Set(value) {
|
|
382
|
-
return {
|
|
383
|
-
*serialize(set, stream) {
|
|
384
|
-
yield* PROTO.UVarInt32.serialize(set.size, stream);
|
|
385
|
-
for (const [_, v] of set.entries()) {
|
|
386
|
-
yield* value.serialize(v, stream);
|
|
387
|
-
}
|
|
388
|
-
},
|
|
389
|
-
*deserialize(stream) {
|
|
390
|
-
const size = yield* PROTO.UVarInt32.deserialize(stream);
|
|
391
|
-
const result = new globalThis.Set();
|
|
392
|
-
for (let i = 0; i < size; i++) {
|
|
393
|
-
const v = yield* value.deserialize(stream);
|
|
394
|
-
result.add(v);
|
|
395
|
-
}
|
|
396
|
-
return result;
|
|
397
|
-
}
|
|
398
|
-
};
|
|
399
|
-
}
|
|
400
|
-
PROTO.Set = Set;
|
|
401
|
-
PROTO.Endpoint = PROTO.String;
|
|
402
|
-
PROTO.Header = PROTO.Object({
|
|
403
|
-
guid: PROTO.String,
|
|
404
|
-
encoding: PROTO.String,
|
|
405
|
-
index: PROTO.UVarInt32,
|
|
406
|
-
final: PROTO.Boolean
|
|
407
|
-
});
|
|
408
|
-
})(PROTO || (PROTO = {}));
|