@colyseus/schema 3.0.0-alpha.2 → 3.0.0-alpha.4
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 +5 -5
- package/build/cjs/index.js.map +1 -1
- package/build/esm/index.mjs +5 -5
- package/build/esm/index.mjs.map +1 -1
- package/build/umd/index.js +5 -5
- package/lib/encoding/decode.d.ts +21 -19
- package/lib/encoding/decode.js +6 -6
- package/lib/encoding/decode.js.map +1 -1
- package/package.json +1 -1
- package/src/encoding/decode.ts +24 -25
package/build/umd/index.js
CHANGED
|
@@ -1015,9 +1015,9 @@
|
|
|
1015
1015
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
1016
1016
|
* SOFTWARE
|
|
1017
1017
|
*/
|
|
1018
|
-
function utf8Read(bytes,
|
|
1018
|
+
function utf8Read(bytes, it, length) {
|
|
1019
1019
|
var string = '', chr = 0;
|
|
1020
|
-
for (var i = offset, end = offset + length; i < end; i++) {
|
|
1020
|
+
for (var i = it.offset, end = it.offset + length; i < end; i++) {
|
|
1021
1021
|
var byte = bytes[i];
|
|
1022
1022
|
if ((byte & 0x80) === 0x00) {
|
|
1023
1023
|
string += String.fromCharCode(byte);
|
|
@@ -1052,6 +1052,7 @@
|
|
|
1052
1052
|
// (do not throw error to avoid server/client from crashing due to hack attemps)
|
|
1053
1053
|
// throw new Error('Invalid byte ' + byte.toString(16));
|
|
1054
1054
|
}
|
|
1055
|
+
it.offset += length;
|
|
1055
1056
|
return string;
|
|
1056
1057
|
}
|
|
1057
1058
|
function int8(bytes, it) {
|
|
@@ -1119,9 +1120,7 @@
|
|
|
1119
1120
|
else if (prefix === 0xdb) {
|
|
1120
1121
|
length = uint32(bytes, it);
|
|
1121
1122
|
}
|
|
1122
|
-
|
|
1123
|
-
it.offset += length;
|
|
1124
|
-
return value;
|
|
1123
|
+
return utf8Read(bytes, it, length);
|
|
1125
1124
|
}
|
|
1126
1125
|
function stringCheck(bytes, it) {
|
|
1127
1126
|
const prefix = bytes[it.offset];
|
|
@@ -1225,6 +1224,7 @@
|
|
|
1225
1224
|
|
|
1226
1225
|
var decode = /*#__PURE__*/Object.freeze({
|
|
1227
1226
|
__proto__: null,
|
|
1227
|
+
utf8Read: utf8Read,
|
|
1228
1228
|
int8: int8,
|
|
1229
1229
|
uint8: uint8,
|
|
1230
1230
|
int16: int16,
|
package/lib/encoding/decode.d.ts
CHANGED
|
@@ -20,6 +20,7 @@
|
|
|
20
20
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
21
|
* SOFTWARE
|
|
22
22
|
*/
|
|
23
|
+
import type { BufferLike } from "./encode";
|
|
23
24
|
/**
|
|
24
25
|
* msgpack implementation highly based on notepack.io
|
|
25
26
|
* https://github.com/darrachequesne/notepack
|
|
@@ -27,22 +28,23 @@
|
|
|
27
28
|
export interface Iterator {
|
|
28
29
|
offset: number;
|
|
29
30
|
}
|
|
30
|
-
export declare function
|
|
31
|
-
export declare function
|
|
32
|
-
export declare function
|
|
33
|
-
export declare function
|
|
34
|
-
export declare function
|
|
35
|
-
export declare function
|
|
36
|
-
export declare function
|
|
37
|
-
export declare function
|
|
38
|
-
export declare function
|
|
39
|
-
export declare function
|
|
40
|
-
export declare function
|
|
41
|
-
export declare function
|
|
42
|
-
export declare function
|
|
43
|
-
export declare function
|
|
44
|
-
export declare function
|
|
45
|
-
export declare function
|
|
46
|
-
export declare function
|
|
47
|
-
export declare function
|
|
48
|
-
export declare function
|
|
31
|
+
export declare function utf8Read(bytes: BufferLike, it: Iterator, length: number): string;
|
|
32
|
+
export declare function int8(bytes: BufferLike, it: Iterator): number;
|
|
33
|
+
export declare function uint8(bytes: BufferLike, it: Iterator): any;
|
|
34
|
+
export declare function int16(bytes: BufferLike, it: Iterator): number;
|
|
35
|
+
export declare function uint16(bytes: BufferLike, it: Iterator): number;
|
|
36
|
+
export declare function int32(bytes: BufferLike, it: Iterator): number;
|
|
37
|
+
export declare function uint32(bytes: BufferLike, it: Iterator): number;
|
|
38
|
+
export declare function float32(bytes: BufferLike, it: Iterator): number;
|
|
39
|
+
export declare function float64(bytes: BufferLike, it: Iterator): number;
|
|
40
|
+
export declare function int64(bytes: BufferLike, it: Iterator): number;
|
|
41
|
+
export declare function uint64(bytes: BufferLike, it: Iterator): number;
|
|
42
|
+
export declare function readFloat32(bytes: BufferLike, it: Iterator): number;
|
|
43
|
+
export declare function readFloat64(bytes: BufferLike, it: Iterator): number;
|
|
44
|
+
export declare function boolean(bytes: BufferLike, it: Iterator): boolean;
|
|
45
|
+
export declare function string(bytes: BufferLike, it: Iterator): string;
|
|
46
|
+
export declare function stringCheck(bytes: BufferLike, it: Iterator): boolean;
|
|
47
|
+
export declare function number(bytes: BufferLike, it: Iterator): any;
|
|
48
|
+
export declare function numberCheck(bytes: BufferLike, it: Iterator): boolean;
|
|
49
|
+
export declare function arrayCheck(bytes: BufferLike, it: Iterator): boolean;
|
|
50
|
+
export declare function switchStructureCheck(bytes: BufferLike, it: Iterator): boolean;
|
package/lib/encoding/decode.js
CHANGED
|
@@ -22,11 +22,11 @@
|
|
|
22
22
|
* SOFTWARE
|
|
23
23
|
*/
|
|
24
24
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
25
|
-
exports.switchStructureCheck = exports.arrayCheck = exports.numberCheck = exports.number = exports.stringCheck = exports.string = exports.boolean = exports.readFloat64 = exports.readFloat32 = exports.uint64 = exports.int64 = exports.float64 = exports.float32 = exports.uint32 = exports.int32 = exports.uint16 = exports.int16 = exports.uint8 = exports.int8 = void 0;
|
|
25
|
+
exports.switchStructureCheck = exports.arrayCheck = exports.numberCheck = exports.number = exports.stringCheck = exports.string = exports.boolean = exports.readFloat64 = exports.readFloat32 = exports.uint64 = exports.int64 = exports.float64 = exports.float32 = exports.uint32 = exports.int32 = exports.uint16 = exports.int16 = exports.uint8 = exports.int8 = exports.utf8Read = void 0;
|
|
26
26
|
const spec_1 = require("./spec");
|
|
27
|
-
function utf8Read(bytes,
|
|
27
|
+
function utf8Read(bytes, it, length) {
|
|
28
28
|
var string = '', chr = 0;
|
|
29
|
-
for (var i = offset, end = offset + length; i < end; i++) {
|
|
29
|
+
for (var i = it.offset, end = it.offset + length; i < end; i++) {
|
|
30
30
|
var byte = bytes[i];
|
|
31
31
|
if ((byte & 0x80) === 0x00) {
|
|
32
32
|
string += String.fromCharCode(byte);
|
|
@@ -61,8 +61,10 @@ function utf8Read(bytes, offset, length) {
|
|
|
61
61
|
// (do not throw error to avoid server/client from crashing due to hack attemps)
|
|
62
62
|
// throw new Error('Invalid byte ' + byte.toString(16));
|
|
63
63
|
}
|
|
64
|
+
it.offset += length;
|
|
64
65
|
return string;
|
|
65
66
|
}
|
|
67
|
+
exports.utf8Read = utf8Read;
|
|
66
68
|
function int8(bytes, it) {
|
|
67
69
|
return uint8(bytes, it) << 24 >> 24;
|
|
68
70
|
}
|
|
@@ -154,9 +156,7 @@ function string(bytes, it) {
|
|
|
154
156
|
else if (prefix === 0xdb) {
|
|
155
157
|
length = uint32(bytes, it);
|
|
156
158
|
}
|
|
157
|
-
|
|
158
|
-
it.offset += length;
|
|
159
|
-
return value;
|
|
159
|
+
return utf8Read(bytes, it, length);
|
|
160
160
|
}
|
|
161
161
|
exports.string = string;
|
|
162
162
|
function stringCheck(bytes, it) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"decode.js","sourceRoot":"","sources":["../../src/encoding/decode.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;;;;;GAqBG;;;AAEH,iCAA6C;AAS7C,SAAS,QAAQ,CAAC,KAAK,EAAE,MAAM,EAAE,MAAM;IACrC,IAAI,MAAM,GAAG,EAAE,EAAE,GAAG,GAAG,CAAC,CAAC;IACzB,KAAK,IAAI,CAAC,GAAG,MAAM,EAAE,GAAG,GAAG,MAAM,GAAG,MAAM,EAAE,CAAC,GAAG,GAAG,EAA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Ltd.\n *\n * Permission is hereby granted, free of charge, to any person obtaining a copy\n * of this software and associated documentation files (the \"Software\"), to deal\n * in the Software without restriction, including without limitation the rights\n * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\n * copies of the Software, and to permit persons to whom the Software is\n * furnished to do so, subject to the following conditions:\n *\n * The above copyright notice and this permission notice shall be included in all\n * copies or substantial portions of the Software.\n *\n * THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\n * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\n * SOFTWARE\n */\n\nimport { SWITCH_TO_STRUCTURE } from \"./spec\";\n\n/**\n * msgpack implementation highly based on notepack.io\n * https://github.com/darrachequesne/notepack\n */\n\nexport interface Iterator { offset: number; }\n\nfunction utf8Read(bytes, offset, length) {\n var string = '', chr = 0;\n for (var i = offset, end = offset + length; i < end; i++) {\n var byte = bytes[i];\n if ((byte & 0x80) === 0x00) {\n string += String.fromCharCode(byte);\n continue;\n }\n if ((byte & 0xe0) === 0xc0) {\n string += String.fromCharCode(\n ((byte & 0x1f) << 6) |\n (bytes[++i] & 0x3f)\n );\n continue;\n }\n if ((byte & 0xf0) === 0xe0) {\n string += String.fromCharCode(\n ((byte & 0x0f) << 12) |\n ((bytes[++i] & 0x3f) << 6) |\n ((bytes[++i] & 0x3f) << 0)\n );\n continue;\n }\n if ((byte & 0xf8) === 0xf0) {\n chr = ((byte & 0x07) << 18) |\n ((bytes[++i] & 0x3f) << 12) |\n ((bytes[++i] & 0x3f) << 6) |\n ((bytes[++i] & 0x3f) << 0);\n if (chr >= 0x010000) { // surrogate pair\n chr -= 0x010000;\n string += String.fromCharCode((chr >>> 10) + 0xD800, (chr & 0x3FF) + 0xDC00);\n } else {\n string += String.fromCharCode(chr);\n }\n continue;\n }\n\n console.error('Invalid byte ' + byte.toString(16));\n // (do not throw error to avoid server/client from crashing due to hack attemps)\n // throw new Error('Invalid byte ' + byte.toString(16));\n }\n return string;\n}\n\nexport function int8 (bytes: number[], it: Iterator) {\n return uint8(bytes, it) << 24 >> 24;\n};\n\nexport function uint8 (bytes: number[], it: Iterator) {\n return bytes[it.offset++];\n};\n\nexport function int16 (bytes: number[], it: Iterator) {\n return uint16(bytes, it) << 16 >> 16;\n};\n\nexport function uint16 (bytes: number[], it: Iterator) {\n return bytes[it.offset++] | bytes[it.offset++] << 8;\n};\n\nexport function int32 (bytes: number[], it: Iterator) {\n return bytes[it.offset++] | bytes[it.offset++] << 8 | bytes[it.offset++] << 16 | bytes[it.offset++] << 24;\n};\n\nexport function uint32 (bytes: number[], it: Iterator) {\n return int32(bytes, it) >>> 0;\n};\n\nexport function float32(bytes: number[], it: Iterator) {\n return readFloat32(bytes, it);\n}\n\nexport function float64(bytes: number[], it: Iterator) {\n return readFloat64(bytes, it);\n}\n\nexport function int64(bytes: number[], it: Iterator) {\n const low = uint32(bytes, it);\n const high = int32(bytes, it) * Math.pow(2, 32);\n return high + low;\n};\n\nexport function uint64(bytes: number[], it: Iterator) {\n const low = uint32(bytes, it);\n const high = uint32(bytes, it) * Math.pow(2, 32);\n return high + low;\n};\n\n// force little endian to facilitate decoding on multiple implementations\nconst _isLittleEndian = true; // new Uint16Array(new Uint8Array([1, 0]).buffer)[0] === 1;\nconst _int32 = new Int32Array(2);\nconst _float32 = new Float32Array(_int32.buffer);\nconst _float64 = new Float64Array(_int32.buffer);\n\nexport function readFloat32 (bytes: number[], it: Iterator) {\n _int32[0] = int32(bytes, it);\n return _float32[0];\n};\n\nexport function readFloat64 (bytes: number[], it: Iterator) {\n _int32[_isLittleEndian ? 0 : 1] = int32(bytes, it);\n _int32[_isLittleEndian ? 1 : 0] = int32(bytes, it);\n return _float64[0];\n};\n\nexport function boolean (bytes: number[], it: Iterator) {\n return uint8(bytes, it) > 0;\n};\n\nexport function string (bytes, it: Iterator) {\n const prefix = bytes[it.offset++];\n let length: number;\n\n if (prefix < 0xc0) {\n // fixstr\n length = prefix & 0x1f;\n\n } else if (prefix === 0xd9) {\n length = uint8(bytes, it);\n\n } else if (prefix === 0xda) {\n length = uint16(bytes, it);\n\n } else if (prefix === 0xdb) {\n length = uint32(bytes, it);\n }\n\n const value = utf8Read(bytes, it.offset, length);\n it.offset += length;\n\n return value;\n}\n\nexport function stringCheck(bytes, it: Iterator) {\n const prefix = bytes[it.offset];\n return (\n // fixstr\n (prefix < 0xc0 && prefix > 0xa0) ||\n // str 8\n prefix === 0xd9 ||\n // str 16\n prefix === 0xda ||\n // str 32\n prefix === 0xdb\n );\n}\n\nexport function number (bytes, it: Iterator) {\n const prefix = bytes[it.offset++];\n\n if (prefix < 0x80) {\n // positive fixint\n return prefix;\n\n } else if (prefix === 0xca) {\n // float 32\n return readFloat32(bytes, it);\n\n } else if (prefix === 0xcb) {\n // float 64\n return readFloat64(bytes, it);\n\n } else if (prefix === 0xcc) {\n // uint 8\n return uint8(bytes, it);\n\n } else if (prefix === 0xcd) {\n // uint 16\n return uint16(bytes, it);\n\n } else if (prefix === 0xce) {\n // uint 32\n return uint32(bytes, it);\n\n } else if (prefix === 0xcf) {\n // uint 64\n return uint64(bytes, it);\n\n } else if (prefix === 0xd0) {\n // int 8\n return int8(bytes, it);\n\n } else if (prefix === 0xd1) {\n // int 16\n return int16(bytes, it);\n\n } else if (prefix === 0xd2) {\n // int 32\n return int32(bytes, it);\n\n } else if (prefix === 0xd3) {\n // int 64\n return int64(bytes, it);\n\n } else if (prefix > 0xdf) {\n // negative fixint\n return (0xff - prefix + 1) * -1\n }\n};\n\nexport function numberCheck (bytes, it: Iterator) {\n const prefix = bytes[it.offset];\n // positive fixint - 0x00 - 0x7f\n // float 32 - 0xca\n // float 64 - 0xcb\n // uint 8 - 0xcc\n // uint 16 - 0xcd\n // uint 32 - 0xce\n // uint 64 - 0xcf\n // int 8 - 0xd0\n // int 16 - 0xd1\n // int 32 - 0xd2\n // int 64 - 0xd3\n return (\n prefix < 0x80 ||\n (prefix >= 0xca && prefix <= 0xd3)\n );\n}\n\nexport function arrayCheck (bytes, it: Iterator) {\n return bytes[it.offset] < 0xa0;\n\n // const prefix = bytes[it.offset] ;\n\n // if (prefix < 0xa0) {\n // return prefix;\n\n // // array\n // } else if (prefix === 0xdc) {\n // it.offset += 2;\n\n // } else if (0xdd) {\n // it.offset += 4;\n // }\n\n // return prefix;\n}\n\nexport function switchStructureCheck(bytes, it: Iterator) {\n return (\n // previous byte should be `SWITCH_TO_STRUCTURE`\n bytes[it.offset - 1] === SWITCH_TO_STRUCTURE &&\n // next byte should be a number\n (bytes[it.offset] < 0x80 || (bytes[it.offset] >= 0xca && bytes[it.offset] <= 0xd3))\n );\n}"]}
|
|
1
|
+
{"version":3,"file":"decode.js","sourceRoot":"","sources":["../../src/encoding/decode.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;;;;;GAqBG;;;AAEH,iCAA6C;AAU7C,SAAgB,QAAQ,CAAC,KAAiB,EAAE,EAAY,EAAE,MAAc;IACtE,IAAI,MAAM,GAAG,EAAE,EAAE,GAAG,GAAG,CAAC,CAAC;IACzB,KAAK,IAAI,CAAC,GAAG,EAAE,CAAC,MAAM,EAAE,GAAG,GAAG,EAAE,CAAC,MAAM,GAAG,MAAM,EAAE,CAAC,GAAG,GAAG,EAAE,CAAC,EAAE,EAAE,CAAC;QAC/D,IAAI,IAAI,GAAG,KAAK,CAAC,CAAC,CAAC,CAAC;QACpB,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC,KAAK,IAAI,EAAE,CAAC;YAC3B,MAAM,IAAI,MAAM,CAAC,YAAY,CAAC,I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C,CAAC;IAChC,gCAAgC;IAChC,yBAAyB;IACzB,yBAAyB;IACzB,yBAAyB;IACzB,yBAAyB;IACzB,yBAAyB;IACzB,yBAAyB;IACzB,yBAAyB;IACzB,yBAAyB;IACzB,yBAAyB;IACzB,yBAAyB;IACzB,OAAO,CACL,MAAM,GAAG,IAAI;QACb,CAAC,MAAM,IAAI,IAAI,IAAI,MAAM,IAAI,IAAI,CAAC,CACnC,CAAC;AACJ,CAAC;AAjBD,kCAiBC;AAED,SAAgB,UAAU,CAAE,KAAiB,EAAE,EAAY;IACzD,OAAO,KAAK,CAAC,EAAE,CAAC,MAAM,CAAC,GAAG,IAAI,CAAC;IAE/B,oCAAoC;IAEpC,uBAAuB;IACvB,mBAAmB;IAEnB,WAAW;IACX,gCAAgC;IAChC,oBAAoB;IAEpB,qBAAqB;IACrB,oBAAoB;IACpB,IAAI;IAEJ,iBAAiB;AACnB,CAAC;AAjBD,gCAiBC;AAED,SAAgB,oBAAoB,CAAC,KAAiB,EAAE,EAAY;IAClE,OAAO;IACH,gDAAgD;IAChD,KAAK,CAAC,EAAE,CAAC,MAAM,GAAG,CAAC,CAAC,KAAK,0BAAmB;QAC5C,+BAA+B;QAC/B,CAAC,KAAK,CAAC,EAAE,CAAC,MAAM,CAAC,GAAG,IAAI,IAAI,CAAC,KAAK,CAAC,EAAE,CAAC,MAAM,CAAC,IAAI,IAAI,IAAI,KAAK,CAAC,EAAE,CAAC,MAAM,CAAC,IAAI,IAAI,CAAC,CAAC,CACtF,CAAC;AACJ,CAAC;AAPD,oDAOC","sourcesContent":["/**\n * Copyright (c) 2018 Endel Dreyer\n * Copyright (c) 2014 Ion Drive Software Ltd.\n *\n * Permission is hereby granted, free of charge, to any person obtaining a copy\n * of this software and associated documentation files (the \"Software\"), to deal\n * in the Software without restriction, including without limitation the rights\n * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\n * copies of the Software, and to permit persons to whom the Software is\n * furnished to do so, subject to the following conditions:\n *\n * The above copyright notice and this permission notice shall be included in all\n * copies or substantial portions of the Software.\n *\n * THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\n * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\n * SOFTWARE\n */\n\nimport { SWITCH_TO_STRUCTURE } from \"./spec\";\nimport type { BufferLike } from \"./encode\";\n\n/**\n * msgpack implementation highly based on notepack.io\n * https://github.com/darrachequesne/notepack\n */\n\nexport interface Iterator { offset: number; }\n\nexport function utf8Read(bytes: BufferLike, it: Iterator, length: number) {\n var string = '', chr = 0;\n for (var i = it.offset, end = it.offset + length; i < end; i++) {\n var byte = bytes[i];\n if ((byte & 0x80) === 0x00) {\n string += String.fromCharCode(byte);\n continue;\n }\n if ((byte & 0xe0) === 0xc0) {\n string += String.fromCharCode(\n ((byte & 0x1f) << 6) |\n (bytes[++i] & 0x3f)\n );\n continue;\n }\n if ((byte & 0xf0) === 0xe0) {\n string += String.fromCharCode(\n ((byte & 0x0f) << 12) |\n ((bytes[++i] & 0x3f) << 6) |\n ((bytes[++i] & 0x3f) << 0)\n );\n continue;\n }\n if ((byte & 0xf8) === 0xf0) {\n chr = ((byte & 0x07) << 18) |\n ((bytes[++i] & 0x3f) << 12) |\n ((bytes[++i] & 0x3f) << 6) |\n ((bytes[++i] & 0x3f) << 0);\n if (chr >= 0x010000) { // surrogate pair\n chr -= 0x010000;\n string += String.fromCharCode((chr >>> 10) + 0xD800, (chr & 0x3FF) + 0xDC00);\n } else {\n string += String.fromCharCode(chr);\n }\n continue;\n }\n\n console.error('Invalid byte ' + byte.toString(16));\n // (do not throw error to avoid server/client from crashing due to hack attemps)\n // throw new Error('Invalid byte ' + byte.toString(16));\n }\n it.offset += length;\n return string;\n}\n\nexport function int8 (bytes: BufferLike, it: Iterator) {\n return uint8(bytes, it) << 24 >> 24;\n};\n\nexport function uint8 (bytes: BufferLike, it: Iterator) {\n return bytes[it.offset++];\n};\n\nexport function int16 (bytes: BufferLike, it: Iterator) {\n return uint16(bytes, it) << 16 >> 16;\n};\n\nexport function uint16 (bytes: BufferLike, it: Iterator) {\n return bytes[it.offset++] | bytes[it.offset++] << 8;\n};\n\nexport function int32 (bytes: BufferLike, it: Iterator) {\n return bytes[it.offset++] | bytes[it.offset++] << 8 | bytes[it.offset++] << 16 | bytes[it.offset++] << 24;\n};\n\nexport function uint32 (bytes: BufferLike, it: Iterator) {\n return int32(bytes, it) >>> 0;\n};\n\nexport function float32(bytes: BufferLike, it: Iterator) {\n return readFloat32(bytes, it);\n}\n\nexport function float64(bytes: BufferLike, it: Iterator) {\n return readFloat64(bytes, it);\n}\n\nexport function int64(bytes: BufferLike, it: Iterator) {\n const low = uint32(bytes, it);\n const high = int32(bytes, it) * Math.pow(2, 32);\n return high + low;\n};\n\nexport function uint64(bytes: BufferLike, it: Iterator) {\n const low = uint32(bytes, it);\n const high = uint32(bytes, it) * Math.pow(2, 32);\n return high + low;\n};\n\n// force little endian to facilitate decoding on multiple implementations\nconst _isLittleEndian = true; // new Uint16Array(new Uint8Array([1, 0]).buffer)[0] === 1;\nconst _int32 = new Int32Array(2);\nconst _float32 = new Float32Array(_int32.buffer);\nconst _float64 = new Float64Array(_int32.buffer);\n\nexport function readFloat32 (bytes: BufferLike, it: Iterator) {\n _int32[0] = int32(bytes, it);\n return _float32[0];\n};\n\nexport function readFloat64 (bytes: BufferLike, it: Iterator) {\n _int32[_isLittleEndian ? 0 : 1] = int32(bytes, it);\n _int32[_isLittleEndian ? 1 : 0] = int32(bytes, it);\n return _float64[0];\n};\n\nexport function boolean (bytes: BufferLike, it: Iterator) {\n return uint8(bytes, it) > 0;\n};\n\nexport function string (bytes: BufferLike, it: Iterator) {\n const prefix = bytes[it.offset++];\n let length: number;\n\n if (prefix < 0xc0) {\n // fixstr\n length = prefix & 0x1f;\n\n } else if (prefix === 0xd9) {\n length = uint8(bytes, it);\n\n } else if (prefix === 0xda) {\n length = uint16(bytes, it);\n\n } else if (prefix === 0xdb) {\n length = uint32(bytes, it);\n }\n\n return utf8Read(bytes, it, length);\n}\n\nexport function stringCheck(bytes: BufferLike, it: Iterator) {\n const prefix = bytes[it.offset];\n return (\n // fixstr\n (prefix < 0xc0 && prefix > 0xa0) ||\n // str 8\n prefix === 0xd9 ||\n // str 16\n prefix === 0xda ||\n // str 32\n prefix === 0xdb\n );\n}\n\nexport function number (bytes: BufferLike, it: Iterator) {\n const prefix = bytes[it.offset++];\n\n if (prefix < 0x80) {\n // positive fixint\n return prefix;\n\n } else if (prefix === 0xca) {\n // float 32\n return readFloat32(bytes, it);\n\n } else if (prefix === 0xcb) {\n // float 64\n return readFloat64(bytes, it);\n\n } else if (prefix === 0xcc) {\n // uint 8\n return uint8(bytes, it);\n\n } else if (prefix === 0xcd) {\n // uint 16\n return uint16(bytes, it);\n\n } else if (prefix === 0xce) {\n // uint 32\n return uint32(bytes, it);\n\n } else if (prefix === 0xcf) {\n // uint 64\n return uint64(bytes, it);\n\n } else if (prefix === 0xd0) {\n // int 8\n return int8(bytes, it);\n\n } else if (prefix === 0xd1) {\n // int 16\n return int16(bytes, it);\n\n } else if (prefix === 0xd2) {\n // int 32\n return int32(bytes, it);\n\n } else if (prefix === 0xd3) {\n // int 64\n return int64(bytes, it);\n\n } else if (prefix > 0xdf) {\n // negative fixint\n return (0xff - prefix + 1) * -1\n }\n};\n\nexport function numberCheck (bytes: BufferLike, it: Iterator) {\n const prefix = bytes[it.offset];\n // positive fixint - 0x00 - 0x7f\n // float 32 - 0xca\n // float 64 - 0xcb\n // uint 8 - 0xcc\n // uint 16 - 0xcd\n // uint 32 - 0xce\n // uint 64 - 0xcf\n // int 8 - 0xd0\n // int 16 - 0xd1\n // int 32 - 0xd2\n // int 64 - 0xd3\n return (\n prefix < 0x80 ||\n (prefix >= 0xca && prefix <= 0xd3)\n );\n}\n\nexport function arrayCheck (bytes: BufferLike, it: Iterator) {\n return bytes[it.offset] < 0xa0;\n\n // const prefix = bytes[it.offset] ;\n\n // if (prefix < 0xa0) {\n // return prefix;\n\n // // array\n // } else if (prefix === 0xdc) {\n // it.offset += 2;\n\n // } else if (0xdd) {\n // it.offset += 4;\n // }\n\n // return prefix;\n}\n\nexport function switchStructureCheck(bytes: BufferLike, it: Iterator) {\n return (\n // previous byte should be `SWITCH_TO_STRUCTURE`\n bytes[it.offset - 1] === SWITCH_TO_STRUCTURE &&\n // next byte should be a number\n (bytes[it.offset] < 0x80 || (bytes[it.offset] >= 0xca && bytes[it.offset] <= 0xd3))\n );\n}"]}
|
package/package.json
CHANGED
package/src/encoding/decode.ts
CHANGED
|
@@ -22,6 +22,7 @@
|
|
|
22
22
|
*/
|
|
23
23
|
|
|
24
24
|
import { SWITCH_TO_STRUCTURE } from "./spec";
|
|
25
|
+
import type { BufferLike } from "./encode";
|
|
25
26
|
|
|
26
27
|
/**
|
|
27
28
|
* msgpack implementation highly based on notepack.io
|
|
@@ -30,9 +31,9 @@ import { SWITCH_TO_STRUCTURE } from "./spec";
|
|
|
30
31
|
|
|
31
32
|
export interface Iterator { offset: number; }
|
|
32
33
|
|
|
33
|
-
function utf8Read(bytes,
|
|
34
|
+
export function utf8Read(bytes: BufferLike, it: Iterator, length: number) {
|
|
34
35
|
var string = '', chr = 0;
|
|
35
|
-
for (var i = offset, end = offset + length; i < end; i++) {
|
|
36
|
+
for (var i = it.offset, end = it.offset + length; i < end; i++) {
|
|
36
37
|
var byte = bytes[i];
|
|
37
38
|
if ((byte & 0x80) === 0x00) {
|
|
38
39
|
string += String.fromCharCode(byte);
|
|
@@ -71,48 +72,49 @@ function utf8Read(bytes, offset, length) {
|
|
|
71
72
|
// (do not throw error to avoid server/client from crashing due to hack attemps)
|
|
72
73
|
// throw new Error('Invalid byte ' + byte.toString(16));
|
|
73
74
|
}
|
|
75
|
+
it.offset += length;
|
|
74
76
|
return string;
|
|
75
77
|
}
|
|
76
78
|
|
|
77
|
-
export function int8 (bytes:
|
|
79
|
+
export function int8 (bytes: BufferLike, it: Iterator) {
|
|
78
80
|
return uint8(bytes, it) << 24 >> 24;
|
|
79
81
|
};
|
|
80
82
|
|
|
81
|
-
export function uint8 (bytes:
|
|
83
|
+
export function uint8 (bytes: BufferLike, it: Iterator) {
|
|
82
84
|
return bytes[it.offset++];
|
|
83
85
|
};
|
|
84
86
|
|
|
85
|
-
export function int16 (bytes:
|
|
87
|
+
export function int16 (bytes: BufferLike, it: Iterator) {
|
|
86
88
|
return uint16(bytes, it) << 16 >> 16;
|
|
87
89
|
};
|
|
88
90
|
|
|
89
|
-
export function uint16 (bytes:
|
|
91
|
+
export function uint16 (bytes: BufferLike, it: Iterator) {
|
|
90
92
|
return bytes[it.offset++] | bytes[it.offset++] << 8;
|
|
91
93
|
};
|
|
92
94
|
|
|
93
|
-
export function int32 (bytes:
|
|
95
|
+
export function int32 (bytes: BufferLike, it: Iterator) {
|
|
94
96
|
return bytes[it.offset++] | bytes[it.offset++] << 8 | bytes[it.offset++] << 16 | bytes[it.offset++] << 24;
|
|
95
97
|
};
|
|
96
98
|
|
|
97
|
-
export function uint32 (bytes:
|
|
99
|
+
export function uint32 (bytes: BufferLike, it: Iterator) {
|
|
98
100
|
return int32(bytes, it) >>> 0;
|
|
99
101
|
};
|
|
100
102
|
|
|
101
|
-
export function float32(bytes:
|
|
103
|
+
export function float32(bytes: BufferLike, it: Iterator) {
|
|
102
104
|
return readFloat32(bytes, it);
|
|
103
105
|
}
|
|
104
106
|
|
|
105
|
-
export function float64(bytes:
|
|
107
|
+
export function float64(bytes: BufferLike, it: Iterator) {
|
|
106
108
|
return readFloat64(bytes, it);
|
|
107
109
|
}
|
|
108
110
|
|
|
109
|
-
export function int64(bytes:
|
|
111
|
+
export function int64(bytes: BufferLike, it: Iterator) {
|
|
110
112
|
const low = uint32(bytes, it);
|
|
111
113
|
const high = int32(bytes, it) * Math.pow(2, 32);
|
|
112
114
|
return high + low;
|
|
113
115
|
};
|
|
114
116
|
|
|
115
|
-
export function uint64(bytes:
|
|
117
|
+
export function uint64(bytes: BufferLike, it: Iterator) {
|
|
116
118
|
const low = uint32(bytes, it);
|
|
117
119
|
const high = uint32(bytes, it) * Math.pow(2, 32);
|
|
118
120
|
return high + low;
|
|
@@ -124,22 +126,22 @@ const _int32 = new Int32Array(2);
|
|
|
124
126
|
const _float32 = new Float32Array(_int32.buffer);
|
|
125
127
|
const _float64 = new Float64Array(_int32.buffer);
|
|
126
128
|
|
|
127
|
-
export function readFloat32 (bytes:
|
|
129
|
+
export function readFloat32 (bytes: BufferLike, it: Iterator) {
|
|
128
130
|
_int32[0] = int32(bytes, it);
|
|
129
131
|
return _float32[0];
|
|
130
132
|
};
|
|
131
133
|
|
|
132
|
-
export function readFloat64 (bytes:
|
|
134
|
+
export function readFloat64 (bytes: BufferLike, it: Iterator) {
|
|
133
135
|
_int32[_isLittleEndian ? 0 : 1] = int32(bytes, it);
|
|
134
136
|
_int32[_isLittleEndian ? 1 : 0] = int32(bytes, it);
|
|
135
137
|
return _float64[0];
|
|
136
138
|
};
|
|
137
139
|
|
|
138
|
-
export function boolean (bytes:
|
|
140
|
+
export function boolean (bytes: BufferLike, it: Iterator) {
|
|
139
141
|
return uint8(bytes, it) > 0;
|
|
140
142
|
};
|
|
141
143
|
|
|
142
|
-
export function string (bytes, it: Iterator) {
|
|
144
|
+
export function string (bytes: BufferLike, it: Iterator) {
|
|
143
145
|
const prefix = bytes[it.offset++];
|
|
144
146
|
let length: number;
|
|
145
147
|
|
|
@@ -157,13 +159,10 @@ export function string (bytes, it: Iterator) {
|
|
|
157
159
|
length = uint32(bytes, it);
|
|
158
160
|
}
|
|
159
161
|
|
|
160
|
-
|
|
161
|
-
it.offset += length;
|
|
162
|
-
|
|
163
|
-
return value;
|
|
162
|
+
return utf8Read(bytes, it, length);
|
|
164
163
|
}
|
|
165
164
|
|
|
166
|
-
export function stringCheck(bytes, it: Iterator) {
|
|
165
|
+
export function stringCheck(bytes: BufferLike, it: Iterator) {
|
|
167
166
|
const prefix = bytes[it.offset];
|
|
168
167
|
return (
|
|
169
168
|
// fixstr
|
|
@@ -177,7 +176,7 @@ export function stringCheck(bytes, it: Iterator) {
|
|
|
177
176
|
);
|
|
178
177
|
}
|
|
179
178
|
|
|
180
|
-
export function number (bytes, it: Iterator) {
|
|
179
|
+
export function number (bytes: BufferLike, it: Iterator) {
|
|
181
180
|
const prefix = bytes[it.offset++];
|
|
182
181
|
|
|
183
182
|
if (prefix < 0x80) {
|
|
@@ -230,7 +229,7 @@ export function number (bytes, it: Iterator) {
|
|
|
230
229
|
}
|
|
231
230
|
};
|
|
232
231
|
|
|
233
|
-
export function numberCheck (bytes, it: Iterator) {
|
|
232
|
+
export function numberCheck (bytes: BufferLike, it: Iterator) {
|
|
234
233
|
const prefix = bytes[it.offset];
|
|
235
234
|
// positive fixint - 0x00 - 0x7f
|
|
236
235
|
// float 32 - 0xca
|
|
@@ -249,7 +248,7 @@ export function numberCheck (bytes, it: Iterator) {
|
|
|
249
248
|
);
|
|
250
249
|
}
|
|
251
250
|
|
|
252
|
-
export function arrayCheck (bytes, it: Iterator) {
|
|
251
|
+
export function arrayCheck (bytes: BufferLike, it: Iterator) {
|
|
253
252
|
return bytes[it.offset] < 0xa0;
|
|
254
253
|
|
|
255
254
|
// const prefix = bytes[it.offset] ;
|
|
@@ -268,7 +267,7 @@ export function arrayCheck (bytes, it: Iterator) {
|
|
|
268
267
|
// return prefix;
|
|
269
268
|
}
|
|
270
269
|
|
|
271
|
-
export function switchStructureCheck(bytes, it: Iterator) {
|
|
270
|
+
export function switchStructureCheck(bytes: BufferLike, it: Iterator) {
|
|
272
271
|
return (
|
|
273
272
|
// previous byte should be `SWITCH_TO_STRUCTURE`
|
|
274
273
|
bytes[it.offset - 1] === SWITCH_TO_STRUCTURE &&
|