lib0 0.2.51 → 0.2.53
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/.github/workflows/node.js.yml +1 -1
- package/README.md +22 -20
- package/decoding.d.ts +2 -0
- package/decoding.d.ts.map +1 -1
- package/decoding.js +39 -14
- package/dist/{broadcastchannel-1e999014.cjs → broadcastchannel-a5969a44.cjs} +2 -2
- package/dist/{broadcastchannel-1e999014.cjs.map → broadcastchannel-a5969a44.cjs.map} +1 -1
- package/dist/broadcastchannel.cjs +6 -3
- package/dist/broadcastchannel.cjs.map +1 -1
- package/dist/{buffer-c98f67d5.cjs → buffer-9c449d1d.cjs} +93 -29
- package/dist/buffer-9c449d1d.cjs.map +1 -0
- package/dist/buffer.cjs +5 -2
- package/dist/buffer.cjs.map +1 -1
- package/dist/cache.cjs +3 -0
- package/dist/cache.cjs.map +1 -1
- package/dist/component.cjs +2 -2
- package/dist/decoding.cjs +8 -3
- package/dist/decoding.cjs.map +1 -1
- package/dist/decoding.d.ts +2 -0
- package/dist/decoding.d.ts.map +1 -1
- package/dist/{diff-2593547b.cjs → diff-642271b1.cjs} +2 -2
- package/dist/{diff-2593547b.cjs.map → diff-642271b1.cjs.map} +1 -1
- package/dist/diff.cjs +2 -2
- package/dist/encoding.cjs +8 -2
- package/dist/encoding.cjs.map +1 -1
- package/dist/encoding.d.ts +3 -0
- package/dist/encoding.d.ts.map +1 -1
- package/dist/encoding.test.d.ts +6 -1
- package/dist/encoding.test.d.ts.map +1 -1
- package/dist/{environment-60b83194.cjs → environment-3c81ab2f.cjs} +36 -13
- package/dist/environment-3c81ab2f.cjs.map +1 -0
- package/dist/environment.cjs +5 -1
- package/dist/environment.cjs.map +1 -1
- package/dist/environment.d.ts +1 -0
- package/dist/environment.d.ts.map +1 -1
- package/dist/{function-e4045b1d.cjs → function-3410854f.cjs} +14 -2
- package/dist/{function-e4045b1d.cjs.map → function-3410854f.cjs.map} +1 -1
- package/dist/function.cjs +2 -1
- package/dist/function.cjs.map +1 -1
- package/dist/function.d.ts +1 -0
- package/dist/function.d.ts.map +1 -1
- package/dist/index.cjs +7 -7
- package/dist/list.cjs +52 -1
- package/dist/list.cjs.map +1 -1
- package/dist/list.d.ts +5 -0
- package/dist/list.d.ts.map +1 -1
- package/dist/list.test.d.ts.map +1 -1
- package/dist/{logging-0a4d8595.cjs → logging-a2dc7e43.cjs} +131 -34
- package/dist/logging-a2dc7e43.cjs.map +1 -0
- package/dist/logging.cjs +3 -3
- package/dist/logging.d.ts.map +1 -1
- package/dist/number.test.d.ts +1 -0
- package/dist/number.test.d.ts.map +1 -1
- package/dist/{prng-bbec83e2.cjs → prng-c71ea8ea.cjs} +2 -2
- package/dist/{prng-bbec83e2.cjs.map → prng-c71ea8ea.cjs.map} +1 -1
- package/dist/prng.cjs +6 -3
- package/dist/prng.cjs.map +1 -1
- package/dist/testing.cjs +9 -9
- package/dist/testing.cjs.map +1 -1
- package/encoding.d.ts +3 -0
- package/encoding.d.ts.map +1 -1
- package/encoding.js +46 -14
- package/encoding.test.d.ts +6 -1
- package/encoding.test.d.ts.map +1 -1
- package/environment.d.ts +1 -0
- package/environment.d.ts.map +1 -1
- package/environment.js +32 -11
- package/function.d.ts +1 -0
- package/function.d.ts.map +1 -1
- package/function.js +10 -0
- package/list.d.ts +5 -0
- package/list.d.ts.map +1 -1
- package/list.js +46 -1
- package/list.test.d.ts.map +1 -1
- package/logging.d.ts.map +1 -1
- package/logging.js +128 -31
- package/number.test.d.ts +1 -0
- package/number.test.d.ts.map +1 -1
- package/package.json +2 -2
- package/testing.js +3 -3
- package/.circleci/config.yml +0 -7
- package/dist/buffer-c98f67d5.cjs.map +0 -1
- package/dist/environment-60b83194.cjs.map +0 -1
- package/dist/logging-0a4d8595.cjs.map +0 -1
- package/dist/test.cjs +0 -7637
- package/dist/test.cjs.map +0 -1
- package/dist/test.d.ts +0 -2
- package/dist/test.d.ts.map +0 -1
- package/dist/test.js +0 -7664
- package/dist/test.js.map +0 -1
package/README.md
CHANGED
|
@@ -12,7 +12,7 @@ export const stringify = JSON.stringify
|
|
|
12
12
|
export const parse = JSON.parse
|
|
13
13
|
|
|
14
14
|
// index.js
|
|
15
|
-
import * as json from 'lib0/json
|
|
15
|
+
import * as json from 'lib0/json'
|
|
16
16
|
export const f = (arg1, arg2) => json.stringify(arg1) + json.stringify(arg2)
|
|
17
17
|
|
|
18
18
|
// compiled with rollup and uglifyjs:
|
|
@@ -34,6 +34,7 @@ Each function in this library is tested thoroughly and is not deoptimized by v8
|
|
|
34
34
|
|
|
35
35
|
The code style might be a bit different from what you are used to. Stay open. Most of the design choices have been thought through. The purpose of this code style is to create code that is optimized by the compiler and that results in small code bundles when used with common module bundlers. Keep that in mind when reading the library.
|
|
36
36
|
|
|
37
|
+
* No polymorphism!
|
|
37
38
|
* Modules should only export pure functions and constants. This way the module bundler can eliminate dead code. The statement `const x = someCondition ? A : B` cannot be eleminated, because it is tied to a condition.
|
|
38
39
|
* Use Classes for structuring data. Classes are well supported by jsdoc and are immediately optimized by the compiler. I.e. prefer `class Coord { constructor (x, y) { this.x = x; this.y = y} }` instead of `{ x: x, y: y }`, because the compiler needs to be assured that the order of properties does not change. `{ y: y, x: x }` has a different hidden class than `{ x: x, y: y }`, which will lead to code deoptimizations if their use is alternated.
|
|
39
40
|
* The user of your module should never create data objects with the `new` keyword. Prefer exporting factory functions like `const createCoordinate = (x, y) => new Coord(x, y)`.
|
|
@@ -321,15 +322,7 @@ to the next byte and read it as unsigned integer.</p></dd>
|
|
|
321
322
|
<dd><p>Look ahead and read varUint without incrementing position</p></dd>
|
|
322
323
|
<b><code>decoding.peekVarInt(decoder: module:decoding.Decoder): number</code></b><br>
|
|
323
324
|
<dd><p>Look ahead and read varUint without incrementing position</p></dd>
|
|
324
|
-
<b><code>decoding.readVarString
|
|
325
|
-
<dd><p>Read string of variable length</p>
|
|
326
|
-
<ul>
|
|
327
|
-
<li>varUint is used to store the length of the string</li>
|
|
328
|
-
</ul>
|
|
329
|
-
<p>Transforming utf8 to a string is pretty expensive. The code performs 10x better
|
|
330
|
-
when String.fromCodePoint is fed with all characters as arguments.
|
|
331
|
-
But most environments have a maximum number of arguments per functions.
|
|
332
|
-
For effiency reasons we apply a maximum of 10000 characters at once.</p></dd>
|
|
325
|
+
<b><code>decoding.readVarString</code></b><br>
|
|
333
326
|
<b><code>decoding.peekVarString(decoder: module:decoding.Decoder): string</code></b><br>
|
|
334
327
|
<dd><p>Look ahead and read varString without incrementing position</p></dd>
|
|
335
328
|
<b><code>decoding.readFromDataView(decoder: module:decoding.Decoder, len: number): DataView</code></b><br>
|
|
@@ -480,6 +473,9 @@ decoding.hasContent(decoder) // => false - all data is read
|
|
|
480
473
|
<dd><p>The current length of the encoded data.</p></dd>
|
|
481
474
|
<b><code>encoding.toUint8Array(encoder: module:encoding.Encoder): Uint8Array</code></b><br>
|
|
482
475
|
<dd><p>Transform to Uint8Array.</p></dd>
|
|
476
|
+
<b><code>encoding.verifyLen(encoder: module:encoding.Encoder, len: number)</code></b><br>
|
|
477
|
+
<dd><p>Verify that it is possible to write <code>len</code> bytes wtihout checking. If
|
|
478
|
+
necessary, a new Buffer with the required length is attached.</p></dd>
|
|
483
479
|
<b><code>encoding.write(encoder: module:encoding.Encoder, num: number)</code></b><br>
|
|
484
480
|
<dd><p>Write one byte to the encoder.</p></dd>
|
|
485
481
|
<b><code>encoding.set(encoder: module:encoding.Encoder, pos: number, num: number)</code></b><br>
|
|
@@ -501,16 +497,11 @@ Position must already be written (i.e. encoder.length > pos)</p></dd>
|
|
|
501
497
|
<b><code>encoding.setUint32(encoder: module:encoding.Encoder, pos: number, num: number)</code></b><br>
|
|
502
498
|
<dd><p>Write two bytes as an unsigned integer at a specific location.</p></dd>
|
|
503
499
|
<b><code>encoding.writeVarUint(encoder: module:encoding.Encoder, num: number)</code></b><br>
|
|
504
|
-
<dd><p>Write a variable length unsigned integer.</p>
|
|
505
|
-
<p>Encodes integers in the range from [0, 4294967295] / [0, 0xffffffff]. (max 32 bit unsigned integer)</p></dd>
|
|
500
|
+
<dd><p>Write a variable length unsigned integer. Max encodable integer is 2^53.</p></dd>
|
|
506
501
|
<b><code>encoding.writeVarInt(encoder: module:encoding.Encoder, num: number)</code></b><br>
|
|
507
502
|
<dd><p>Write a variable length integer.</p>
|
|
508
|
-
<p>Encodes integers in the range from [-2147483648, -2147483647].</p>
|
|
509
|
-
<p>We don't use zig-zag encoding because we want to keep the option open
|
|
510
|
-
to use the same function for BigInt and 53bit integers (doubles).</p>
|
|
511
503
|
<p>We use the 7th bit instead for signaling that this is a negative number.</p></dd>
|
|
512
|
-
<b><code>encoding.writeVarString
|
|
513
|
-
<dd><p>Write a variable length string.</p></dd>
|
|
504
|
+
<b><code>encoding.writeVarString</code></b><br>
|
|
514
505
|
<b><code>encoding.writeBinaryEncoder(encoder: module:encoding.Encoder, append: module:encoding.Encoder)</code></b><br>
|
|
515
506
|
<dd><p>Write the content of another Encoder.</p></dd>
|
|
516
507
|
<b><code>encoding.writeUint8Array(encoder: module:encoding.Encoder, uint8Array: Uint8Array)</code></b><br>
|
|
@@ -707,6 +698,7 @@ In practice, when decoding several million small strings, the GC will kick in mo
|
|
|
707
698
|
<b><code>map.getConf(name: string): string|null</code></b><br>
|
|
708
699
|
<b><code>map.hasConf</code></b><br>
|
|
709
700
|
<b><code>map.production</code></b><br>
|
|
701
|
+
<b><code>map.supportsColor</code></b><br>
|
|
710
702
|
</dl>
|
|
711
703
|
</details>
|
|
712
704
|
<details><summary><b>[lib0/error]</b> Error helpers.</summary>
|
|
@@ -742,6 +734,7 @@ In practice, when decoding several million small strings, the GC will kick in mo
|
|
|
742
734
|
<b><code>function.equalityStrict(a: T, b: T): boolean</code></b><br>
|
|
743
735
|
<b><code>function.equalityFlat(a: Array<T>|object, b: Array<T>|object): boolean</code></b><br>
|
|
744
736
|
<b><code>function.equalityDeep(a: any, b: any): boolean</code></b><br>
|
|
737
|
+
<b><code>function.isOneOf(value: V, options: Array<OPTS>)</code></b><br>
|
|
745
738
|
</dl>
|
|
746
739
|
</details>
|
|
747
740
|
<details><summary><b>[lib0/lib0]</b> Experimental method to import lib0.</summary>
|
|
@@ -819,11 +812,16 @@ In practice, when decoding several million small strings, the GC will kick in mo
|
|
|
819
812
|
<b><code>()</code></b><br>
|
|
820
813
|
<b><code>(queue: module:list.List<N>)</code></b><br>
|
|
821
814
|
<b><code>()</code></b><br>
|
|
822
|
-
<b><code>
|
|
815
|
+
<b><code>(queue: module:list.List<N>, node: N)</code></b><br>
|
|
823
816
|
<dd><p>Remove a single node from the queue. Only works with Queues that operate on Doubly-linked lists of nodes.</p></dd>
|
|
817
|
+
<b><code>()</code></b><br>
|
|
818
|
+
<b><code>ode</code></b><br>
|
|
824
819
|
<b><code>ode()</code></b><br>
|
|
825
820
|
<b><code>etween(queue: module:list.List<N>, left: N| null, right: N| null, node: N)</code></b><br>
|
|
826
821
|
<b><code>etween()</code></b><br>
|
|
822
|
+
<b><code>(queue: module:list.List<N>, node: N, newNode: N)</code></b><br>
|
|
823
|
+
<dd><p>Remove a single node from the queue. Only works with Queues that operate on Doubly-linked lists of nodes.</p></dd>
|
|
824
|
+
<b><code>()</code></b><br>
|
|
827
825
|
<b><code>(queue: module:list.List<N>, n: N)</code></b><br>
|
|
828
826
|
<b><code>()</code></b><br>
|
|
829
827
|
<b><code>nt(queue: module:list.List<N>, n: N)</code></b><br>
|
|
@@ -834,6 +832,10 @@ In practice, when decoding several million small strings, the GC will kick in mo
|
|
|
834
832
|
<b><code>()</code></b><br>
|
|
835
833
|
<b><code>(list: module:list.List<N>, f: function(N):M): Array<M></code></b><br>
|
|
836
834
|
<b><code>()</code></b><br>
|
|
835
|
+
<b><code>(list: module:list.List<N>)</code></b><br>
|
|
836
|
+
<b><code>()</code></b><br>
|
|
837
|
+
<b><code>(list: module:list.List<N>, f: function(N):M)</code></b><br>
|
|
838
|
+
<b><code>()</code></b><br>
|
|
837
839
|
</dl>
|
|
838
840
|
</details>
|
|
839
841
|
<details><summary><b>[lib0/logging]</b> Isomorphic logging module with support for colors!</summary>
|
|
@@ -1171,8 +1173,8 @@ integrate this algorithm.</p>
|
|
|
1171
1173
|
<pre>import * as testing from 'lib0/testing'</pre>
|
|
1172
1174
|
|
|
1173
1175
|
<pre class="prettyprint source lang-js"><code>// test.js template for creating a test executable
|
|
1174
|
-
import { runTests } from 'lib0/testing
|
|
1175
|
-
import * as log from 'lib0/logging
|
|
1176
|
+
import { runTests } from 'lib0/testing'
|
|
1177
|
+
import * as log from 'lib0/logging'
|
|
1176
1178
|
import * as mod1 from './mod1.test.js'
|
|
1177
1179
|
import * as mod2 from './mod2.test.js'
|
|
1178
1180
|
import { isBrowser, isNode } from 'lib0/environment.js'
|
package/decoding.d.ts
CHANGED
|
@@ -37,6 +37,8 @@ export function readVarUint(decoder: Decoder): number;
|
|
|
37
37
|
export function readVarInt(decoder: Decoder): number;
|
|
38
38
|
export function peekVarUint(decoder: Decoder): number;
|
|
39
39
|
export function peekVarInt(decoder: Decoder): number;
|
|
40
|
+
export function _readVarStringPolyfill(decoder: Decoder): string;
|
|
41
|
+
export function _readVarStringNative(decoder: Decoder): string;
|
|
40
42
|
export function readVarString(decoder: Decoder): string;
|
|
41
43
|
export function peekVarString(decoder: Decoder): string;
|
|
42
44
|
export function readFromDataView(decoder: Decoder, len: number): DataView;
|
package/decoding.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"decoding.d.ts","sourceRoot":"","sources":["decoding.js"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"decoding.d.ts","sourceRoot":"","sources":["decoding.js"],"names":[],"mappings":"AAkCA;;GAEG;AACH;IACE;;OAEG;IACH,wBAFW,UAAU,EAepB;IAZC;;;;OAIG;IACH,KAFU,UAAU,CAEC;IACrB;;;;OAIG;IACH,KAFU,MAAM,CAEJ;CAEf;AAOM,0CAHI,UAAU,GACT,OAAO,CAE+C;AAO3D,oCAHI,OAAO,GACN,OAAO,CAEoD;AAWhE,+BAJI,OAAO,gCAEN,OAAO,CAMlB;AAaM,wCAJI,OAAO,OACP,MAAM,GACL,UAAU,CAMrB;AAYM,2CAHI,OAAO,GACN,UAAU,CAEmE;AAQlF,8CAHI,OAAO,GACN,UAAU,CAEkF;AAQjG,+BAHI,OAAO,GACN,MAAM,CAE2B;AAQtC,mCAHI,OAAO,GACN,MAAM,CAE4C;AASvD,oCAHI,OAAO,GACN,MAAM,CAQjB;AASM,oCAHI,OAAO,GACN,MAAM,CAUjB;AAUM,6CAHI,OAAO,GACN,MAAM,CAUjB;AAUM,mCAHI,OAAO,GACN,MAAM,CAE0C;AAUrD,oCAHI,OAAO,GACN,MAAM,CAImB;AAU9B,oCAHI,OAAO,GACN,MAAM,CAOX;AAYA,qCAHI,OAAO,GACN,MAAM,CAkBjB;AAaM,oCAHI,OAAO,GACN,MAAM,CAwBjB;AASM,qCAHI,OAAO,GACN,MAAM,CAOjB;AASM,oCAHI,OAAO,GACN,MAAM,CAOjB;AAgBM,gDAJI,OAAO,UA2BjB;AAOM,8CAHI,OAAO,UAI4D;AA/BvE,uCAJI,OAAO,UA2BjB;AA6BM,uCAHI,OAAO,GACN,MAAM,CAOjB;AAOM,0CAJI,OAAO,OACP,MAAM,GACL,QAAQ,CAMnB;AAKM,qCAFI,OAAO,UAEqE;AAKhF,qCAFI,OAAO,UAEqE;AAKhF,sCAFI,OAAO,OAE4F;AAKvG,uCAFI,OAAO,OAE8F;AAyCzG,iCAFI,OAAO,OAEqE;AAEvF;;;;GAIG;AACH;IACE;;;OAGG;IACH,wBAHW,UAAU,iBACD,OAAO,KAAE,CAAC,EAc7B;IAVC;;OAEG;IACH,eAPkB,OAAO,KAAE,CAAC,CAOR;IACpB;;;OAGG;IACH,GAFU,CAAC,GAAC,IAAI,CAEH;IACb,cAAc;IAGhB,UAWC;CACF;AAED;IACE;;;OAGG;IACH,wBAHW,UAAU,SACV,MAAM,EAShB;IALC;;;OAGG;IACH,GAFU,MAAM,CAEF;IAGhB;;OAEG;IACH,QAFY,MAAM,CAKjB;CACF;AAED;IACE;;;OAGG;IACH,wBAHW,UAAU,SACV,MAAM,EAUhB;IANC;;;OAGG;IACH,GAFU,MAAM,CAEF;IACd,cAAc;IAGhB;;OAEG;IACH,QAFY,MAAM,CAajB;CACF;AAED;IAMI;;OAEG;IACH,GAFU,MAAM,CAEN;IACV,cAAc;IAGhB,eAaC;CACF;AAED;IAMI;;OAEG;IACH,GAFU,MAAM,CAEN;IACV,cAAc;IAGhB,eAaC;CACF;AAED;IAMI;;OAEG;IACH,GAFU,MAAM,CAEN;IACV,cAAc;IACd,aAAa;IAGf;;OAEG;IACH,QAFY,MAAM,CAgBjB;CACF;AAED;IACE;;OAEG;IACH,wBAFW,UAAU,EASpB;IANC,2BAAgD;IAChD,YAAsC;IACtC;;OAEG;IACH,MAFU,MAAM,CAEH;IAGf;;OAEG;IACH,QAFY,MAAM,CAOjB;CACF"}
|
package/decoding.js
CHANGED
|
@@ -29,6 +29,8 @@
|
|
|
29
29
|
import * as buffer from './buffer.js'
|
|
30
30
|
import * as binary from './binary.js'
|
|
31
31
|
import * as math from './math.js'
|
|
32
|
+
import * as number from './number.js'
|
|
33
|
+
import * as string from './string.js'
|
|
32
34
|
|
|
33
35
|
/**
|
|
34
36
|
* A Decoder handles the decoding of an Uint8Array.
|
|
@@ -234,16 +236,17 @@ export const peekUint32 = decoder => (
|
|
|
234
236
|
*/
|
|
235
237
|
export const readVarUint = decoder => {
|
|
236
238
|
let num = 0
|
|
237
|
-
let
|
|
239
|
+
let mult = 1
|
|
238
240
|
while (true) {
|
|
239
241
|
const r = decoder.arr[decoder.pos++]
|
|
240
|
-
num = num | ((r & binary.BITS7) << len)
|
|
241
|
-
|
|
242
|
+
// num = num | ((r & binary.BITS7) << len)
|
|
243
|
+
num = num + (r & binary.BITS7) * mult // shift $r << (7*#iterations) and add it to num
|
|
244
|
+
mult *= 128 // next iteration, shift 7 "more" to the left
|
|
242
245
|
if (r < binary.BIT8) {
|
|
243
|
-
return num
|
|
246
|
+
return num
|
|
244
247
|
}
|
|
245
248
|
/* istanbul ignore if */
|
|
246
|
-
if (
|
|
249
|
+
if (num > number.MAX_SAFE_INTEGER) {
|
|
247
250
|
throw new Error('Integer out of range!')
|
|
248
251
|
}
|
|
249
252
|
}
|
|
@@ -263,7 +266,7 @@ export const readVarUint = decoder => {
|
|
|
263
266
|
export const readVarInt = decoder => {
|
|
264
267
|
let r = decoder.arr[decoder.pos++]
|
|
265
268
|
let num = r & binary.BITS6
|
|
266
|
-
let
|
|
269
|
+
let mult = 64
|
|
267
270
|
const sign = (r & binary.BIT7) > 0 ? -1 : 1
|
|
268
271
|
if ((r & binary.BIT8) === 0) {
|
|
269
272
|
// don't continue reading
|
|
@@ -271,13 +274,14 @@ export const readVarInt = decoder => {
|
|
|
271
274
|
}
|
|
272
275
|
while (true) {
|
|
273
276
|
r = decoder.arr[decoder.pos++]
|
|
274
|
-
num = num | ((r & binary.BITS7) << len)
|
|
275
|
-
|
|
277
|
+
// num = num | ((r & binary.BITS7) << len)
|
|
278
|
+
num = num + (r & binary.BITS7) * mult
|
|
279
|
+
mult *= 128
|
|
276
280
|
if (r < binary.BIT8) {
|
|
277
|
-
return sign *
|
|
281
|
+
return sign * num
|
|
278
282
|
}
|
|
279
283
|
/* istanbul ignore if */
|
|
280
|
-
if (
|
|
284
|
+
if (num > number.MAX_SAFE_INTEGER) {
|
|
281
285
|
throw new Error('Integer out of range!')
|
|
282
286
|
}
|
|
283
287
|
}
|
|
@@ -312,8 +316,8 @@ export const peekVarInt = decoder => {
|
|
|
312
316
|
}
|
|
313
317
|
|
|
314
318
|
/**
|
|
315
|
-
*
|
|
316
|
-
*
|
|
319
|
+
* We don't test this function anymore as we use native decoding/encoding by default now.
|
|
320
|
+
* Better not modify this anymore..
|
|
317
321
|
*
|
|
318
322
|
* Transforming utf8 to a string is pretty expensive. The code performs 10x better
|
|
319
323
|
* when String.fromCodePoint is fed with all characters as arguments.
|
|
@@ -324,7 +328,8 @@ export const peekVarInt = decoder => {
|
|
|
324
328
|
* @param {Decoder} decoder
|
|
325
329
|
* @return {String} The read String.
|
|
326
330
|
*/
|
|
327
|
-
|
|
331
|
+
/* istanbul ignore next */
|
|
332
|
+
export const _readVarStringPolyfill = decoder => {
|
|
328
333
|
let remainingLen = readVarUint(decoder)
|
|
329
334
|
if (remainingLen === 0) {
|
|
330
335
|
return ''
|
|
@@ -349,6 +354,26 @@ export const readVarString = decoder => {
|
|
|
349
354
|
}
|
|
350
355
|
}
|
|
351
356
|
|
|
357
|
+
/**
|
|
358
|
+
* @function
|
|
359
|
+
* @param {Decoder} decoder
|
|
360
|
+
* @return {String} The read String
|
|
361
|
+
*/
|
|
362
|
+
export const _readVarStringNative = decoder =>
|
|
363
|
+
/** @type any */ (string.utf8TextDecoder).decode(readVarUint8Array(decoder))
|
|
364
|
+
|
|
365
|
+
/**
|
|
366
|
+
* Read string of variable length
|
|
367
|
+
* * varUint is used to store the length of the string
|
|
368
|
+
*
|
|
369
|
+
* @function
|
|
370
|
+
* @param {Decoder} decoder
|
|
371
|
+
* @return {String} The read String
|
|
372
|
+
*
|
|
373
|
+
*/
|
|
374
|
+
/* istanbul ignore next */
|
|
375
|
+
export const readVarString = string.utf8TextDecoder ? _readVarStringNative : _readVarStringPolyfill
|
|
376
|
+
|
|
352
377
|
/**
|
|
353
378
|
* Look ahead and read varString without incrementing position
|
|
354
379
|
*
|
|
@@ -608,7 +633,7 @@ export class IntDiffOptRleDecoder extends Decoder {
|
|
|
608
633
|
const diff = readVarInt(this)
|
|
609
634
|
// if the first bit is set, we read more data
|
|
610
635
|
const hasCount = diff & 1
|
|
611
|
-
this.diff = diff >> 1
|
|
636
|
+
this.diff = math.floor(diff / 2) // shift >> 1
|
|
612
637
|
this.count = 1
|
|
613
638
|
if (hasCount) {
|
|
614
639
|
this.count = readVarUint(this) + 2
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
3
|
var map = require('./map-28a001c9.cjs');
|
|
4
|
-
var encoding = require('./buffer-
|
|
4
|
+
var encoding = require('./buffer-9c449d1d.cjs');
|
|
5
5
|
var storage = require('./storage.cjs');
|
|
6
6
|
|
|
7
7
|
/* eslint-env browser */
|
|
@@ -101,4 +101,4 @@ exports.broadcastchannel = broadcastchannel;
|
|
|
101
101
|
exports.publish = publish;
|
|
102
102
|
exports.subscribe = subscribe;
|
|
103
103
|
exports.unsubscribe = unsubscribe;
|
|
104
|
-
//# sourceMappingURL=broadcastchannel-
|
|
104
|
+
//# sourceMappingURL=broadcastchannel-a5969a44.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"broadcastchannel-
|
|
1
|
+
{"version":3,"file":"broadcastchannel-a5969a44.cjs","sources":["../broadcastchannel.js"],"sourcesContent":["/* eslint-env browser */\n\n/**\n * Helpers for cross-tab communication using broadcastchannel with LocalStorage fallback.\n *\n * ```js\n * // In browser window A:\n * broadcastchannel.subscribe('my events', data => console.log(data))\n * broadcastchannel.publish('my events', 'Hello world!') // => A: 'Hello world!' fires synchronously in same tab\n *\n * // In browser window B:\n * broadcastchannel.publish('my events', 'hello from tab B') // => A: 'hello from tab B'\n * ```\n *\n * @module broadcastchannel\n */\n\n// @todo before next major: use Uint8Array instead as buffer object\n\nimport * as map from './map.js'\nimport * as buffer from './buffer.js'\nimport * as storage from './storage.js'\n\n/**\n * @typedef {Object} Channel\n * @property {Set<function(any, any):any>} Channel.subs\n * @property {any} Channel.bc\n */\n\n/**\n * @type {Map<string, Channel>}\n */\nconst channels = new Map()\n\nclass LocalStoragePolyfill {\n /**\n * @param {string} room\n */\n constructor (room) {\n this.room = room\n /**\n * @type {null|function({data:ArrayBuffer}):void}\n */\n this.onmessage = null\n storage.onChange(e => e.key === room && this.onmessage !== null && this.onmessage({ data: buffer.fromBase64(e.newValue || '') }))\n }\n\n /**\n * @param {ArrayBuffer} buf\n */\n postMessage (buf) {\n storage.varStorage.setItem(this.room, buffer.toBase64(buffer.createUint8ArrayFromArrayBuffer(buf)))\n }\n}\n\n// Use BroadcastChannel or Polyfill\nconst BC = typeof BroadcastChannel === 'undefined' ? LocalStoragePolyfill : BroadcastChannel\n\n/**\n * @param {string} room\n * @return {Channel}\n */\nconst getChannel = room =>\n map.setIfUndefined(channels, room, () => {\n const subs = new Set()\n const bc = new BC(room)\n /**\n * @param {{data:ArrayBuffer}} e\n */\n bc.onmessage = e => subs.forEach(sub => sub(e.data, 'broadcastchannel'))\n return {\n bc, subs\n }\n })\n\n/**\n * Subscribe to global `publish` events.\n *\n * @function\n * @param {string} room\n * @param {function(any, any):any} f\n */\nexport const subscribe = (room, f) => getChannel(room).subs.add(f)\n\n/**\n * Unsubscribe from `publish` global events.\n *\n * @function\n * @param {string} room\n * @param {function(any, any):any} f\n */\nexport const unsubscribe = (room, f) => getChannel(room).subs.delete(f)\n\n/**\n * Publish data to all subscribers (including subscribers on this tab)\n *\n * @function\n * @param {string} room\n * @param {any} data\n * @param {any} [origin]\n */\nexport const publish = (room, data, origin = null) => {\n const c = getChannel(room)\n c.bc.postMessage(data)\n c.subs.forEach(sub => sub(data, origin))\n}\n"],"names":["storage.onChange","buffer.fromBase64","storage.varStorage","buffer.toBase64","buffer.createUint8ArrayFromArrayBuffer","map.setIfUndefined"],"mappings":";;;;;;AAAA;AAsBA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,MAAM,QAAQ,GAAG,IAAI,GAAG,GAAE;AAC1B;AACA,MAAM,oBAAoB,CAAC;AAC3B;AACA;AACA;AACA,EAAE,WAAW,CAAC,CAAC,IAAI,EAAE;AACrB,IAAI,IAAI,CAAC,IAAI,GAAG,KAAI;AACpB;AACA;AACA;AACA,IAAI,IAAI,CAAC,SAAS,GAAG,KAAI;AACzB,IAAIA,gBAAgB,CAAC,CAAC,IAAI,CAAC,CAAC,GAAG,KAAK,IAAI,IAAI,IAAI,CAAC,SAAS,KAAK,IAAI,IAAI,IAAI,CAAC,SAAS,CAAC,EAAE,IAAI,EAAEC,mBAAiB,CAAC,CAAC,CAAC,QAAQ,IAAI,EAAE,CAAC,EAAE,CAAC,EAAC;AACrI,GAAG;AACH;AACA;AACA;AACA;AACA,EAAE,WAAW,CAAC,CAAC,GAAG,EAAE;AACpB,IAAIC,kBAAkB,CAAC,OAAO,CAAC,IAAI,CAAC,IAAI,EAAEC,iBAAe,CAACC,wCAAsC,CAAC,GAAG,CAAC,CAAC,EAAC;AACvG,GAAG;AACH,CAAC;AACD;AACA;AACA,MAAM,EAAE,GAAG,OAAO,gBAAgB,KAAK,WAAW,GAAG,oBAAoB,GAAG,iBAAgB;AAC5F;AACA;AACA;AACA;AACA;AACA,MAAM,UAAU,GAAG,IAAI;AACvB,EAAEC,kBAAkB,CAAC,QAAQ,EAAE,IAAI,EAAE,MAAM;AAC3C,IAAI,MAAM,IAAI,GAAG,IAAI,GAAG,GAAE;AAC1B,IAAI,MAAM,EAAE,GAAG,IAAI,EAAE,CAAC,IAAI,EAAC;AAC3B;AACA;AACA;AACA,IAAI,EAAE,CAAC,SAAS,GAAG,CAAC,IAAI,IAAI,CAAC,OAAO,CAAC,GAAG,IAAI,GAAG,CAAC,CAAC,CAAC,IAAI,EAAE,kBAAkB,CAAC,EAAC;AAC5E,IAAI,OAAO;AACX,MAAM,EAAE,EAAE,IAAI;AACd,KAAK;AACL,GAAG,EAAC;AACJ;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACY,MAAC,SAAS,GAAG,CAAC,IAAI,EAAE,CAAC,KAAK,UAAU,CAAC,IAAI,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,EAAC;AAClE;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACY,MAAC,WAAW,GAAG,CAAC,IAAI,EAAE,CAAC,KAAK,UAAU,CAAC,IAAI,CAAC,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,EAAC;AACvE;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACY,MAAC,OAAO,GAAG,CAAC,IAAI,EAAE,IAAI,EAAE,MAAM,GAAG,IAAI,KAAK;AACtD,EAAE,MAAM,CAAC,GAAG,UAAU,CAAC,IAAI,EAAC;AAC5B,EAAE,CAAC,CAAC,EAAE,CAAC,WAAW,CAAC,IAAI,EAAC;AACxB,EAAE,CAAC,CAAC,IAAI,CAAC,OAAO,CAAC,GAAG,IAAI,GAAG,CAAC,IAAI,EAAE,MAAM,CAAC,EAAC;AAC1C;;;;;;;;;;;;;;"}
|
|
@@ -3,12 +3,15 @@
|
|
|
3
3
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
4
|
|
|
5
5
|
require('./map-28a001c9.cjs');
|
|
6
|
-
require('./buffer-
|
|
6
|
+
require('./buffer-9c449d1d.cjs');
|
|
7
7
|
require('./storage.cjs');
|
|
8
|
-
var broadcastchannel = require('./broadcastchannel-
|
|
8
|
+
var broadcastchannel = require('./broadcastchannel-a5969a44.cjs');
|
|
9
9
|
require('./string-ad04f734.cjs');
|
|
10
|
-
require('./environment-
|
|
10
|
+
require('./environment-3c81ab2f.cjs');
|
|
11
11
|
require('./conditions-fb475c70.cjs');
|
|
12
|
+
require('./function-3410854f.cjs');
|
|
13
|
+
require('./array-acefe0f2.cjs');
|
|
14
|
+
require('./object-dcdd6eed.cjs');
|
|
12
15
|
require('./binary-ac8e39e2.cjs');
|
|
13
16
|
require('./math-08e068f9.cjs');
|
|
14
17
|
require('./number-e62129bc.cjs');
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"broadcastchannel.cjs","sources":[],"sourcesContent":[],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"broadcastchannel.cjs","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;"}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
3
|
var string = require('./string-ad04f734.cjs');
|
|
4
|
-
var environment = require('./environment-
|
|
4
|
+
var environment = require('./environment-3c81ab2f.cjs');
|
|
5
5
|
var binary = require('./binary-ac8e39e2.cjs');
|
|
6
6
|
var math = require('./math-08e068f9.cjs');
|
|
7
7
|
var number = require('./number-e62129bc.cjs');
|
|
@@ -235,9 +235,7 @@ const setUint32 = (encoder, pos, num) => {
|
|
|
235
235
|
};
|
|
236
236
|
|
|
237
237
|
/**
|
|
238
|
-
* Write a variable length unsigned integer.
|
|
239
|
-
*
|
|
240
|
-
* Encodes integers in the range from [0, 4294967295] / [0, 0xffffffff]. (max 32 bit unsigned integer)
|
|
238
|
+
* Write a variable length unsigned integer. Max encodable integer is 2^53.
|
|
241
239
|
*
|
|
242
240
|
* @function
|
|
243
241
|
* @param {Encoder} encoder
|
|
@@ -246,7 +244,7 @@ const setUint32 = (encoder, pos, num) => {
|
|
|
246
244
|
const writeVarUint = (encoder, num) => {
|
|
247
245
|
while (num > binary.BITS7) {
|
|
248
246
|
write(encoder, binary.BIT8 | (binary.BITS7 & num));
|
|
249
|
-
num
|
|
247
|
+
num = math.floor(num / 128); // shift >>> 7
|
|
250
248
|
}
|
|
251
249
|
write(encoder, binary.BITS7 & num);
|
|
252
250
|
};
|
|
@@ -254,11 +252,6 @@ const writeVarUint = (encoder, num) => {
|
|
|
254
252
|
/**
|
|
255
253
|
* Write a variable length integer.
|
|
256
254
|
*
|
|
257
|
-
* Encodes integers in the range from [-2147483648, -2147483647].
|
|
258
|
-
*
|
|
259
|
-
* We don't use zig-zag encoding because we want to keep the option open
|
|
260
|
-
* to use the same function for BigInt and 53bit integers (doubles).
|
|
261
|
-
*
|
|
262
255
|
* We use the 7th bit instead for signaling that this is a negative number.
|
|
263
256
|
*
|
|
264
257
|
* @function
|
|
@@ -272,15 +265,21 @@ const writeVarInt = (encoder, num) => {
|
|
|
272
265
|
}
|
|
273
266
|
// |- whether to continue reading |- whether is negative |- number
|
|
274
267
|
write(encoder, (num > binary.BITS6 ? binary.BIT8 : 0) | (isNegative ? binary.BIT7 : 0) | (binary.BITS6 & num));
|
|
275
|
-
num
|
|
268
|
+
num = math.floor(num / 64); // shift >>> 6
|
|
276
269
|
// We don't need to consider the case of num === 0 so we can use a different
|
|
277
270
|
// pattern here than above.
|
|
278
271
|
while (num > 0) {
|
|
279
272
|
write(encoder, (num > binary.BITS7 ? binary.BIT8 : 0) | (binary.BITS7 & num));
|
|
280
|
-
num
|
|
273
|
+
num = math.floor(num / 128); // shift >>> 7
|
|
281
274
|
}
|
|
282
275
|
};
|
|
283
276
|
|
|
277
|
+
/**
|
|
278
|
+
* A cache to store strings temporarily
|
|
279
|
+
*/
|
|
280
|
+
const _strBuffer = new Uint8Array(30000);
|
|
281
|
+
const _maxStrBSize = _strBuffer.length / 3;
|
|
282
|
+
|
|
284
283
|
/**
|
|
285
284
|
* Write a variable length string.
|
|
286
285
|
*
|
|
@@ -288,7 +287,28 @@ const writeVarInt = (encoder, num) => {
|
|
|
288
287
|
* @param {Encoder} encoder
|
|
289
288
|
* @param {String} str The string that is to be encoded.
|
|
290
289
|
*/
|
|
291
|
-
const
|
|
290
|
+
const _writeVarStringNative = (encoder, str) => {
|
|
291
|
+
if (str.length < _maxStrBSize) {
|
|
292
|
+
// We can encode the string into the existing buffer
|
|
293
|
+
/* istanbul ignore else */
|
|
294
|
+
const written = string.utf8TextEncoder.encodeInto(str, _strBuffer).written || 0;
|
|
295
|
+
writeVarUint(encoder, written);
|
|
296
|
+
for (let i = 0; i < written; i++) {
|
|
297
|
+
write(encoder, _strBuffer[i]);
|
|
298
|
+
}
|
|
299
|
+
} else {
|
|
300
|
+
writeVarUint8Array(encoder, string.encodeUtf8(str));
|
|
301
|
+
}
|
|
302
|
+
};
|
|
303
|
+
|
|
304
|
+
/**
|
|
305
|
+
* Write a variable length string.
|
|
306
|
+
*
|
|
307
|
+
* @function
|
|
308
|
+
* @param {Encoder} encoder
|
|
309
|
+
* @param {String} str The string that is to be encoded.
|
|
310
|
+
*/
|
|
311
|
+
const _writeVarStringPolyfill = (encoder, str) => {
|
|
292
312
|
const encodedString = unescape(encodeURIComponent(str));
|
|
293
313
|
const len = encodedString.length;
|
|
294
314
|
writeVarUint(encoder, len);
|
|
@@ -297,6 +317,16 @@ const writeVarString = (encoder, str) => {
|
|
|
297
317
|
}
|
|
298
318
|
};
|
|
299
319
|
|
|
320
|
+
/**
|
|
321
|
+
* Write a variable length string.
|
|
322
|
+
*
|
|
323
|
+
* @function
|
|
324
|
+
* @param {Encoder} encoder
|
|
325
|
+
* @param {String} str The string that is to be encoded.
|
|
326
|
+
*/
|
|
327
|
+
/* istanbul ignore next */
|
|
328
|
+
const writeVarString = (string.utf8TextEncoder && string.utf8TextEncoder.encodeInto) ? _writeVarStringNative : _writeVarStringPolyfill;
|
|
329
|
+
|
|
300
330
|
/**
|
|
301
331
|
* Write the content of another Encoder.
|
|
302
332
|
*
|
|
@@ -724,7 +754,8 @@ class IncUintOptRleEncoder {
|
|
|
724
754
|
const flushIntDiffOptRleEncoder = encoder => {
|
|
725
755
|
if (encoder.count > 0) {
|
|
726
756
|
// 31 bit making up the diff | wether to write the counter
|
|
727
|
-
const encodedDiff = encoder.diff << 1 | (encoder.count === 1 ? 0 : 1)
|
|
757
|
+
// const encodedDiff = encoder.diff << 1 | (encoder.count === 1 ? 0 : 1)
|
|
758
|
+
const encodedDiff = encoder.diff * 2 + (encoder.count === 1 ? 0 : 1);
|
|
728
759
|
// flush counter, unless this is the first value (count = 0)
|
|
729
760
|
// case 1: just a single value. set first bit to positive
|
|
730
761
|
// case 2: write several values. set first bit to negative to indicate that there is a length coming
|
|
@@ -832,6 +863,7 @@ var encoding = /*#__PURE__*/Object.freeze({
|
|
|
832
863
|
createEncoder: createEncoder,
|
|
833
864
|
length: length,
|
|
834
865
|
toUint8Array: toUint8Array,
|
|
866
|
+
verifyLen: verifyLen,
|
|
835
867
|
write: write,
|
|
836
868
|
set: set,
|
|
837
869
|
writeUint8: writeUint8,
|
|
@@ -843,6 +875,8 @@ var encoding = /*#__PURE__*/Object.freeze({
|
|
|
843
875
|
setUint32: setUint32,
|
|
844
876
|
writeVarUint: writeVarUint,
|
|
845
877
|
writeVarInt: writeVarInt,
|
|
878
|
+
_writeVarStringNative: _writeVarStringNative,
|
|
879
|
+
_writeVarStringPolyfill: _writeVarStringPolyfill,
|
|
846
880
|
writeVarString: writeVarString,
|
|
847
881
|
writeBinaryEncoder: writeBinaryEncoder,
|
|
848
882
|
writeUint8Array: writeUint8Array,
|
|
@@ -1094,16 +1128,17 @@ const peekUint32 = decoder => (
|
|
|
1094
1128
|
*/
|
|
1095
1129
|
const readVarUint = decoder => {
|
|
1096
1130
|
let num = 0;
|
|
1097
|
-
let
|
|
1131
|
+
let mult = 1;
|
|
1098
1132
|
while (true) {
|
|
1099
1133
|
const r = decoder.arr[decoder.pos++];
|
|
1100
|
-
num = num | ((r & binary.BITS7) << len)
|
|
1101
|
-
|
|
1134
|
+
// num = num | ((r & binary.BITS7) << len)
|
|
1135
|
+
num = num + (r & binary.BITS7) * mult; // shift $r << (7*#iterations) and add it to num
|
|
1136
|
+
mult *= 128; // next iteration, shift 7 "more" to the left
|
|
1102
1137
|
if (r < binary.BIT8) {
|
|
1103
|
-
return num
|
|
1138
|
+
return num
|
|
1104
1139
|
}
|
|
1105
1140
|
/* istanbul ignore if */
|
|
1106
|
-
if (
|
|
1141
|
+
if (num > number.MAX_SAFE_INTEGER) {
|
|
1107
1142
|
throw new Error('Integer out of range!')
|
|
1108
1143
|
}
|
|
1109
1144
|
}
|
|
@@ -1123,7 +1158,7 @@ const readVarUint = decoder => {
|
|
|
1123
1158
|
const readVarInt = decoder => {
|
|
1124
1159
|
let r = decoder.arr[decoder.pos++];
|
|
1125
1160
|
let num = r & binary.BITS6;
|
|
1126
|
-
let
|
|
1161
|
+
let mult = 64;
|
|
1127
1162
|
const sign = (r & binary.BIT7) > 0 ? -1 : 1;
|
|
1128
1163
|
if ((r & binary.BIT8) === 0) {
|
|
1129
1164
|
// don't continue reading
|
|
@@ -1131,13 +1166,14 @@ const readVarInt = decoder => {
|
|
|
1131
1166
|
}
|
|
1132
1167
|
while (true) {
|
|
1133
1168
|
r = decoder.arr[decoder.pos++];
|
|
1134
|
-
num = num | ((r & binary.BITS7) << len)
|
|
1135
|
-
|
|
1169
|
+
// num = num | ((r & binary.BITS7) << len)
|
|
1170
|
+
num = num + (r & binary.BITS7) * mult;
|
|
1171
|
+
mult *= 128;
|
|
1136
1172
|
if (r < binary.BIT8) {
|
|
1137
|
-
return sign *
|
|
1173
|
+
return sign * num
|
|
1138
1174
|
}
|
|
1139
1175
|
/* istanbul ignore if */
|
|
1140
|
-
if (
|
|
1176
|
+
if (num > number.MAX_SAFE_INTEGER) {
|
|
1141
1177
|
throw new Error('Integer out of range!')
|
|
1142
1178
|
}
|
|
1143
1179
|
}
|
|
@@ -1172,8 +1208,8 @@ const peekVarInt = decoder => {
|
|
|
1172
1208
|
};
|
|
1173
1209
|
|
|
1174
1210
|
/**
|
|
1175
|
-
*
|
|
1176
|
-
*
|
|
1211
|
+
* We don't test this function anymore as we use native decoding/encoding by default now.
|
|
1212
|
+
* Better not modify this anymore..
|
|
1177
1213
|
*
|
|
1178
1214
|
* Transforming utf8 to a string is pretty expensive. The code performs 10x better
|
|
1179
1215
|
* when String.fromCodePoint is fed with all characters as arguments.
|
|
@@ -1184,7 +1220,8 @@ const peekVarInt = decoder => {
|
|
|
1184
1220
|
* @param {Decoder} decoder
|
|
1185
1221
|
* @return {String} The read String.
|
|
1186
1222
|
*/
|
|
1187
|
-
|
|
1223
|
+
/* istanbul ignore next */
|
|
1224
|
+
const _readVarStringPolyfill = decoder => {
|
|
1188
1225
|
let remainingLen = readVarUint(decoder);
|
|
1189
1226
|
if (remainingLen === 0) {
|
|
1190
1227
|
return ''
|
|
@@ -1209,6 +1246,26 @@ const readVarString = decoder => {
|
|
|
1209
1246
|
}
|
|
1210
1247
|
};
|
|
1211
1248
|
|
|
1249
|
+
/**
|
|
1250
|
+
* @function
|
|
1251
|
+
* @param {Decoder} decoder
|
|
1252
|
+
* @return {String} The read String
|
|
1253
|
+
*/
|
|
1254
|
+
const _readVarStringNative = decoder =>
|
|
1255
|
+
/** @type any */ (string.utf8TextDecoder).decode(readVarUint8Array(decoder));
|
|
1256
|
+
|
|
1257
|
+
/**
|
|
1258
|
+
* Read string of variable length
|
|
1259
|
+
* * varUint is used to store the length of the string
|
|
1260
|
+
*
|
|
1261
|
+
* @function
|
|
1262
|
+
* @param {Decoder} decoder
|
|
1263
|
+
* @return {String} The read String
|
|
1264
|
+
*
|
|
1265
|
+
*/
|
|
1266
|
+
/* istanbul ignore next */
|
|
1267
|
+
const readVarString = string.utf8TextDecoder ? _readVarStringNative : _readVarStringPolyfill;
|
|
1268
|
+
|
|
1212
1269
|
/**
|
|
1213
1270
|
* Look ahead and read varString without incrementing position
|
|
1214
1271
|
*
|
|
@@ -1468,7 +1525,7 @@ class IntDiffOptRleDecoder extends Decoder {
|
|
|
1468
1525
|
const diff = readVarInt(this);
|
|
1469
1526
|
// if the first bit is set, we read more data
|
|
1470
1527
|
const hasCount = diff & 1;
|
|
1471
|
-
this.diff = diff >> 1
|
|
1528
|
+
this.diff = math.floor(diff / 2); // shift >> 1
|
|
1472
1529
|
this.count = 1;
|
|
1473
1530
|
if (hasCount) {
|
|
1474
1531
|
this.count = readVarUint(this) + 2;
|
|
@@ -1525,6 +1582,8 @@ var decoding = /*#__PURE__*/Object.freeze({
|
|
|
1525
1582
|
readVarInt: readVarInt,
|
|
1526
1583
|
peekVarUint: peekVarUint,
|
|
1527
1584
|
peekVarInt: peekVarInt,
|
|
1585
|
+
_readVarStringPolyfill: _readVarStringPolyfill,
|
|
1586
|
+
_readVarStringNative: _readVarStringNative,
|
|
1528
1587
|
readVarString: readVarString,
|
|
1529
1588
|
peekVarString: peekVarString,
|
|
1530
1589
|
readFromDataView: readFromDataView,
|
|
@@ -1679,6 +1738,10 @@ exports.StringDecoder = StringDecoder;
|
|
|
1679
1738
|
exports.StringEncoder = StringEncoder;
|
|
1680
1739
|
exports.UintOptRleDecoder = UintOptRleDecoder;
|
|
1681
1740
|
exports.UintOptRleEncoder = UintOptRleEncoder;
|
|
1741
|
+
exports._readVarStringNative = _readVarStringNative;
|
|
1742
|
+
exports._readVarStringPolyfill = _readVarStringPolyfill;
|
|
1743
|
+
exports._writeVarStringNative = _writeVarStringNative;
|
|
1744
|
+
exports._writeVarStringPolyfill = _writeVarStringPolyfill;
|
|
1682
1745
|
exports.buffer = buffer;
|
|
1683
1746
|
exports.clone = clone;
|
|
1684
1747
|
exports.copyUint8Array = copyUint8Array;
|
|
@@ -1723,6 +1786,7 @@ exports.setUint8 = setUint8;
|
|
|
1723
1786
|
exports.skip8 = skip8;
|
|
1724
1787
|
exports.toBase64 = toBase64;
|
|
1725
1788
|
exports.toUint8Array = toUint8Array;
|
|
1789
|
+
exports.verifyLen = verifyLen;
|
|
1726
1790
|
exports.write = write;
|
|
1727
1791
|
exports.writeAny = writeAny;
|
|
1728
1792
|
exports.writeBigInt64 = writeBigInt64;
|
|
@@ -1740,4 +1804,4 @@ exports.writeVarInt = writeVarInt;
|
|
|
1740
1804
|
exports.writeVarString = writeVarString;
|
|
1741
1805
|
exports.writeVarUint = writeVarUint;
|
|
1742
1806
|
exports.writeVarUint8Array = writeVarUint8Array;
|
|
1743
|
-
//# sourceMappingURL=buffer-
|
|
1807
|
+
//# sourceMappingURL=buffer-9c449d1d.cjs.map
|