@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.
@@ -1242,7 +1242,7 @@ var decode = /*#__PURE__*/Object.freeze({
1242
1242
 
1243
1243
  const DEFINITION_MISMATCH = -1;
1244
1244
  function decodeValue(decoder, operation, ref, index, type, bytes, it, allChanges) {
1245
- const $root = decoder.$root;
1245
+ const $root = decoder.root;
1246
1246
  const previousValue = ref[$getByIndex](index);
1247
1247
  let value;
1248
1248
  if ((operation & OPERATION.DELETE) === OPERATION.DELETE) {
@@ -1442,7 +1442,7 @@ const decodeArray = function (decoder, bytes, it, ref, allChanges) {
1442
1442
  else if (operation === OPERATION.DELETE_BY_REFID) {
1443
1443
  // TODO: refactor here, try to follow same flow as below
1444
1444
  const refId = number(bytes, it);
1445
- const previousValue = decoder.$root.refs.get(refId);
1445
+ const previousValue = decoder.root.refs.get(refId);
1446
1446
  const index = ref.findIndex((value) => value === previousValue);
1447
1447
  ref[$deleteByIndex](index);
1448
1448
  allChanges.push({
@@ -3382,7 +3382,7 @@ class Encoder {
3382
3382
  this.state = state;
3383
3383
  state[$changes].setRoot(this.root);
3384
3384
  }
3385
- encode(it = { offset: 0 }, view, bytes = this.sharedBuffer, changeTrees = this.root.changes) {
3385
+ encode(it = { offset: 0 }, view, buffer = this.sharedBuffer, changeTrees = this.root.changes) {
3386
3386
  const initialOffset = it.offset; // cache current offset in case we need to resize the buffer
3387
3387
  const isEncodeAll = this.root.allChanges === changeTrees;
3388
3388
  const hasView = (view !== undefined);
@@ -3404,8 +3404,8 @@ class Encoder {
3404
3404
  }
3405
3405
  // skip root `refId` if it's the first change tree
3406
3406
  if (it.offset !== initialOffset || changeTree !== rootChangeTree) {
3407
- bytes[it.offset++] = SWITCH_TO_STRUCTURE & 255;
3408
- number$1(bytes, changeTree.refId, it);
3407
+ buffer[it.offset++] = SWITCH_TO_STRUCTURE & 255;
3408
+ number$1(buffer, changeTree.refId, it);
3409
3409
  }
3410
3410
  const changesIterator = changes.entries();
3411
3411
  for (const [fieldIndex, operation] of changesIterator) {
@@ -3427,12 +3427,12 @@ class Encoder {
3427
3427
  // fieldIndex,
3428
3428
  // operation: OPERATION[operation],
3429
3429
  // });
3430
- encoder(this, bytes, changeTree, fieldIndex, operation, it, isEncodeAll, hasView);
3430
+ encoder(this, buffer, changeTree, fieldIndex, operation, it, isEncodeAll, hasView);
3431
3431
  }
3432
3432
  }
3433
- if (it.offset > bytes.byteLength) {
3433
+ if (it.offset > buffer.byteLength) {
3434
3434
  const newSize = getNextPowerOf2(this.sharedBuffer.byteLength * 2);
3435
- console.warn("@colyseus/schema encode buffer overflow. Current buffer size: " + bytes.byteLength + ", encoding offset: " + it.offset + ", new size: " + newSize);
3435
+ console.warn("@colyseus/schema encode buffer overflow. Current buffer size: " + buffer.byteLength + ", encoding offset: " + it.offset + ", new size: " + newSize);
3436
3436
  //
3437
3437
  // resize buffer and re-encode (TODO: can we avoid re-encoding here?)
3438
3438
  //
@@ -3450,15 +3450,15 @@ class Encoder {
3450
3450
  this.onEndEncode(changeTrees);
3451
3451
  }
3452
3452
  // return bytes;
3453
- return bytes.slice(0, it.offset);
3453
+ return buffer.slice(0, it.offset);
3454
3454
  }
3455
3455
  }
3456
- encodeAll(it = { offset: 0 }) {
3456
+ encodeAll(it = { offset: 0 }, buffer = this.sharedBuffer) {
3457
3457
  // console.log(`encodeAll(), this.$root.allChanges (${this.$root.allChanges.size})`);
3458
3458
  // Array.from(this.$root.allChanges.entries()).map((item) => {
3459
3459
  // console.log("->", item[0].refId, item[0].ref.toJSON());
3460
3460
  // });
3461
- return this.encode(it, undefined, this.sharedBuffer, this.root.allChanges);
3461
+ return this.encode(it, undefined, buffer, this.root.allChanges);
3462
3462
  }
3463
3463
  encodeAllView(view, sharedOffset, it, bytes = this.sharedBuffer) {
3464
3464
  const viewOffset = it.offset;
@@ -3692,12 +3692,12 @@ class Decoder {
3692
3692
  }
3693
3693
  setRoot(root) {
3694
3694
  this.state = root;
3695
- this.$root = new ReferenceTracker();
3696
- this.$root.addRef(0, root);
3695
+ this.root = new ReferenceTracker();
3696
+ this.root.addRef(0, root);
3697
3697
  }
3698
3698
  decode(bytes, it = { offset: 0 }, ref = this.state) {
3699
3699
  const allChanges = [];
3700
- const $root = this.$root;
3700
+ const $root = this.root;
3701
3701
  const totalBytes = bytes.byteLength;
3702
3702
  let decoder = ref['constructor'][$decoder];
3703
3703
  this.currentRefId = 0;
@@ -3778,7 +3778,7 @@ class Decoder {
3778
3778
  previousValue: value
3779
3779
  });
3780
3780
  if (needRemoveRef) {
3781
- this.$root.removeRef(this.$root.refIds.get(value));
3781
+ this.root.removeRef(this.root.refIds.get(value));
3782
3782
  }
3783
3783
  });
3784
3784
  }