@colyseus/schema 3.0.0-alpha.1 → 3.0.0-alpha.3
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/build/cjs/index.js +40 -20
- package/build/cjs/index.js.map +1 -1
- package/build/esm/index.mjs +40 -20
- package/build/esm/index.mjs.map +1 -1
- package/build/umd/index.js +40 -20
- package/lib/encoder/ChangeTree.d.ts +0 -2
- package/lib/encoder/ChangeTree.js +0 -1
- package/lib/encoder/ChangeTree.js.map +1 -1
- package/lib/encoder/Encoder.d.ts +4 -5
- package/lib/encoder/Encoder.js +14 -14
- package/lib/encoder/Encoder.js.map +1 -1
- package/lib/encoder/StateView.d.ts +2 -0
- package/lib/encoder/StateView.js +4 -1
- package/lib/encoder/StateView.js.map +1 -1
- package/lib/encoding/decode.d.ts +21 -19
- package/lib/encoding/decode.js +6 -6
- package/lib/encoding/decode.js.map +1 -1
- package/lib/encoding/encode.d.ts +2 -2
- package/lib/encoding/encode.js +2 -1
- package/lib/encoding/encode.js.map +1 -1
- package/package.json +1 -1
- package/src/encoder/ChangeTree.ts +0 -2
- package/src/encoder/Encoder.ts +17 -18
- package/src/encoder/StateView.ts +4 -0
- package/src/encoding/decode.ts +25 -25
- package/src/encoding/encode.ts +2 -2
package/build/esm/index.mjs
CHANGED
|
@@ -164,7 +164,6 @@ class Root {
|
|
|
164
164
|
// pending changes to be encoded
|
|
165
165
|
this.changes = new Map();
|
|
166
166
|
this.filteredChanges = new Map();
|
|
167
|
-
this.views = [];
|
|
168
167
|
}
|
|
169
168
|
getNextUniqueId() {
|
|
170
169
|
return this.nextUniqueId++;
|
|
@@ -560,6 +559,26 @@ try {
|
|
|
560
559
|
textEncoder = new TextEncoder();
|
|
561
560
|
}
|
|
562
561
|
catch (e) { }
|
|
562
|
+
function utf8Length(str) {
|
|
563
|
+
var c = 0, length = 0;
|
|
564
|
+
for (var i = 0, l = str.length; i < l; i++) {
|
|
565
|
+
c = str.charCodeAt(i);
|
|
566
|
+
if (c < 0x80) {
|
|
567
|
+
length += 1;
|
|
568
|
+
}
|
|
569
|
+
else if (c < 0x800) {
|
|
570
|
+
length += 2;
|
|
571
|
+
}
|
|
572
|
+
else if (c < 0xd800 || c >= 0xe000) {
|
|
573
|
+
length += 3;
|
|
574
|
+
}
|
|
575
|
+
else {
|
|
576
|
+
i++;
|
|
577
|
+
length += 4;
|
|
578
|
+
}
|
|
579
|
+
}
|
|
580
|
+
return length;
|
|
581
|
+
}
|
|
563
582
|
function utf8Write(view, str, it) {
|
|
564
583
|
var c = 0;
|
|
565
584
|
for (var i = 0, l = str.length; i < l; i++) {
|
|
@@ -766,6 +785,7 @@ function number$1(bytes, value, it) {
|
|
|
766
785
|
|
|
767
786
|
var encode = /*#__PURE__*/Object.freeze({
|
|
768
787
|
__proto__: null,
|
|
788
|
+
utf8Length: utf8Length,
|
|
769
789
|
utf8Write: utf8Write,
|
|
770
790
|
int8: int8$1,
|
|
771
791
|
uint8: uint8$1,
|
|
@@ -989,9 +1009,10 @@ const encodeArray = function (encoder, bytes, changeTree, field, operation, it,
|
|
|
989
1009
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
990
1010
|
* SOFTWARE
|
|
991
1011
|
*/
|
|
992
|
-
function utf8Read(bytes,
|
|
1012
|
+
function utf8Read(bytes, it, length) {
|
|
1013
|
+
it.offset += length;
|
|
993
1014
|
var string = '', chr = 0;
|
|
994
|
-
for (var i = offset, end = offset + length; i < end; i++) {
|
|
1015
|
+
for (var i = it.offset, end = it.offset + length; i < end; i++) {
|
|
995
1016
|
var byte = bytes[i];
|
|
996
1017
|
if ((byte & 0x80) === 0x00) {
|
|
997
1018
|
string += String.fromCharCode(byte);
|
|
@@ -1093,9 +1114,7 @@ function string(bytes, it) {
|
|
|
1093
1114
|
else if (prefix === 0xdb) {
|
|
1094
1115
|
length = uint32(bytes, it);
|
|
1095
1116
|
}
|
|
1096
|
-
|
|
1097
|
-
it.offset += length;
|
|
1098
|
-
return value;
|
|
1117
|
+
return utf8Read(bytes, it, length);
|
|
1099
1118
|
}
|
|
1100
1119
|
function stringCheck(bytes, it) {
|
|
1101
1120
|
const prefix = bytes[it.offset];
|
|
@@ -1199,6 +1218,7 @@ function switchStructureCheck(bytes, it) {
|
|
|
1199
1218
|
|
|
1200
1219
|
var decode = /*#__PURE__*/Object.freeze({
|
|
1201
1220
|
__proto__: null,
|
|
1221
|
+
utf8Read: utf8Read,
|
|
1202
1222
|
int8: int8,
|
|
1203
1223
|
uint8: uint8,
|
|
1204
1224
|
int16: int16,
|
|
@@ -3358,13 +3378,13 @@ class Encoder {
|
|
|
3358
3378
|
// });
|
|
3359
3379
|
}
|
|
3360
3380
|
setRoot(state) {
|
|
3361
|
-
this
|
|
3381
|
+
this.root = new Root();
|
|
3362
3382
|
this.state = state;
|
|
3363
|
-
state[$changes].setRoot(this
|
|
3383
|
+
state[$changes].setRoot(this.root);
|
|
3364
3384
|
}
|
|
3365
|
-
encode(it = { offset: 0 }, view, bytes = this.sharedBuffer, changeTrees = this
|
|
3385
|
+
encode(it = { offset: 0 }, view, bytes = this.sharedBuffer, changeTrees = this.root.changes) {
|
|
3366
3386
|
const initialOffset = it.offset; // cache current offset in case we need to resize the buffer
|
|
3367
|
-
const isEncodeAll = this
|
|
3387
|
+
const isEncodeAll = this.root.allChanges === changeTrees;
|
|
3368
3388
|
const hasView = (view !== undefined);
|
|
3369
3389
|
const rootChangeTree = this.state[$changes];
|
|
3370
3390
|
const changeTreesIterator = changeTrees.entries();
|
|
@@ -3438,14 +3458,14 @@ class Encoder {
|
|
|
3438
3458
|
// Array.from(this.$root.allChanges.entries()).map((item) => {
|
|
3439
3459
|
// console.log("->", item[0].refId, item[0].ref.toJSON());
|
|
3440
3460
|
// });
|
|
3441
|
-
return this.encode(it, undefined, this.sharedBuffer, this
|
|
3461
|
+
return this.encode(it, undefined, this.sharedBuffer, this.root.allChanges);
|
|
3442
3462
|
}
|
|
3443
3463
|
encodeAllView(view, sharedOffset, it, bytes = this.sharedBuffer) {
|
|
3444
3464
|
const viewOffset = it.offset;
|
|
3445
3465
|
// console.log(`encodeAllView(), this.$root.allFilteredChanges (${this.$root.allFilteredChanges.size})`);
|
|
3446
3466
|
// this.debugAllFilteredChanges();
|
|
3447
3467
|
// try to encode "filtered" changes
|
|
3448
|
-
this.encode(it, view, bytes, this
|
|
3468
|
+
this.encode(it, view, bytes, this.root.allFilteredChanges);
|
|
3449
3469
|
return Buffer.concat([
|
|
3450
3470
|
bytes.slice(0, sharedOffset),
|
|
3451
3471
|
bytes.slice(viewOffset, it.offset)
|
|
@@ -3464,7 +3484,7 @@ class Encoder {
|
|
|
3464
3484
|
encodeView(view, sharedOffset, it, bytes = this.sharedBuffer) {
|
|
3465
3485
|
const viewOffset = it.offset;
|
|
3466
3486
|
// try to encode "filtered" changes
|
|
3467
|
-
this.encode(it, view, bytes, this
|
|
3487
|
+
this.encode(it, view, bytes, this.root.filteredChanges);
|
|
3468
3488
|
// encode visibility changes (add/remove for this view)
|
|
3469
3489
|
const viewChangesIterator = view.changes.entries();
|
|
3470
3490
|
for (const [changeTree, changes] of viewChangesIterator) {
|
|
@@ -3496,7 +3516,7 @@ class Encoder {
|
|
|
3496
3516
|
bytes.slice(viewOffset, it.offset)
|
|
3497
3517
|
]);
|
|
3498
3518
|
}
|
|
3499
|
-
onEndEncode(changeTrees = this
|
|
3519
|
+
onEndEncode(changeTrees = this.root.changes) {
|
|
3500
3520
|
const changeTreesIterator = changeTrees.entries();
|
|
3501
3521
|
for (const [changeTree, _] of changeTreesIterator) {
|
|
3502
3522
|
changeTree.endEncode();
|
|
@@ -3504,14 +3524,14 @@ class Encoder {
|
|
|
3504
3524
|
}
|
|
3505
3525
|
discardChanges() {
|
|
3506
3526
|
// discard shared changes
|
|
3507
|
-
if (this
|
|
3508
|
-
this.onEndEncode(this
|
|
3509
|
-
this
|
|
3527
|
+
if (this.root.changes.size > 0) {
|
|
3528
|
+
this.onEndEncode(this.root.changes);
|
|
3529
|
+
this.root.changes.clear();
|
|
3510
3530
|
}
|
|
3511
3531
|
// discard filtered changes
|
|
3512
|
-
if (this
|
|
3513
|
-
this.onEndEncode(this
|
|
3514
|
-
this
|
|
3532
|
+
if (this.root.filteredChanges.size > 0) {
|
|
3533
|
+
this.onEndEncode(this.root.filteredChanges);
|
|
3534
|
+
this.root.filteredChanges.clear();
|
|
3515
3535
|
}
|
|
3516
3536
|
}
|
|
3517
3537
|
tryEncodeTypeId(bytes, baseType, targetType, it) {
|