mcbe-ipc 3.3.1 → 3.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/dist/ipc.d.ts CHANGED
@@ -81,6 +81,7 @@ export declare namespace PROTO {
81
81
  function Optional<T>(s: PROTO.Serializable<T>): PROTO.Serializable<T | undefined>;
82
82
  function Map<K, V>(kS: PROTO.Serializable<K>, vS: PROTO.Serializable<V>): PROTO.Serializable<Map<K, V>>;
83
83
  function Set<V>(s: PROTO.Serializable<V>): PROTO.Serializable<Set<V>>;
84
+ function Cached<V>(s: PROTO.Serializable<V>, depth?: number): PROTO.Serializable<V>;
84
85
  }
85
86
  export declare namespace NET {
86
87
  type Meta = {
package/dist/ipc.js CHANGED
@@ -402,6 +402,34 @@ export var PROTO;
402
402
  };
403
403
  }
404
404
  PROTO.Set = Set;
405
+ function Cached(s, depth = 16) {
406
+ const cache = new globalThis.Map();
407
+ return {
408
+ *serialize(value, stream) {
409
+ const hit = cache.get(value);
410
+ if (hit !== undefined) {
411
+ stream.write(hit);
412
+ cache.delete(value);
413
+ cache.set(value, hit);
414
+ }
415
+ else {
416
+ const buffer = new PROTO.Buffer();
417
+ yield* s.serialize(value, buffer);
418
+ const bytes = buffer.to_uint8array();
419
+ stream.write(bytes);
420
+ cache.set(value, bytes);
421
+ if (cache.size > depth) {
422
+ const first = cache.keys().next().value;
423
+ cache.delete(first);
424
+ }
425
+ }
426
+ },
427
+ *deserialize(stream) {
428
+ return yield* s.deserialize(stream);
429
+ }
430
+ };
431
+ }
432
+ PROTO.Cached = Cached;
405
433
  })(PROTO || (PROTO = {}));
406
434
  export var NET;
407
435
  (function (NET) {
package/package.json CHANGED
@@ -3,7 +3,7 @@
3
3
  "author": "OmniacDev",
4
4
  "description": "IPC system for MCBE Script API projects",
5
5
  "license": "MIT",
6
- "version": "3.3.1",
6
+ "version": "3.4.0",
7
7
  "repository": {
8
8
  "type": "git",
9
9
  "url": "git+https://github.com/OmniacDev/MCBE-IPC.git"