@colyseus/schema 3.0.0-alpha.5 → 3.0.0-alpha.7

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.
@@ -1246,7 +1246,7 @@ var decode = /*#__PURE__*/Object.freeze({
1246
1246
 
1247
1247
  const DEFINITION_MISMATCH = -1;
1248
1248
  function decodeValue(decoder, operation, ref, index, type, bytes, it, allChanges) {
1249
- const $root = decoder.$root;
1249
+ const $root = decoder.root;
1250
1250
  const previousValue = ref[$getByIndex](index);
1251
1251
  let value;
1252
1252
  if ((operation & exports.OPERATION.DELETE) === exports.OPERATION.DELETE) {
@@ -1446,7 +1446,7 @@ const decodeArray = function (decoder, bytes, it, ref, allChanges) {
1446
1446
  else if (operation === exports.OPERATION.DELETE_BY_REFID) {
1447
1447
  // TODO: refactor here, try to follow same flow as below
1448
1448
  const refId = number(bytes, it);
1449
- const previousValue = decoder.$root.refs.get(refId);
1449
+ const previousValue = decoder.root.refs.get(refId);
1450
1450
  const index = ref.findIndex((value) => value === previousValue);
1451
1451
  ref[$deleteByIndex](index);
1452
1452
  allChanges.push({
@@ -3386,7 +3386,7 @@ class Encoder {
3386
3386
  this.state = state;
3387
3387
  state[$changes].setRoot(this.root);
3388
3388
  }
3389
- encode(it = { offset: 0 }, view, bytes = this.sharedBuffer, changeTrees = this.root.changes) {
3389
+ encode(it = { offset: 0 }, view, buffer = this.sharedBuffer, changeTrees = this.root.changes) {
3390
3390
  const initialOffset = it.offset; // cache current offset in case we need to resize the buffer
3391
3391
  const isEncodeAll = this.root.allChanges === changeTrees;
3392
3392
  const hasView = (view !== undefined);
@@ -3408,8 +3408,8 @@ class Encoder {
3408
3408
  }
3409
3409
  // skip root `refId` if it's the first change tree
3410
3410
  if (it.offset !== initialOffset || changeTree !== rootChangeTree) {
3411
- bytes[it.offset++] = SWITCH_TO_STRUCTURE & 255;
3412
- number$1(bytes, changeTree.refId, it);
3411
+ buffer[it.offset++] = SWITCH_TO_STRUCTURE & 255;
3412
+ number$1(buffer, changeTree.refId, it);
3413
3413
  }
3414
3414
  const changesIterator = changes.entries();
3415
3415
  for (const [fieldIndex, operation] of changesIterator) {
@@ -3431,12 +3431,12 @@ class Encoder {
3431
3431
  // fieldIndex,
3432
3432
  // operation: OPERATION[operation],
3433
3433
  // });
3434
- encoder(this, bytes, changeTree, fieldIndex, operation, it, isEncodeAll, hasView);
3434
+ encoder(this, buffer, changeTree, fieldIndex, operation, it, isEncodeAll, hasView);
3435
3435
  }
3436
3436
  }
3437
- if (it.offset > bytes.byteLength) {
3437
+ if (it.offset > buffer.byteLength) {
3438
3438
  const newSize = getNextPowerOf2(this.sharedBuffer.byteLength * 2);
3439
- console.warn("@colyseus/schema encode buffer overflow. Current buffer size: " + bytes.byteLength + ", encoding offset: " + it.offset + ", new size: " + newSize);
3439
+ console.warn("@colyseus/schema encode buffer overflow. Current buffer size: " + buffer.byteLength + ", encoding offset: " + it.offset + ", new size: " + newSize);
3440
3440
  //
3441
3441
  // resize buffer and re-encode (TODO: can we avoid re-encoding here?)
3442
3442
  //
@@ -3454,15 +3454,15 @@ class Encoder {
3454
3454
  this.onEndEncode(changeTrees);
3455
3455
  }
3456
3456
  // return bytes;
3457
- return bytes.slice(0, it.offset);
3457
+ return buffer.slice(0, it.offset);
3458
3458
  }
3459
3459
  }
3460
- encodeAll(it = { offset: 0 }) {
3460
+ encodeAll(it = { offset: 0 }, buffer = this.sharedBuffer) {
3461
3461
  // console.log(`encodeAll(), this.$root.allChanges (${this.$root.allChanges.size})`);
3462
3462
  // Array.from(this.$root.allChanges.entries()).map((item) => {
3463
3463
  // console.log("->", item[0].refId, item[0].ref.toJSON());
3464
3464
  // });
3465
- return this.encode(it, undefined, this.sharedBuffer, this.root.allChanges);
3465
+ return this.encode(it, undefined, buffer, this.root.allChanges);
3466
3466
  }
3467
3467
  encodeAllView(view, sharedOffset, it, bytes = this.sharedBuffer) {
3468
3468
  const viewOffset = it.offset;
@@ -3696,12 +3696,12 @@ class Decoder {
3696
3696
  }
3697
3697
  setRoot(root) {
3698
3698
  this.state = root;
3699
- this.$root = new ReferenceTracker();
3700
- this.$root.addRef(0, root);
3699
+ this.root = new ReferenceTracker();
3700
+ this.root.addRef(0, root);
3701
3701
  }
3702
3702
  decode(bytes, it = { offset: 0 }, ref = this.state) {
3703
3703
  const allChanges = [];
3704
- const $root = this.$root;
3704
+ const $root = this.root;
3705
3705
  const totalBytes = bytes.byteLength;
3706
3706
  let decoder = ref['constructor'][$decoder];
3707
3707
  this.currentRefId = 0;
@@ -3782,7 +3782,7 @@ class Decoder {
3782
3782
  previousValue: value
3783
3783
  });
3784
3784
  if (needRemoveRef) {
3785
- this.$root.removeRef(this.$root.refIds.get(value));
3785
+ this.root.removeRef(this.root.refIds.get(value));
3786
3786
  }
3787
3787
  });
3788
3788
  }