@colyseus/schema 3.0.0-alpha.4 → 3.0.0-alpha.41

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.
Files changed (146) hide show
  1. package/README.md +148 -62
  2. package/bin/schema-debug +94 -0
  3. package/build/cjs/index.js +2201 -1507
  4. package/build/cjs/index.js.map +1 -1
  5. package/build/esm/index.mjs +2198 -1506
  6. package/build/esm/index.mjs.map +1 -1
  7. package/build/umd/index.js +2208 -1514
  8. package/lib/Metadata.d.ts +21 -9
  9. package/lib/Metadata.js +169 -32
  10. package/lib/Metadata.js.map +1 -1
  11. package/lib/Reflection.d.ts +19 -4
  12. package/lib/Reflection.js +66 -32
  13. package/lib/Reflection.js.map +1 -1
  14. package/lib/Schema.d.ts +4 -4
  15. package/lib/Schema.js +44 -50
  16. package/lib/Schema.js.map +1 -1
  17. package/lib/annotations.d.ts +31 -34
  18. package/lib/annotations.js +110 -160
  19. package/lib/annotations.js.map +1 -1
  20. package/lib/bench_encode.d.ts +1 -0
  21. package/lib/bench_encode.js +130 -0
  22. package/lib/bench_encode.js.map +1 -0
  23. package/lib/codegen/api.js +1 -2
  24. package/lib/codegen/api.js.map +1 -1
  25. package/lib/codegen/languages/cpp.js +1 -2
  26. package/lib/codegen/languages/cpp.js.map +1 -1
  27. package/lib/codegen/languages/csharp.js +2 -46
  28. package/lib/codegen/languages/csharp.js.map +1 -1
  29. package/lib/codegen/languages/haxe.js +1 -2
  30. package/lib/codegen/languages/haxe.js.map +1 -1
  31. package/lib/codegen/languages/java.js +1 -2
  32. package/lib/codegen/languages/java.js.map +1 -1
  33. package/lib/codegen/languages/js.js +1 -2
  34. package/lib/codegen/languages/js.js.map +1 -1
  35. package/lib/codegen/languages/lua.js +1 -2
  36. package/lib/codegen/languages/lua.js.map +1 -1
  37. package/lib/codegen/languages/ts.js +1 -2
  38. package/lib/codegen/languages/ts.js.map +1 -1
  39. package/lib/codegen/parser.js +85 -3
  40. package/lib/codegen/parser.js.map +1 -1
  41. package/lib/codegen/types.js +6 -3
  42. package/lib/codegen/types.js.map +1 -1
  43. package/lib/debug.d.ts +1 -0
  44. package/lib/debug.js +51 -0
  45. package/lib/debug.js.map +1 -0
  46. package/lib/decoder/DecodeOperation.d.ts +3 -4
  47. package/lib/decoder/DecodeOperation.js +37 -19
  48. package/lib/decoder/DecodeOperation.js.map +1 -1
  49. package/lib/decoder/Decoder.d.ts +6 -7
  50. package/lib/decoder/Decoder.js +14 -14
  51. package/lib/decoder/Decoder.js.map +1 -1
  52. package/lib/decoder/ReferenceTracker.js +3 -2
  53. package/lib/decoder/ReferenceTracker.js.map +1 -1
  54. package/lib/decoder/strategy/RawChanges.js +1 -2
  55. package/lib/decoder/strategy/RawChanges.js.map +1 -1
  56. package/lib/decoder/strategy/StateCallbacks.d.ts +44 -11
  57. package/lib/decoder/strategy/StateCallbacks.js +75 -65
  58. package/lib/decoder/strategy/StateCallbacks.js.map +1 -1
  59. package/lib/encoder/ChangeTree.d.ts +27 -21
  60. package/lib/encoder/ChangeTree.js +246 -186
  61. package/lib/encoder/ChangeTree.js.map +1 -1
  62. package/lib/encoder/EncodeOperation.d.ts +3 -6
  63. package/lib/encoder/EncodeOperation.js +51 -65
  64. package/lib/encoder/EncodeOperation.js.map +1 -1
  65. package/lib/encoder/Encoder.d.ts +9 -8
  66. package/lib/encoder/Encoder.js +168 -91
  67. package/lib/encoder/Encoder.js.map +1 -1
  68. package/lib/encoder/Root.d.ts +22 -0
  69. package/lib/encoder/Root.js +81 -0
  70. package/lib/encoder/Root.js.map +1 -0
  71. package/lib/encoder/StateView.d.ts +7 -7
  72. package/lib/encoder/StateView.js +70 -74
  73. package/lib/encoder/StateView.js.map +1 -1
  74. package/lib/encoding/assert.d.ts +7 -6
  75. package/lib/encoding/assert.js +13 -5
  76. package/lib/encoding/assert.js.map +1 -1
  77. package/lib/encoding/decode.d.ts +35 -20
  78. package/lib/encoding/decode.js +43 -87
  79. package/lib/encoding/decode.js.map +1 -1
  80. package/lib/encoding/encode.d.ts +36 -17
  81. package/lib/encoding/encode.js +82 -68
  82. package/lib/encoding/encode.js.map +1 -1
  83. package/lib/encoding/spec.d.ts +4 -5
  84. package/lib/encoding/spec.js +1 -2
  85. package/lib/encoding/spec.js.map +1 -1
  86. package/lib/index.d.ts +10 -9
  87. package/lib/index.js +24 -17
  88. package/lib/index.js.map +1 -1
  89. package/lib/types/HelperTypes.d.ts +34 -2
  90. package/lib/types/HelperTypes.js.map +1 -1
  91. package/lib/types/TypeContext.d.ts +23 -0
  92. package/lib/types/TypeContext.js +111 -0
  93. package/lib/types/TypeContext.js.map +1 -0
  94. package/lib/types/custom/ArraySchema.d.ts +2 -2
  95. package/lib/types/custom/ArraySchema.js +33 -22
  96. package/lib/types/custom/ArraySchema.js.map +1 -1
  97. package/lib/types/custom/CollectionSchema.js +1 -0
  98. package/lib/types/custom/CollectionSchema.js.map +1 -1
  99. package/lib/types/custom/MapSchema.d.ts +3 -1
  100. package/lib/types/custom/MapSchema.js +12 -4
  101. package/lib/types/custom/MapSchema.js.map +1 -1
  102. package/lib/types/custom/SetSchema.js +1 -0
  103. package/lib/types/custom/SetSchema.js.map +1 -1
  104. package/lib/types/registry.d.ts +8 -1
  105. package/lib/types/registry.js +23 -6
  106. package/lib/types/registry.js.map +1 -1
  107. package/lib/types/symbols.d.ts +8 -5
  108. package/lib/types/symbols.js +9 -6
  109. package/lib/types/symbols.js.map +1 -1
  110. package/lib/types/utils.js +1 -2
  111. package/lib/types/utils.js.map +1 -1
  112. package/lib/utils.js +9 -7
  113. package/lib/utils.js.map +1 -1
  114. package/package.json +7 -6
  115. package/src/Metadata.ts +190 -42
  116. package/src/Reflection.ts +77 -39
  117. package/src/Schema.ts +59 -64
  118. package/src/annotations.ts +156 -202
  119. package/src/bench_encode.ts +108 -0
  120. package/src/codegen/languages/csharp.ts +1 -47
  121. package/src/codegen/parser.ts +107 -0
  122. package/src/codegen/types.ts +1 -0
  123. package/src/debug.ts +55 -0
  124. package/src/decoder/DecodeOperation.ts +46 -18
  125. package/src/decoder/Decoder.ts +17 -15
  126. package/src/decoder/ReferenceTracker.ts +3 -2
  127. package/src/decoder/strategy/StateCallbacks.ts +153 -82
  128. package/src/encoder/ChangeTree.ts +286 -202
  129. package/src/encoder/EncodeOperation.ts +78 -78
  130. package/src/encoder/Encoder.ts +202 -97
  131. package/src/encoder/Root.ts +93 -0
  132. package/src/encoder/StateView.ts +76 -88
  133. package/src/encoding/assert.ts +17 -8
  134. package/src/encoding/decode.ts +62 -97
  135. package/src/encoding/encode.ts +99 -65
  136. package/src/encoding/spec.ts +3 -5
  137. package/src/index.ts +12 -20
  138. package/src/types/HelperTypes.ts +54 -2
  139. package/src/types/TypeContext.ts +133 -0
  140. package/src/types/custom/ArraySchema.ts +49 -19
  141. package/src/types/custom/CollectionSchema.ts +1 -0
  142. package/src/types/custom/MapSchema.ts +18 -5
  143. package/src/types/custom/SetSchema.ts +1 -0
  144. package/src/types/registry.ts +22 -3
  145. package/src/types/symbols.ts +10 -7
  146. package/src/utils.ts +7 -3
@@ -22,8 +22,15 @@
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 = exports.utf8Read = void 0;
26
- const spec_1 = require("./spec");
25
+ exports.decode = void 0;
26
+ // force little endian to facilitate decoding on multiple implementations
27
+ const _isLittleEndian = true; // new Uint16Array(new Uint8Array([1, 0]).buffer)[0] === 1;
28
+ const _convoBuffer = new ArrayBuffer(8);
29
+ const _int32 = new Int32Array(_convoBuffer);
30
+ const _float32 = new Float32Array(_convoBuffer);
31
+ const _float64 = new Float64Array(_convoBuffer);
32
+ const _uint64 = new BigUint64Array(_convoBuffer);
33
+ const _int64 = new BigInt64Array(_convoBuffer);
27
34
  function utf8Read(bytes, it, length) {
28
35
  var string = '', chr = 0;
29
36
  for (var i = it.offset, end = it.offset + length; i < end; i++) {
@@ -64,81 +71,66 @@ function utf8Read(bytes, it, length) {
64
71
  it.offset += length;
65
72
  return string;
66
73
  }
67
- exports.utf8Read = utf8Read;
68
74
  function int8(bytes, it) {
69
75
  return uint8(bytes, it) << 24 >> 24;
70
76
  }
71
- exports.int8 = int8;
72
77
  ;
73
78
  function uint8(bytes, it) {
74
79
  return bytes[it.offset++];
75
80
  }
76
- exports.uint8 = uint8;
77
81
  ;
78
82
  function int16(bytes, it) {
79
83
  return uint16(bytes, it) << 16 >> 16;
80
84
  }
81
- exports.int16 = int16;
82
85
  ;
83
86
  function uint16(bytes, it) {
84
87
  return bytes[it.offset++] | bytes[it.offset++] << 8;
85
88
  }
86
- exports.uint16 = uint16;
87
89
  ;
88
90
  function int32(bytes, it) {
89
91
  return bytes[it.offset++] | bytes[it.offset++] << 8 | bytes[it.offset++] << 16 | bytes[it.offset++] << 24;
90
92
  }
91
- exports.int32 = int32;
92
93
  ;
93
94
  function uint32(bytes, it) {
94
95
  return int32(bytes, it) >>> 0;
95
96
  }
96
- exports.uint32 = uint32;
97
97
  ;
98
98
  function float32(bytes, it) {
99
- return readFloat32(bytes, it);
99
+ _int32[0] = int32(bytes, it);
100
+ return _float32[0];
100
101
  }
101
- exports.float32 = float32;
102
+ ;
102
103
  function float64(bytes, it) {
103
- return readFloat64(bytes, it);
104
+ _int32[_isLittleEndian ? 0 : 1] = int32(bytes, it);
105
+ _int32[_isLittleEndian ? 1 : 0] = int32(bytes, it);
106
+ return _float64[0];
104
107
  }
105
- exports.float64 = float64;
108
+ ;
106
109
  function int64(bytes, it) {
107
110
  const low = uint32(bytes, it);
108
111
  const high = int32(bytes, it) * Math.pow(2, 32);
109
112
  return high + low;
110
113
  }
111
- exports.int64 = int64;
112
114
  ;
113
115
  function uint64(bytes, it) {
114
116
  const low = uint32(bytes, it);
115
117
  const high = uint32(bytes, it) * Math.pow(2, 32);
116
118
  return high + low;
117
119
  }
118
- exports.uint64 = uint64;
119
120
  ;
120
- // force little endian to facilitate decoding on multiple implementations
121
- const _isLittleEndian = true; // new Uint16Array(new Uint8Array([1, 0]).buffer)[0] === 1;
122
- const _int32 = new Int32Array(2);
123
- const _float32 = new Float32Array(_int32.buffer);
124
- const _float64 = new Float64Array(_int32.buffer);
125
- function readFloat32(bytes, it) {
121
+ function bigint64(bytes, it) {
126
122
  _int32[0] = int32(bytes, it);
127
- return _float32[0];
123
+ _int32[1] = int32(bytes, it);
124
+ return _int64[0];
128
125
  }
129
- exports.readFloat32 = readFloat32;
130
- ;
131
- function readFloat64(bytes, it) {
132
- _int32[_isLittleEndian ? 0 : 1] = int32(bytes, it);
133
- _int32[_isLittleEndian ? 1 : 0] = int32(bytes, it);
134
- return _float64[0];
126
+ function biguint64(bytes, it) {
127
+ _int32[0] = int32(bytes, it);
128
+ _int32[1] = int32(bytes, it);
129
+ return _uint64[0];
135
130
  }
136
- exports.readFloat64 = readFloat64;
137
- ;
138
131
  function boolean(bytes, it) {
139
132
  return uint8(bytes, it) > 0;
140
133
  }
141
- exports.boolean = boolean;
142
134
  ;
143
135
  function string(bytes, it) {
144
136
  const prefix = bytes[it.offset++];
@@ -158,20 +150,6 @@ function string(bytes, it) {
158
150
  }
159
151
  return utf8Read(bytes, it, length);
160
152
  }
161
- exports.string = string;
162
- function stringCheck(bytes, it) {
163
- const prefix = bytes[it.offset];
164
- return (
165
- // fixstr
166
- (prefix < 0xc0 && prefix > 0xa0) ||
167
- // str 8
168
- prefix === 0xd9 ||
169
- // str 16
170
- prefix === 0xda ||
171
- // str 32
172
- prefix === 0xdb);
173
- }
174
- exports.stringCheck = stringCheck;
175
153
  function number(bytes, it) {
176
154
  const prefix = bytes[it.offset++];
177
155
  if (prefix < 0x80) {
@@ -180,11 +158,11 @@ function number(bytes, it) {
180
158
  }
181
159
  else if (prefix === 0xca) {
182
160
  // float 32
183
- return readFloat32(bytes, it);
161
+ return float32(bytes, it);
184
162
  }
185
163
  else if (prefix === 0xcb) {
186
164
  // float 64
187
- return readFloat64(bytes, it);
165
+ return float64(bytes, it);
188
166
  }
189
167
  else if (prefix === 0xcc) {
190
168
  // uint 8
@@ -223,45 +201,23 @@ function number(bytes, it) {
223
201
  return (0xff - prefix + 1) * -1;
224
202
  }
225
203
  }
226
- exports.number = number;
227
204
  ;
228
- function numberCheck(bytes, it) {
229
- const prefix = bytes[it.offset];
230
- // positive fixint - 0x00 - 0x7f
231
- // float 32 - 0xca
232
- // float 64 - 0xcb
233
- // uint 8 - 0xcc
234
- // uint 16 - 0xcd
235
- // uint 32 - 0xce
236
- // uint 64 - 0xcf
237
- // int 8 - 0xd0
238
- // int 16 - 0xd1
239
- // int 32 - 0xd2
240
- // int 64 - 0xd3
241
- return (prefix < 0x80 ||
242
- (prefix >= 0xca && prefix <= 0xd3));
243
- }
244
- exports.numberCheck = numberCheck;
245
- function arrayCheck(bytes, it) {
246
- return bytes[it.offset] < 0xa0;
247
- // const prefix = bytes[it.offset] ;
248
- // if (prefix < 0xa0) {
249
- // return prefix;
250
- // // array
251
- // } else if (prefix === 0xdc) {
252
- // it.offset += 2;
253
- // } else if (0xdd) {
254
- // it.offset += 4;
255
- // }
256
- // return prefix;
257
- }
258
- exports.arrayCheck = arrayCheck;
259
- function switchStructureCheck(bytes, it) {
260
- return (
261
- // previous byte should be `SWITCH_TO_STRUCTURE`
262
- bytes[it.offset - 1] === spec_1.SWITCH_TO_STRUCTURE &&
263
- // next byte should be a number
264
- (bytes[it.offset] < 0x80 || (bytes[it.offset] >= 0xca && bytes[it.offset] <= 0xd3)));
265
- }
266
- exports.switchStructureCheck = switchStructureCheck;
205
+ exports.decode = {
206
+ utf8Read,
207
+ int8,
208
+ uint8,
209
+ int16,
210
+ uint16,
211
+ int32,
212
+ uint32,
213
+ float32,
214
+ float64,
215
+ int64,
216
+ uint64,
217
+ bigint64,
218
+ biguint64,
219
+ boolean,
220
+ string,
221
+ number,
222
+ };
267
223
  //# sourceMappingURL=decode.js.map
@@ -1 +1 @@
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,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,GAAG,IAAI,CAAC,CACpB,CAAC;YACF,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,EAAE,CAAC;gBACrB,CAAC,CAAC,KAAK,CAAC,EAAE,CAAC,CAAC,GAAG,IAAI,CAAC,IAAI,CAAC,CAAC;gBAC1B,CAAC,CAAC,KAAK,CAAC,EAAE,CAA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AgB,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}"]}
1
+ {"version":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AK,EAAE,EAAE,CAAC,CAAC;IAE1B,CAAC;SAAM,IAAI,MAAM,KAAK,IAAI,EAAE,CAAC;QAC3B,SAAS;QACT,OAAO,KAAK,CAAC,KAAK,EAAE,EAAE,CAAC,CAAC;IAE1B,CAAC;SAAM,IAAI,MAAM,GAAG,IAAI,EAAE,CAAC;QACzB,kBAAkB;QAClB,OAAO,CAAC,IAAI,GAAG,MAAM,GAAG,CAAC,CAAC,GAAG,CAAC,CAAC,CAAA;IACjC,CAAC;AACH,CAAC;AAAA,CAAC;AAEW,QAAA,MAAM,GAAG;IAClB,QAAQ;IACR,IAAI;IACJ,KAAK;IACL,KAAK;IACL,MAAM;IACN,KAAK;IACL,MAAM;IACN,OAAO;IACP,OAAO;IACP,KAAK;IACL,MAAM;IACN,QAAQ;IACR,SAAS;IACT,OAAO;IACP,MAAM;IACN,MAAM;CACT,CAAA","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 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\n// force little endian to facilitate decoding on multiple implementations\nconst _isLittleEndian = true; // new Uint16Array(new Uint8Array([1, 0]).buffer)[0] === 1;\nconst _convoBuffer = new ArrayBuffer(8);\n\nconst _int32 = new Int32Array(_convoBuffer);\nconst _float32 = new Float32Array(_convoBuffer);\nconst _float64 = new Float64Array(_convoBuffer);\nconst _uint64 = new BigUint64Array(_convoBuffer);\nconst _int64 = new BigInt64Array(_convoBuffer);\n\nfunction 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\nfunction int8 (bytes: BufferLike, it: Iterator) {\n return uint8(bytes, it) << 24 >> 24;\n};\n\nfunction uint8 (bytes: BufferLike, it: Iterator) {\n return bytes[it.offset++];\n};\n\nfunction int16 (bytes: BufferLike, it: Iterator) {\n return uint16(bytes, it) << 16 >> 16;\n};\n\nfunction uint16 (bytes: BufferLike, it: Iterator) {\n return bytes[it.offset++] | bytes[it.offset++] << 8;\n};\n\nfunction int32 (bytes: BufferLike, it: Iterator) {\n return bytes[it.offset++] | bytes[it.offset++] << 8 | bytes[it.offset++] << 16 | bytes[it.offset++] << 24;\n};\n\nfunction uint32 (bytes: BufferLike, it: Iterator) {\n return int32(bytes, it) >>> 0;\n};\n\nfunction float32 (bytes: BufferLike, it: Iterator) {\n _int32[0] = int32(bytes, it);\n return _float32[0];\n};\n\nfunction float64 (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\nfunction 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\nfunction 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\nfunction bigint64(bytes: BufferLike, it: Iterator) {\n _int32[0] = int32(bytes, it);\n _int32[1] = int32(bytes, it);\n return _int64[0];\n}\n\nfunction biguint64(bytes: BufferLike, it: Iterator) {\n _int32[0] = int32(bytes, it);\n _int32[1] = int32(bytes, it);\n return _uint64[0];\n}\n\nfunction boolean (bytes: BufferLike, it: Iterator) {\n return uint8(bytes, it) > 0;\n};\n\nfunction 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\nfunction 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 float32(bytes, it);\n\n } else if (prefix === 0xcb) {\n // float 64\n return float64(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 const decode = {\n utf8Read,\n int8,\n uint8,\n int16,\n uint16,\n int32,\n uint32,\n float32,\n float64,\n int64,\n uint64,\n bigint64,\n biguint64,\n boolean,\n string,\n number,\n}"]}
@@ -22,20 +22,39 @@
22
22
  */
23
23
  import type { Iterator } from "./decode";
24
24
  export type BufferLike = number[] | ArrayBufferLike;
25
- export declare function utf8Length(str: any): number;
26
- export declare function utf8Write(view: any, str: any, it: any): void;
27
- export declare function int8(bytes: BufferLike, value: number, it: Iterator): void;
28
- export declare function uint8(bytes: BufferLike, value: number, it: Iterator): void;
29
- export declare function int16(bytes: BufferLike, value: number, it: Iterator): void;
30
- export declare function uint16(bytes: BufferLike, value: number, it: Iterator): void;
31
- export declare function int32(bytes: BufferLike, value: number, it: Iterator): void;
32
- export declare function uint32(bytes: BufferLike, value: number, it: Iterator): void;
33
- export declare function int64(bytes: BufferLike, value: number, it: Iterator): void;
34
- export declare function uint64(bytes: BufferLike, value: number, it: Iterator): void;
35
- export declare function float32(bytes: BufferLike, value: number, it: Iterator): void;
36
- export declare function float64(bytes: BufferLike, value: number, it: Iterator): void;
37
- export declare function writeFloat32(bytes: BufferLike, value: number, it: Iterator): void;
38
- export declare function writeFloat64(bytes: BufferLike, value: number, it: Iterator): void;
39
- export declare function boolean(bytes: BufferLike, value: number, it: Iterator): void;
40
- export declare function string(bytes: BufferLike, value: string, it: Iterator): number;
41
- export declare function number(bytes: BufferLike, value: number, it: Iterator): 1 | 2 | 3 | 5 | 9;
25
+ declare function utf8Write(view: BufferLike, str: string, it: Iterator): void;
26
+ declare function int8(bytes: BufferLike, value: number, it: Iterator): void;
27
+ declare function uint8(bytes: BufferLike, value: number, it: Iterator): void;
28
+ declare function int16(bytes: BufferLike, value: number, it: Iterator): void;
29
+ declare function uint16(bytes: BufferLike, value: number, it: Iterator): void;
30
+ declare function int32(bytes: BufferLike, value: number, it: Iterator): void;
31
+ declare function uint32(bytes: BufferLike, value: number, it: Iterator): void;
32
+ declare function int64(bytes: BufferLike, value: number, it: Iterator): void;
33
+ declare function uint64(bytes: BufferLike, value: number, it: Iterator): void;
34
+ declare function bigint64(bytes: BufferLike, value: bigint, it: Iterator): void;
35
+ declare function biguint64(bytes: BufferLike, value: bigint, it: Iterator): void;
36
+ declare function float32(bytes: BufferLike, value: number, it: Iterator): void;
37
+ declare function float64(bytes: BufferLike, value: number, it: Iterator): void;
38
+ declare function boolean(bytes: BufferLike, value: number, it: Iterator): void;
39
+ declare function string(bytes: BufferLike, value: string, it: Iterator): number;
40
+ declare function number(bytes: BufferLike, value: number, it: Iterator): 1 | 2 | 3 | 5 | 9;
41
+ export declare const encode: {
42
+ int8: typeof int8;
43
+ uint8: typeof uint8;
44
+ int16: typeof int16;
45
+ uint16: typeof uint16;
46
+ int32: typeof int32;
47
+ uint32: typeof uint32;
48
+ int64: typeof int64;
49
+ uint64: typeof uint64;
50
+ bigint64: typeof bigint64;
51
+ biguint64: typeof biguint64;
52
+ float32: typeof float32;
53
+ float64: typeof float64;
54
+ boolean: typeof boolean;
55
+ string: typeof string;
56
+ number: typeof number;
57
+ utf8Write: typeof utf8Write;
58
+ utf8Length: (str: string, _?: any) => number;
59
+ };
60
+ export {};
@@ -22,7 +22,7 @@
22
22
  * SOFTWARE
23
23
  */
24
24
  Object.defineProperty(exports, "__esModule", { value: true });
25
- exports.number = exports.string = exports.boolean = exports.writeFloat64 = exports.writeFloat32 = exports.float64 = exports.float32 = exports.uint64 = exports.int64 = exports.uint32 = exports.int32 = exports.uint16 = exports.int16 = exports.uint8 = exports.int8 = exports.utf8Write = exports.utf8Length = void 0;
25
+ exports.encode = void 0;
26
26
  /**
27
27
  * msgpack implementation highly based on notepack.io
28
28
  * https://github.com/darrachequesne/notepack
@@ -33,27 +33,36 @@ try {
33
33
  textEncoder = new TextEncoder();
34
34
  }
35
35
  catch (e) { }
36
- function utf8Length(str) {
37
- var c = 0, length = 0;
38
- for (var i = 0, l = str.length; i < l; i++) {
39
- c = str.charCodeAt(i);
40
- if (c < 0x80) {
41
- length += 1;
42
- }
43
- else if (c < 0x800) {
44
- length += 2;
45
- }
46
- else if (c < 0xd800 || c >= 0xe000) {
47
- length += 3;
48
- }
49
- else {
50
- i++;
51
- length += 4;
36
+ // force little endian to facilitate decoding on multiple implementations
37
+ const _isLittleEndian = true; // new Uint16Array(new Uint8Array([1, 0]).buffer)[0] === 1;
38
+ const _convoBuffer = new ArrayBuffer(8);
39
+ const _int32 = new Int32Array(_convoBuffer);
40
+ const _float32 = new Float32Array(_convoBuffer);
41
+ const _float64 = new Float64Array(_convoBuffer);
42
+ const _int64 = new BigInt64Array(_convoBuffer);
43
+ const hasBufferByteLength = (typeof Buffer !== 'undefined' && Buffer.byteLength);
44
+ const utf8Length = (hasBufferByteLength)
45
+ ? Buffer.byteLength // node
46
+ : function (str, _) {
47
+ var c = 0, length = 0;
48
+ for (var i = 0, l = str.length; i < l; i++) {
49
+ c = str.charCodeAt(i);
50
+ if (c < 0x80) {
51
+ length += 1;
52
+ }
53
+ else if (c < 0x800) {
54
+ length += 2;
55
+ }
56
+ else if (c < 0xd800 || c >= 0xe000) {
57
+ length += 3;
58
+ }
59
+ else {
60
+ i++;
61
+ length += 4;
62
+ }
52
63
  }
53
- }
54
- return length;
55
- }
56
- exports.utf8Length = utf8Length;
64
+ return length;
65
+ };
57
66
  function utf8Write(view, str, it) {
58
67
  var c = 0;
59
68
  for (var i = 0, l = str.length; i < l; i++) {
@@ -62,46 +71,44 @@ function utf8Write(view, str, it) {
62
71
  view[it.offset++] = c;
63
72
  }
64
73
  else if (c < 0x800) {
65
- view[it.offset++] = 0xc0 | (c >> 6);
66
- view[it.offset++] = 0x80 | (c & 0x3f);
74
+ view[it.offset] = 0xc0 | (c >> 6);
75
+ view[it.offset + 1] = 0x80 | (c & 0x3f);
76
+ it.offset += 2;
67
77
  }
68
78
  else if (c < 0xd800 || c >= 0xe000) {
69
- view[it.offset++] = 0xe0 | (c >> 12);
70
- view[it.offset++] = 0x80 | (c >> 6 & 0x3f);
71
- view[it.offset++] = 0x80 | (c & 0x3f);
79
+ view[it.offset] = 0xe0 | (c >> 12);
80
+ view[it.offset + 1] = 0x80 | (c >> 6 & 0x3f);
81
+ view[it.offset + 2] = 0x80 | (c & 0x3f);
82
+ it.offset += 3;
72
83
  }
73
84
  else {
74
85
  i++;
75
86
  c = 0x10000 + (((c & 0x3ff) << 10) | (str.charCodeAt(i) & 0x3ff));
76
- view[it.offset++] = 0xf0 | (c >> 18);
77
- view[it.offset++] = 0x80 | (c >> 12 & 0x3f);
78
- view[it.offset++] = 0x80 | (c >> 6 & 0x3f);
79
- view[it.offset++] = 0x80 | (c & 0x3f);
87
+ view[it.offset] = 0xf0 | (c >> 18);
88
+ view[it.offset + 1] = 0x80 | (c >> 12 & 0x3f);
89
+ view[it.offset + 2] = 0x80 | (c >> 6 & 0x3f);
90
+ view[it.offset + 3] = 0x80 | (c & 0x3f);
91
+ it.offset += 4;
80
92
  }
81
93
  }
82
94
  }
83
- exports.utf8Write = utf8Write;
84
95
  function int8(bytes, value, it) {
85
96
  bytes[it.offset++] = value & 255;
86
97
  }
87
- exports.int8 = int8;
88
98
  ;
89
99
  function uint8(bytes, value, it) {
90
100
  bytes[it.offset++] = value & 255;
91
101
  }
92
- exports.uint8 = uint8;
93
102
  ;
94
103
  function int16(bytes, value, it) {
95
104
  bytes[it.offset++] = value & 255;
96
105
  bytes[it.offset++] = (value >> 8) & 255;
97
106
  }
98
- exports.int16 = int16;
99
107
  ;
100
108
  function uint16(bytes, value, it) {
101
109
  bytes[it.offset++] = value & 255;
102
110
  bytes[it.offset++] = (value >> 8) & 255;
103
111
  }
104
- exports.uint16 = uint16;
105
112
  ;
106
113
  function int32(bytes, value, it) {
107
114
  bytes[it.offset++] = value & 255;
@@ -109,7 +116,6 @@ function int32(bytes, value, it) {
109
116
  bytes[it.offset++] = (value >> 16) & 255;
110
117
  bytes[it.offset++] = (value >> 24) & 255;
111
118
  }
112
- exports.int32 = int32;
113
119
  ;
114
120
  function uint32(bytes, value, it) {
115
121
  const b4 = value >> 24;
@@ -121,7 +127,6 @@ function uint32(bytes, value, it) {
121
127
  bytes[it.offset++] = b3 & 255;
122
128
  bytes[it.offset++] = b4 & 255;
123
129
  }
124
- exports.uint32 = uint32;
125
130
  ;
126
131
  function int64(bytes, value, it) {
127
132
  const high = Math.floor(value / Math.pow(2, 32));
@@ -129,7 +134,6 @@ function int64(bytes, value, it) {
129
134
  uint32(bytes, low, it);
130
135
  uint32(bytes, high, it);
131
136
  }
132
- exports.int64 = int64;
133
137
  ;
134
138
  function uint64(bytes, value, it) {
135
139
  const high = (value / Math.pow(2, 32)) >> 0;
@@ -137,46 +141,36 @@ function uint64(bytes, value, it) {
137
141
  uint32(bytes, low, it);
138
142
  uint32(bytes, high, it);
139
143
  }
140
- exports.uint64 = uint64;
141
144
  ;
142
- function float32(bytes, value, it) {
143
- writeFloat32(bytes, value, it);
145
+ function bigint64(bytes, value, it) {
146
+ _int64[0] = BigInt.asIntN(64, value);
147
+ int32(bytes, _int32[0], it);
148
+ int32(bytes, _int32[1], it);
144
149
  }
145
- exports.float32 = float32;
146
- function float64(bytes, value, it) {
147
- writeFloat64(bytes, value, it);
150
+ function biguint64(bytes, value, it) {
151
+ _int64[0] = BigInt.asIntN(64, value);
152
+ int32(bytes, _int32[0], it);
153
+ int32(bytes, _int32[1], it);
148
154
  }
149
- exports.float64 = float64;
150
- // force little endian to facilitate decoding on multiple implementations
151
- const _isLittleEndian = true; // new Uint16Array(new Uint8Array([1, 0]).buffer)[0] === 1;
152
- const _int32 = new Int32Array(2);
153
- const _float32 = new Float32Array(_int32.buffer);
154
- const _float64 = new Float64Array(_int32.buffer);
155
- function writeFloat32(bytes, value, it) {
155
+ function float32(bytes, value, it) {
156
156
  _float32[0] = value;
157
157
  int32(bytes, _int32[0], it);
158
158
  }
159
- exports.writeFloat32 = writeFloat32;
160
- ;
161
- function writeFloat64(bytes, value, it) {
159
+ function float64(bytes, value, it) {
162
160
  _float64[0] = value;
163
161
  int32(bytes, _int32[_isLittleEndian ? 0 : 1], it);
164
162
  int32(bytes, _int32[_isLittleEndian ? 1 : 0], it);
165
163
  }
166
- exports.writeFloat64 = writeFloat64;
167
- ;
168
164
  function boolean(bytes, value, it) {
169
165
  bytes[it.offset++] = value ? 1 : 0; // uint8
170
166
  }
171
- exports.boolean = boolean;
172
167
  ;
173
168
  function string(bytes, value, it) {
174
169
  // encode `null` strings as empty.
175
170
  if (!value) {
176
171
  value = "";
177
172
  }
178
- // let length = utf8Length(value);
179
- let length = Buffer.byteLength(value, "utf8");
173
+ let length = utf8Length(value, "utf8");
180
174
  let size = 0;
181
175
  // fixstr
182
176
  if (length < 0x20) {
@@ -207,7 +201,6 @@ function string(bytes, value, it) {
207
201
  utf8Write(bytes, value, it);
208
202
  return size + length;
209
203
  }
210
- exports.string = string;
211
204
  function number(bytes, value, it) {
212
205
  if (isNaN(value)) {
213
206
  return number(bytes, 0, it);
@@ -216,15 +209,18 @@ function number(bytes, value, it) {
216
209
  return number(bytes, (value > 0) ? Number.MAX_SAFE_INTEGER : -Number.MAX_SAFE_INTEGER, it);
217
210
  }
218
211
  else if (value !== (value | 0)) {
212
+ if (Math.abs(value) <= 3.4028235e+38) { // range check
213
+ _float32[0] = value;
214
+ if (Math.abs(Math.abs(_float32[0]) - Math.abs(value)) < 1e-4) { // precision check; adjust 1e-n (n = precision) to in-/decrease acceptable precision loss
215
+ // now we know value is in range for f32 and has acceptable precision for f32
216
+ bytes[it.offset++] = 0xca;
217
+ float32(bytes, value, it);
218
+ return 5;
219
+ }
220
+ }
219
221
  bytes[it.offset++] = 0xcb;
220
- writeFloat64(bytes, value, it);
222
+ float64(bytes, value, it);
221
223
  return 9;
222
- // TODO: encode float 32?
223
- // is it possible to differentiate between float32 / float64 here?
224
- // // float 32
225
- // bytes.push(0xca);
226
- // writeFloat32(bytes, value);
227
- // return 5;
228
224
  }
229
225
  if (value >= 0) {
230
226
  // positive fixnum
@@ -285,5 +281,23 @@ function number(bytes, value, it) {
285
281
  return 9;
286
282
  }
287
283
  }
288
- exports.number = number;
284
+ exports.encode = {
285
+ int8,
286
+ uint8,
287
+ int16,
288
+ uint16,
289
+ int32,
290
+ uint32,
291
+ int64,
292
+ uint64,
293
+ bigint64,
294
+ biguint64,
295
+ float32,
296
+ float64,
297
+ boolean,
298
+ string,
299
+ number,
300
+ utf8Write,
301
+ utf8Length,
302
+ };
289
303
  //# sourceMappingURL=encode.js.map