@colyseus/schema 3.0.0-alpha.7 → 3.0.0-alpha.8
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 +30 -24
- package/build/cjs/index.js.map +1 -1
- package/build/esm/index.mjs +30 -24
- package/build/esm/index.mjs.map +1 -1
- package/build/umd/index.js +30 -24
- package/lib/encoder/Encoder.js +7 -3
- package/lib/encoder/Encoder.js.map +1 -1
- package/lib/encoding/encode.d.ts +2 -1
- package/lib/encoding/encode.js +23 -22
- package/lib/encoding/encode.js.map +1 -1
- package/package.json +1 -1
- package/src/encoder/Encoder.ts +9 -3
- package/src/encoding/encode.ts +24 -21
package/build/cjs/index.js
CHANGED
|
@@ -563,26 +563,29 @@ try {
|
|
|
563
563
|
textEncoder = new TextEncoder();
|
|
564
564
|
}
|
|
565
565
|
catch (e) { }
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
566
|
+
const hasBufferByteLength = (typeof Buffer !== 'undefined' && Buffer.byteLength);
|
|
567
|
+
const utf8Length = (hasBufferByteLength)
|
|
568
|
+
? Buffer.byteLength // node
|
|
569
|
+
: function (str, _) {
|
|
570
|
+
var c = 0, length = 0;
|
|
571
|
+
for (var i = 0, l = str.length; i < l; i++) {
|
|
572
|
+
c = str.charCodeAt(i);
|
|
573
|
+
if (c < 0x80) {
|
|
574
|
+
length += 1;
|
|
575
|
+
}
|
|
576
|
+
else if (c < 0x800) {
|
|
577
|
+
length += 2;
|
|
578
|
+
}
|
|
579
|
+
else if (c < 0xd800 || c >= 0xe000) {
|
|
580
|
+
length += 3;
|
|
581
|
+
}
|
|
582
|
+
else {
|
|
583
|
+
i++;
|
|
584
|
+
length += 4;
|
|
585
|
+
}
|
|
582
586
|
}
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
}
|
|
587
|
+
return length;
|
|
588
|
+
};
|
|
586
589
|
function utf8Write(view, str, it) {
|
|
587
590
|
var c = 0;
|
|
588
591
|
for (var i = 0, l = str.length; i < l; i++) {
|
|
@@ -677,8 +680,7 @@ function string$1(bytes, value, it) {
|
|
|
677
680
|
if (!value) {
|
|
678
681
|
value = "";
|
|
679
682
|
}
|
|
680
|
-
|
|
681
|
-
let length = Buffer.byteLength(value, "utf8");
|
|
683
|
+
let length = utf8Length(value, "utf8");
|
|
682
684
|
let size = 0;
|
|
683
685
|
// fixstr
|
|
684
686
|
if (length < 0x20) {
|
|
@@ -3435,13 +3437,17 @@ class Encoder {
|
|
|
3435
3437
|
}
|
|
3436
3438
|
}
|
|
3437
3439
|
if (it.offset > buffer.byteLength) {
|
|
3438
|
-
const newSize = getNextPowerOf2(
|
|
3440
|
+
const newSize = getNextPowerOf2(buffer.byteLength * 2);
|
|
3439
3441
|
console.warn("@colyseus/schema encode buffer overflow. Current buffer size: " + buffer.byteLength + ", encoding offset: " + it.offset + ", new size: " + newSize);
|
|
3440
3442
|
//
|
|
3441
3443
|
// resize buffer and re-encode (TODO: can we avoid re-encoding here?)
|
|
3442
3444
|
//
|
|
3443
|
-
|
|
3444
|
-
|
|
3445
|
+
buffer = Buffer.allocUnsafeSlow(newSize);
|
|
3446
|
+
// assign resized buffer to local sharedBuffer
|
|
3447
|
+
if (buffer === this.sharedBuffer) {
|
|
3448
|
+
this.sharedBuffer = buffer;
|
|
3449
|
+
}
|
|
3450
|
+
return this.encode({ offset: initialOffset }, view, buffer);
|
|
3445
3451
|
}
|
|
3446
3452
|
else {
|
|
3447
3453
|
//
|