@colyseus/schema 3.0.0-alpha.2 → 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 +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 +25 -25
package/build/umd/index.js
CHANGED
|
@@ -1015,9 +1015,10 @@
|
|
|
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
|
+
it.offset += length;
|
|
1019
1020
|
var string = '', chr = 0;
|
|
1020
|
-
for (var i = offset, end = offset + length; i < end; i++) {
|
|
1021
|
+
for (var i = it.offset, end = it.offset + length; i < end; i++) {
|
|
1021
1022
|
var byte = bytes[i];
|
|
1022
1023
|
if ((byte & 0x80) === 0x00) {
|
|
1023
1024
|
string += String.fromCharCode(byte);
|
|
@@ -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,12 @@
|
|
|
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
|
+
it.offset += length;
|
|
28
29
|
var string = '', chr = 0;
|
|
29
|
-
for (var i = offset, end = offset + length; i < end; i++) {
|
|
30
|
+
for (var i = it.offset, end = it.offset + length; i < end; i++) {
|
|
30
31
|
var byte = bytes[i];
|
|
31
32
|
if ((byte & 0x80) === 0x00) {
|
|
32
33
|
string += String.fromCharCode(byte);
|
|
@@ -63,6 +64,7 @@ function utf8Read(bytes, offset, length) {
|
|
|
63
64
|
}
|
|
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,EAAE,CAAC,EAAE,EAAE,CAAC;QACzD,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,IAAI,CAAC,CAAC;YACpC,SAAS;QACX,CAAC;QACD,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC,KAAK,IAAI,EAAE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zB,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,KAAK,EAAE,EAAY;IAC7C,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,KAAK,EAAE,EAAY;IACtD,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\";\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,EAAE,CAAC,MAAM,IAAI,MAAM,CAAC;IAEpB,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,IAAI,CAAC,CAAC;YACpC,SAAS;QACX,CAAC;QACD,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC,KAAK,IAAI,EAAE,CAAC;YAC3B,MAAM,IAAI,MAAM,CAAC,YAAY,CAC3B,CAAC,CAAC,IAAI,GAAG,IAAI,CAAC,IAAI,CAAC,CAAC;gBACpB,CAAC,KAAK,CAAC,EAAE,CAAC,CAAC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jBD,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 it.offset += length;\n\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 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,11 @@ 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) {
|
|
35
|
+
it.offset += length;
|
|
36
|
+
|
|
34
37
|
var string = '', chr = 0;
|
|
35
|
-
for (var i = offset, end = offset + length; i < end; i++) {
|
|
38
|
+
for (var i = it.offset, end = it.offset + length; i < end; i++) {
|
|
36
39
|
var byte = bytes[i];
|
|
37
40
|
if ((byte & 0x80) === 0x00) {
|
|
38
41
|
string += String.fromCharCode(byte);
|
|
@@ -74,45 +77,45 @@ function utf8Read(bytes, offset, length) {
|
|
|
74
77
|
return string;
|
|
75
78
|
}
|
|
76
79
|
|
|
77
|
-
export function int8 (bytes:
|
|
80
|
+
export function int8 (bytes: BufferLike, it: Iterator) {
|
|
78
81
|
return uint8(bytes, it) << 24 >> 24;
|
|
79
82
|
};
|
|
80
83
|
|
|
81
|
-
export function uint8 (bytes:
|
|
84
|
+
export function uint8 (bytes: BufferLike, it: Iterator) {
|
|
82
85
|
return bytes[it.offset++];
|
|
83
86
|
};
|
|
84
87
|
|
|
85
|
-
export function int16 (bytes:
|
|
88
|
+
export function int16 (bytes: BufferLike, it: Iterator) {
|
|
86
89
|
return uint16(bytes, it) << 16 >> 16;
|
|
87
90
|
};
|
|
88
91
|
|
|
89
|
-
export function uint16 (bytes:
|
|
92
|
+
export function uint16 (bytes: BufferLike, it: Iterator) {
|
|
90
93
|
return bytes[it.offset++] | bytes[it.offset++] << 8;
|
|
91
94
|
};
|
|
92
95
|
|
|
93
|
-
export function int32 (bytes:
|
|
96
|
+
export function int32 (bytes: BufferLike, it: Iterator) {
|
|
94
97
|
return bytes[it.offset++] | bytes[it.offset++] << 8 | bytes[it.offset++] << 16 | bytes[it.offset++] << 24;
|
|
95
98
|
};
|
|
96
99
|
|
|
97
|
-
export function uint32 (bytes:
|
|
100
|
+
export function uint32 (bytes: BufferLike, it: Iterator) {
|
|
98
101
|
return int32(bytes, it) >>> 0;
|
|
99
102
|
};
|
|
100
103
|
|
|
101
|
-
export function float32(bytes:
|
|
104
|
+
export function float32(bytes: BufferLike, it: Iterator) {
|
|
102
105
|
return readFloat32(bytes, it);
|
|
103
106
|
}
|
|
104
107
|
|
|
105
|
-
export function float64(bytes:
|
|
108
|
+
export function float64(bytes: BufferLike, it: Iterator) {
|
|
106
109
|
return readFloat64(bytes, it);
|
|
107
110
|
}
|
|
108
111
|
|
|
109
|
-
export function int64(bytes:
|
|
112
|
+
export function int64(bytes: BufferLike, it: Iterator) {
|
|
110
113
|
const low = uint32(bytes, it);
|
|
111
114
|
const high = int32(bytes, it) * Math.pow(2, 32);
|
|
112
115
|
return high + low;
|
|
113
116
|
};
|
|
114
117
|
|
|
115
|
-
export function uint64(bytes:
|
|
118
|
+
export function uint64(bytes: BufferLike, it: Iterator) {
|
|
116
119
|
const low = uint32(bytes, it);
|
|
117
120
|
const high = uint32(bytes, it) * Math.pow(2, 32);
|
|
118
121
|
return high + low;
|
|
@@ -124,22 +127,22 @@ const _int32 = new Int32Array(2);
|
|
|
124
127
|
const _float32 = new Float32Array(_int32.buffer);
|
|
125
128
|
const _float64 = new Float64Array(_int32.buffer);
|
|
126
129
|
|
|
127
|
-
export function readFloat32 (bytes:
|
|
130
|
+
export function readFloat32 (bytes: BufferLike, it: Iterator) {
|
|
128
131
|
_int32[0] = int32(bytes, it);
|
|
129
132
|
return _float32[0];
|
|
130
133
|
};
|
|
131
134
|
|
|
132
|
-
export function readFloat64 (bytes:
|
|
135
|
+
export function readFloat64 (bytes: BufferLike, it: Iterator) {
|
|
133
136
|
_int32[_isLittleEndian ? 0 : 1] = int32(bytes, it);
|
|
134
137
|
_int32[_isLittleEndian ? 1 : 0] = int32(bytes, it);
|
|
135
138
|
return _float64[0];
|
|
136
139
|
};
|
|
137
140
|
|
|
138
|
-
export function boolean (bytes:
|
|
141
|
+
export function boolean (bytes: BufferLike, it: Iterator) {
|
|
139
142
|
return uint8(bytes, it) > 0;
|
|
140
143
|
};
|
|
141
144
|
|
|
142
|
-
export function string (bytes, it: Iterator) {
|
|
145
|
+
export function string (bytes: BufferLike, it: Iterator) {
|
|
143
146
|
const prefix = bytes[it.offset++];
|
|
144
147
|
let length: number;
|
|
145
148
|
|
|
@@ -157,13 +160,10 @@ export function string (bytes, it: Iterator) {
|
|
|
157
160
|
length = uint32(bytes, it);
|
|
158
161
|
}
|
|
159
162
|
|
|
160
|
-
|
|
161
|
-
it.offset += length;
|
|
162
|
-
|
|
163
|
-
return value;
|
|
163
|
+
return utf8Read(bytes, it, length);
|
|
164
164
|
}
|
|
165
165
|
|
|
166
|
-
export function stringCheck(bytes, it: Iterator) {
|
|
166
|
+
export function stringCheck(bytes: BufferLike, it: Iterator) {
|
|
167
167
|
const prefix = bytes[it.offset];
|
|
168
168
|
return (
|
|
169
169
|
// fixstr
|
|
@@ -177,7 +177,7 @@ export function stringCheck(bytes, it: Iterator) {
|
|
|
177
177
|
);
|
|
178
178
|
}
|
|
179
179
|
|
|
180
|
-
export function number (bytes, it: Iterator) {
|
|
180
|
+
export function number (bytes: BufferLike, it: Iterator) {
|
|
181
181
|
const prefix = bytes[it.offset++];
|
|
182
182
|
|
|
183
183
|
if (prefix < 0x80) {
|
|
@@ -230,7 +230,7 @@ export function number (bytes, it: Iterator) {
|
|
|
230
230
|
}
|
|
231
231
|
};
|
|
232
232
|
|
|
233
|
-
export function numberCheck (bytes, it: Iterator) {
|
|
233
|
+
export function numberCheck (bytes: BufferLike, it: Iterator) {
|
|
234
234
|
const prefix = bytes[it.offset];
|
|
235
235
|
// positive fixint - 0x00 - 0x7f
|
|
236
236
|
// float 32 - 0xca
|
|
@@ -249,7 +249,7 @@ export function numberCheck (bytes, it: Iterator) {
|
|
|
249
249
|
);
|
|
250
250
|
}
|
|
251
251
|
|
|
252
|
-
export function arrayCheck (bytes, it: Iterator) {
|
|
252
|
+
export function arrayCheck (bytes: BufferLike, it: Iterator) {
|
|
253
253
|
return bytes[it.offset] < 0xa0;
|
|
254
254
|
|
|
255
255
|
// const prefix = bytes[it.offset] ;
|
|
@@ -268,7 +268,7 @@ export function arrayCheck (bytes, it: Iterator) {
|
|
|
268
268
|
// return prefix;
|
|
269
269
|
}
|
|
270
270
|
|
|
271
|
-
export function switchStructureCheck(bytes, it: Iterator) {
|
|
271
|
+
export function switchStructureCheck(bytes: BufferLike, it: Iterator) {
|
|
272
272
|
return (
|
|
273
273
|
// previous byte should be `SWITCH_TO_STRUCTURE`
|
|
274
274
|
bytes[it.offset - 1] === SWITCH_TO_STRUCTURE &&
|