@ac-kit/format-varint 0.2.7 → 0.3.0

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 (71) hide show
  1. package/CHANGELOG.md +48 -0
  2. package/README.md +10 -0
  3. package/dist/index.d.ts +15 -0
  4. package/dist/index.d.ts.map +1 -1
  5. package/dist/index.js +15 -0
  6. package/dist/index.js.map +1 -1
  7. package/dist/leb128/_leb128.d.ts +22 -0
  8. package/dist/leb128/_leb128.d.ts.map +1 -0
  9. package/dist/leb128/_leb128.js +48 -0
  10. package/dist/leb128/_leb128.js.map +1 -0
  11. package/dist/leb128/decode-leb128.d.ts +40 -0
  12. package/dist/leb128/decode-leb128.d.ts.map +1 -0
  13. package/dist/leb128/decode-leb128.js +61 -0
  14. package/dist/leb128/decode-leb128.js.map +1 -0
  15. package/dist/leb128/encode-big-sleb128.d.ts +10 -0
  16. package/dist/leb128/encode-big-sleb128.d.ts.map +1 -0
  17. package/dist/leb128/encode-big-sleb128.js +25 -0
  18. package/dist/leb128/encode-big-sleb128.js.map +1 -0
  19. package/dist/leb128/encode-big-uleb128.d.ts +11 -0
  20. package/dist/leb128/encode-big-uleb128.d.ts.map +1 -0
  21. package/dist/leb128/encode-big-uleb128.js +29 -0
  22. package/dist/leb128/encode-big-uleb128.js.map +1 -0
  23. package/dist/leb128/encode-sleb128.d.ts +14 -0
  24. package/dist/leb128/encode-sleb128.d.ts.map +1 -0
  25. package/dist/leb128/encode-sleb128.js +20 -0
  26. package/dist/leb128/encode-sleb128.js.map +1 -0
  27. package/dist/leb128/encode-uleb128.d.ts +17 -0
  28. package/dist/leb128/encode-uleb128.d.ts.map +1 -0
  29. package/dist/leb128/encode-uleb128.js +23 -0
  30. package/dist/leb128/encode-uleb128.js.map +1 -0
  31. package/dist/leb128/leb128-codecs.d.ts +23 -0
  32. package/dist/leb128/leb128-codecs.d.ts.map +1 -0
  33. package/dist/leb128/leb128-codecs.js +53 -0
  34. package/dist/leb128/leb128-codecs.js.map +1 -0
  35. package/dist/leb128/leb128-read-options.d.ts +17 -0
  36. package/dist/leb128/leb128-read-options.d.ts.map +1 -0
  37. package/dist/leb128/leb128-read-options.js +2 -0
  38. package/dist/leb128/leb128-read-options.js.map +1 -0
  39. package/dist/leb128/read-big-sleb128.d.ts +20 -0
  40. package/dist/leb128/read-big-sleb128.d.ts.map +1 -0
  41. package/dist/leb128/read-big-sleb128.js +44 -0
  42. package/dist/leb128/read-big-sleb128.js.map +1 -0
  43. package/dist/leb128/read-big-uleb128.d.ts +19 -0
  44. package/dist/leb128/read-big-uleb128.d.ts.map +1 -0
  45. package/dist/leb128/read-big-uleb128.js +39 -0
  46. package/dist/leb128/read-big-uleb128.js.map +1 -0
  47. package/dist/leb128/read-sleb128.d.ts +26 -0
  48. package/dist/leb128/read-sleb128.d.ts.map +1 -0
  49. package/dist/leb128/read-sleb128.js +68 -0
  50. package/dist/leb128/read-sleb128.js.map +1 -0
  51. package/dist/leb128/read-uleb128.d.ts +25 -0
  52. package/dist/leb128/read-uleb128.d.ts.map +1 -0
  53. package/dist/leb128/read-uleb128.js +52 -0
  54. package/dist/leb128/read-uleb128.js.map +1 -0
  55. package/dist/leb128/sleb128-byte-length.d.ts +11 -0
  56. package/dist/leb128/sleb128-byte-length.d.ts.map +1 -0
  57. package/dist/leb128/sleb128-byte-length.js +25 -0
  58. package/dist/leb128/sleb128-byte-length.js.map +1 -0
  59. package/dist/leb128/uleb128-byte-length.d.ts +11 -0
  60. package/dist/leb128/uleb128-byte-length.d.ts.map +1 -0
  61. package/dist/leb128/uleb128-byte-length.js +24 -0
  62. package/dist/leb128/uleb128-byte-length.js.map +1 -0
  63. package/dist/leb128/write-sleb128.d.ts +13 -0
  64. package/dist/leb128/write-sleb128.d.ts.map +1 -0
  65. package/dist/leb128/write-sleb128.js +31 -0
  66. package/dist/leb128/write-sleb128.js.map +1 -0
  67. package/dist/leb128/write-uleb128.d.ts +13 -0
  68. package/dist/leb128/write-uleb128.d.ts.map +1 -0
  69. package/dist/leb128/write-uleb128.js +30 -0
  70. package/dist/leb128/write-uleb128.js.map +1 -0
  71. package/package.json +5 -4
package/CHANGELOG.md CHANGED
@@ -1,5 +1,53 @@
1
1
  # @ac-kit/format-varint
2
2
 
3
+ ## 0.3.0
4
+
5
+ ### Minor Changes
6
+
7
+ - 5c203e7: LEB128, unsigned and signed: `readUleb128` and `readSleb128` read from a
8
+ `ByteReader`, accepting the padded forms DWARF and WebAssembly allow unless
9
+ `canonical` is set, and bounded by `maxByteLength` (5 bytes for WebAssembly's
10
+ `u32`); `encodeUleb128`, `encodeSleb128`, `writeUleb128`, `writeSleb128`,
11
+ `uleb128ByteLength` and `sleb128ByteLength` write the shortest form;
12
+ `decodeUleb128` and `decodeSleb128` take a buffer holding one value; and
13
+ `uleb128Decoder`, `sleb128Decoder` with their encoders stream. Each has a
14
+ `bigint` twin (`readBigUleb128`, `encodeBigSleb128`, …) for values beyond the
15
+ safe integers, which the `number` forms report as a `RangeError`.
16
+
17
+ ### Patch Changes
18
+
19
+ - Updated dependencies [5c203e7]
20
+ - Updated dependencies [5c203e7]
21
+ - Updated dependencies [5c203e7]
22
+ - Updated dependencies [5c203e7]
23
+ - @ac-kit/core@0.14.0
24
+ - @ac-kit/format-core@0.5.1
25
+
26
+ ## 0.2.8
27
+
28
+ ### Patch Changes
29
+
30
+ - Updated dependencies [0b4fe43]
31
+ - Updated dependencies [0b4fe43]
32
+ - Updated dependencies [0b4fe43]
33
+ - Updated dependencies [0b4fe43]
34
+ - Updated dependencies [0b4fe43]
35
+ - Updated dependencies [0b4fe43]
36
+ - Updated dependencies [0b4fe43]
37
+ - Updated dependencies [0b4fe43]
38
+ - Updated dependencies [0b4fe43]
39
+ - Updated dependencies [0b4fe43]
40
+ - Updated dependencies [0b4fe43]
41
+ - Updated dependencies [0b4fe43]
42
+ - Updated dependencies [0b4fe43]
43
+ - Updated dependencies [0b4fe43]
44
+ - Updated dependencies [0b4fe43]
45
+ - Updated dependencies [0b4fe43]
46
+ - Updated dependencies [0b4fe43]
47
+ - Updated dependencies [0b4fe43]
48
+ - @ac-kit/core@0.13.0
49
+ - @ac-kit/format-core@0.5.0
50
+
3
51
  ## 0.2.7
4
52
 
5
53
  ### Patch Changes
package/README.md CHANGED
@@ -23,6 +23,16 @@ interchangeable: LEB128 puts the _least_ significant group first, and source
23
23
  maps use a base-64 alphabet with the sign in the low bit. Every export here
24
24
  names its member, so there is no ambiguous `encodeVarint`.
25
25
 
26
+ **LEB128** is base-128, least significant group first: `uleb128` for unsigned
27
+ values (DWARF's `ULEB128`, WebAssembly's `uN`, Protocol Buffers varints),
28
+ `sleb128` for two's complement with the sign in bit 6 of the final group
29
+ (DWARF's `SLEB128`, WebAssembly's `sN`). It has the same shapes as VLQ —
30
+ `readUleb128`, `encodeUleb128`, `writeUleb128`, `uleb128ByteLength`,
31
+ `decodeUleb128`, `uleb128Decoder`, their `sleb128` twins and `Big` forms. The
32
+ readers accept the padded forms DWARF and WebAssembly allow; `canonical: true`
33
+ rejects them, and `maxByteLength` bounds a value as WebAssembly does (5 bytes
34
+ for a 32-bit integer).
35
+
26
36
  **QUIC** variable-length integers (RFC 9000 §16) have no continuation bit: the
27
37
  two high bits of the first byte give the length, 1, 2, 4 or 8 bytes, and the
28
38
  value follows big-endian. QUIC, HTTP/3 and HTTP datagram capsules use them.
package/dist/index.d.ts CHANGED
@@ -1,4 +1,19 @@
1
1
  export * from "./errors.js";
2
+ export * from "./leb128/decode-leb128.js";
3
+ export * from "./leb128/encode-big-sleb128.js";
4
+ export * from "./leb128/encode-big-uleb128.js";
5
+ export * from "./leb128/encode-sleb128.js";
6
+ export * from "./leb128/encode-uleb128.js";
7
+ export * from "./leb128/leb128-codecs.js";
8
+ export * from "./leb128/leb128-read-options.js";
9
+ export * from "./leb128/read-big-sleb128.js";
10
+ export * from "./leb128/read-big-uleb128.js";
11
+ export * from "./leb128/read-sleb128.js";
12
+ export * from "./leb128/read-uleb128.js";
13
+ export * from "./leb128/sleb128-byte-length.js";
14
+ export * from "./leb128/uleb128-byte-length.js";
15
+ export * from "./leb128/write-sleb128.js";
16
+ export * from "./leb128/write-uleb128.js";
2
17
  export * from "./quic/encode-quic-varint.js";
3
18
  export * from "./quic/quic-varint-byte-length.js";
4
19
  export * from "./quic/read-big-quic-varint.js";
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,aAAa,CAAC;AAC5B,cAAc,8BAA8B,CAAC;AAC7C,cAAc,mCAAmC,CAAC;AAClD,cAAc,gCAAgC,CAAC;AAC/C,cAAc,4BAA4B,CAAC;AAC3C,cAAc,6BAA6B,CAAC;AAC5C,cAAc,0BAA0B,CAAC;AACzC,cAAc,0BAA0B,CAAC;AACzC,cAAc,yBAAyB,CAAC;AACxC,cAAc,qBAAqB,CAAC;AACpC,cAAc,yBAAyB,CAAC;AACxC,cAAc,qBAAqB,CAAC;AACpC,cAAc,uBAAuB,CAAC;AACtC,cAAc,mBAAmB,CAAC;AAClC,cAAc,0BAA0B,CAAC;AACzC,cAAc,sBAAsB,CAAC;AACrC,cAAc,sBAAsB,CAAC;AACrC,cAAc,oBAAoB,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,aAAa,CAAC;AAC5B,cAAc,2BAA2B,CAAC;AAC1C,cAAc,gCAAgC,CAAC;AAC/C,cAAc,gCAAgC,CAAC;AAC/C,cAAc,4BAA4B,CAAC;AAC3C,cAAc,4BAA4B,CAAC;AAC3C,cAAc,2BAA2B,CAAC;AAC1C,cAAc,iCAAiC,CAAC;AAChD,cAAc,8BAA8B,CAAC;AAC7C,cAAc,8BAA8B,CAAC;AAC7C,cAAc,0BAA0B,CAAC;AACzC,cAAc,0BAA0B,CAAC;AACzC,cAAc,iCAAiC,CAAC;AAChD,cAAc,iCAAiC,CAAC;AAChD,cAAc,2BAA2B,CAAC;AAC1C,cAAc,2BAA2B,CAAC;AAC1C,cAAc,8BAA8B,CAAC;AAC7C,cAAc,mCAAmC,CAAC;AAClD,cAAc,gCAAgC,CAAC;AAC/C,cAAc,4BAA4B,CAAC;AAC3C,cAAc,6BAA6B,CAAC;AAC5C,cAAc,0BAA0B,CAAC;AACzC,cAAc,0BAA0B,CAAC;AACzC,cAAc,yBAAyB,CAAC;AACxC,cAAc,qBAAqB,CAAC;AACpC,cAAc,yBAAyB,CAAC;AACxC,cAAc,qBAAqB,CAAC;AACpC,cAAc,uBAAuB,CAAC;AACtC,cAAc,mBAAmB,CAAC;AAClC,cAAc,0BAA0B,CAAC;AACzC,cAAc,sBAAsB,CAAC;AACrC,cAAc,sBAAsB,CAAC;AACrC,cAAc,oBAAoB,CAAC"}
package/dist/index.js CHANGED
@@ -1,4 +1,19 @@
1
1
  export * from "./errors.js";
2
+ export * from "./leb128/decode-leb128.js";
3
+ export * from "./leb128/encode-big-sleb128.js";
4
+ export * from "./leb128/encode-big-uleb128.js";
5
+ export * from "./leb128/encode-sleb128.js";
6
+ export * from "./leb128/encode-uleb128.js";
7
+ export * from "./leb128/leb128-codecs.js";
8
+ export * from "./leb128/leb128-read-options.js";
9
+ export * from "./leb128/read-big-sleb128.js";
10
+ export * from "./leb128/read-big-uleb128.js";
11
+ export * from "./leb128/read-sleb128.js";
12
+ export * from "./leb128/read-uleb128.js";
13
+ export * from "./leb128/sleb128-byte-length.js";
14
+ export * from "./leb128/uleb128-byte-length.js";
15
+ export * from "./leb128/write-sleb128.js";
16
+ export * from "./leb128/write-uleb128.js";
2
17
  export * from "./quic/encode-quic-varint.js";
3
18
  export * from "./quic/quic-varint-byte-length.js";
4
19
  export * from "./quic/read-big-quic-varint.js";
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,aAAa,CAAC;AAC5B,cAAc,8BAA8B,CAAC;AAC7C,cAAc,mCAAmC,CAAC;AAClD,cAAc,gCAAgC,CAAC;AAC/C,cAAc,4BAA4B,CAAC;AAC3C,cAAc,6BAA6B,CAAC;AAC5C,cAAc,0BAA0B,CAAC;AACzC,cAAc,0BAA0B,CAAC;AACzC,cAAc,yBAAyB,CAAC;AACxC,cAAc,qBAAqB,CAAC;AACpC,cAAc,yBAAyB,CAAC;AACxC,cAAc,qBAAqB,CAAC;AACpC,cAAc,uBAAuB,CAAC;AACtC,cAAc,mBAAmB,CAAC;AAClC,cAAc,0BAA0B,CAAC;AACzC,cAAc,sBAAsB,CAAC;AACrC,cAAc,sBAAsB,CAAC;AACrC,cAAc,oBAAoB,CAAC"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,aAAa,CAAC;AAC5B,cAAc,2BAA2B,CAAC;AAC1C,cAAc,gCAAgC,CAAC;AAC/C,cAAc,gCAAgC,CAAC;AAC/C,cAAc,4BAA4B,CAAC;AAC3C,cAAc,4BAA4B,CAAC;AAC3C,cAAc,2BAA2B,CAAC;AAC1C,cAAc,iCAAiC,CAAC;AAChD,cAAc,8BAA8B,CAAC;AAC7C,cAAc,8BAA8B,CAAC;AAC7C,cAAc,0BAA0B,CAAC;AACzC,cAAc,0BAA0B,CAAC;AACzC,cAAc,iCAAiC,CAAC;AAChD,cAAc,iCAAiC,CAAC;AAChD,cAAc,2BAA2B,CAAC;AAC1C,cAAc,2BAA2B,CAAC;AAC1C,cAAc,8BAA8B,CAAC;AAC7C,cAAc,mCAAmC,CAAC;AAClD,cAAc,gCAAgC,CAAC;AAC/C,cAAc,4BAA4B,CAAC;AAC3C,cAAc,6BAA6B,CAAC;AAC5C,cAAc,0BAA0B,CAAC;AACzC,cAAc,0BAA0B,CAAC;AACzC,cAAc,yBAAyB,CAAC;AACxC,cAAc,qBAAqB,CAAC;AACpC,cAAc,yBAAyB,CAAC;AACxC,cAAc,qBAAqB,CAAC;AACpC,cAAc,uBAAuB,CAAC;AACtC,cAAc,mBAAmB,CAAC;AAClC,cAAc,0BAA0B,CAAC;AACzC,cAAc,sBAAsB,CAAC;AACrC,cAAc,sBAAsB,CAAC;AACrC,cAAc,oBAAoB,CAAC"}
@@ -0,0 +1,22 @@
1
+ import { type ByteReader } from "@ac-kit/core";
2
+ import { VarintMalformedError } from "../errors.js";
3
+ import type { Leb128ReadOptions } from "./leb128-read-options.js";
4
+ /** The sign bit of a final `sleb128` group. */
5
+ export declare const SIGN_BIT_ = 64;
6
+ /** `2 ** 49`, the weight of the eighth group: seven groups fill 49 bits exactly. */
7
+ export declare const EIGHTH_GROUP_WEIGHT_: number;
8
+ /** The byte bound `options` sets, `Infinity` when none. */
9
+ export declare function maxByteLength_(caller: string, options: Leb128ReadOptions | undefined): number;
10
+ /**
11
+ * Reads the next byte of a value of which `count` bytes are read, after the
12
+ * checks every reader makes.
13
+ */
14
+ export declare function readGroupByte_(caller: string, reader: ByteReader, count: number, maxByteLength: number): number;
15
+ export declare function isLastByte_(byte: number): boolean;
16
+ /**
17
+ * Whether the final group of a signed encoding only repeats the sign of the
18
+ * group before it, which a shorter encoding would carry.
19
+ */
20
+ export declare function isOverlongSigned_(last: number, previous: number): boolean;
21
+ export declare function overlong_(caller: string): VarintMalformedError;
22
+ //# sourceMappingURL=_leb128.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"_leb128.d.ts","sourceRoot":"","sources":["../../src/leb128/_leb128.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,UAAU,EAAiB,MAAM,cAAc,CAAC;AAG9D,OAAO,EAAyB,oBAAoB,EAAE,MAAM,cAAc,CAAC;AAC3E,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,0BAA0B,CAAC;AAElE,+CAA+C;AAC/C,eAAO,MAAM,SAAS,KAAO,CAAC;AAE9B,oFAAoF;AACpF,eAAO,MAAM,oBAAoB,QAAU,CAAC;AAE5C,2DAA2D;AAC3D,wBAAgB,cAAc,CAC7B,MAAM,EAAE,MAAM,EACd,OAAO,EAAE,iBAAiB,GAAG,SAAS,GACpC,MAAM,CAWR;AAED;;;GAGG;AACH,wBAAgB,cAAc,CAC7B,MAAM,EAAE,MAAM,EACd,MAAM,EAAE,UAAU,EAClB,KAAK,EAAE,MAAM,EACb,aAAa,EAAE,MAAM,GACnB,MAAM,CAcR;AAED,wBAAgB,WAAW,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAEjD;AAED;;;GAGG;AACH,wBAAgB,iBAAiB,CAAC,IAAI,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,GAAG,OAAO,CAKzE;AAED,wBAAgB,SAAS,CAAC,MAAM,EAAE,MAAM,GAAG,oBAAoB,CAI9D"}
@@ -0,0 +1,48 @@
1
+ import { describeValue } from "@ac-kit/core";
2
+ import { CONTINUATION_BIT } from "../_base128.js";
3
+ import { VarintIncompleteError, VarintMalformedError } from "../errors.js";
4
+ /** The sign bit of a final `sleb128` group. */
5
+ export const SIGN_BIT_ = 0x40;
6
+ /** `2 ** 49`, the weight of the eighth group: seven groups fill 49 bits exactly. */
7
+ export const EIGHTH_GROUP_WEIGHT_ = 2 ** 49;
8
+ /** The byte bound `options` sets, `Infinity` when none. */
9
+ export function maxByteLength_(caller, options) {
10
+ const maxByteLength = options?.maxByteLength;
11
+ if (maxByteLength === undefined) {
12
+ return Number.POSITIVE_INFINITY;
13
+ }
14
+ if (!Number.isSafeInteger(maxByteLength) || maxByteLength < 1) {
15
+ throw new RangeError(`${caller}: maxByteLength must be a positive integer, got ${describeValue(maxByteLength)}`);
16
+ }
17
+ return maxByteLength;
18
+ }
19
+ /**
20
+ * Reads the next byte of a value of which `count` bytes are read, after the
21
+ * checks every reader makes.
22
+ */
23
+ export function readGroupByte_(caller, reader, count, maxByteLength) {
24
+ if (count === maxByteLength) {
25
+ throw new VarintMalformedError(`${caller}: continuation bit set on byte ${count}, the last one maxByteLength allows`);
26
+ }
27
+ if (reader.atEnd) {
28
+ throw new VarintIncompleteError(count === 0
29
+ ? `${caller}: no bytes to read`
30
+ : `${caller}: continuation bit set on the last available byte`);
31
+ }
32
+ return reader.readByte();
33
+ }
34
+ export function isLastByte_(byte) {
35
+ return (byte & CONTINUATION_BIT) === 0;
36
+ }
37
+ /**
38
+ * Whether the final group of a signed encoding only repeats the sign of the
39
+ * group before it, which a shorter encoding would carry.
40
+ */
41
+ export function isOverlongSigned_(last, previous) {
42
+ return ((last === 0x00 && (previous & SIGN_BIT_) === 0) ||
43
+ (last === 0x7f && (previous & SIGN_BIT_) !== 0));
44
+ }
45
+ export function overlong_(caller) {
46
+ return new VarintMalformedError(`${caller}: overlong encoding, the final group adds nothing`);
47
+ }
48
+ //# sourceMappingURL=_leb128.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"_leb128.js","sourceRoot":"","sources":["../../src/leb128/_leb128.ts"],"names":[],"mappings":"AAAA,OAAO,EAAmB,aAAa,EAAE,MAAM,cAAc,CAAC;AAE9D,OAAO,EAAE,gBAAgB,EAAE,MAAM,gBAAgB,CAAC;AAClD,OAAO,EAAE,qBAAqB,EAAE,oBAAoB,EAAE,MAAM,cAAc,CAAC;AAG3E,+CAA+C;AAC/C,MAAM,CAAC,MAAM,SAAS,GAAG,IAAI,CAAC;AAE9B,oFAAoF;AACpF,MAAM,CAAC,MAAM,oBAAoB,GAAG,CAAC,IAAI,EAAE,CAAC;AAE5C,2DAA2D;AAC3D,MAAM,UAAU,cAAc,CAC7B,MAAc,EACd,OAAsC;IAEtC,MAAM,aAAa,GAAG,OAAO,EAAE,aAAa,CAAC;IAC7C,IAAI,aAAa,KAAK,SAAS,EAAE,CAAC;QACjC,OAAO,MAAM,CAAC,iBAAiB,CAAC;IACjC,CAAC;IACD,IAAI,CAAC,MAAM,CAAC,aAAa,CAAC,aAAa,CAAC,IAAI,aAAa,GAAG,CAAC,EAAE,CAAC;QAC/D,MAAM,IAAI,UAAU,CACnB,GAAG,MAAM,mDAAmD,aAAa,CAAC,aAAa,CAAC,EAAE,CAC1F,CAAC;IACH,CAAC;IACD,OAAO,aAAa,CAAC;AACtB,CAAC;AAED;;;GAGG;AACH,MAAM,UAAU,cAAc,CAC7B,MAAc,EACd,MAAkB,EAClB,KAAa,EACb,aAAqB;IAErB,IAAI,KAAK,KAAK,aAAa,EAAE,CAAC;QAC7B,MAAM,IAAI,oBAAoB,CAC7B,GAAG,MAAM,kCAAkC,KAAK,qCAAqC,CACrF,CAAC;IACH,CAAC;IACD,IAAI,MAAM,CAAC,KAAK,EAAE,CAAC;QAClB,MAAM,IAAI,qBAAqB,CAC9B,KAAK,KAAK,CAAC;YACV,CAAC,CAAC,GAAG,MAAM,oBAAoB;YAC/B,CAAC,CAAC,GAAG,MAAM,mDAAmD,CAC/D,CAAC;IACH,CAAC;IACD,OAAO,MAAM,CAAC,QAAQ,EAAE,CAAC;AAC1B,CAAC;AAED,MAAM,UAAU,WAAW,CAAC,IAAY;IACvC,OAAO,CAAC,IAAI,GAAG,gBAAgB,CAAC,KAAK,CAAC,CAAC;AACxC,CAAC;AAED;;;GAGG;AACH,MAAM,UAAU,iBAAiB,CAAC,IAAY,EAAE,QAAgB;IAC/D,OAAO,CACN,CAAC,IAAI,KAAK,IAAI,IAAI,CAAC,QAAQ,GAAG,SAAS,CAAC,KAAK,CAAC,CAAC;QAC/C,CAAC,IAAI,KAAK,IAAI,IAAI,CAAC,QAAQ,GAAG,SAAS,CAAC,KAAK,CAAC,CAAC,CAC/C,CAAC;AACH,CAAC;AAED,MAAM,UAAU,SAAS,CAAC,MAAc;IACvC,OAAO,IAAI,oBAAoB,CAC9B,GAAG,MAAM,mDAAmD,CAC5D,CAAC;AACH,CAAC"}
@@ -0,0 +1,40 @@
1
+ import type { Leb128ReadOptions } from "./leb128-read-options.js";
2
+ /**
3
+ * Decodes a buffer holding exactly one unsigned LEB128 — the one-shot
4
+ * counterpart of {@link readUleb128}, which reads a run of values.
5
+ *
6
+ * @throws {VarintIncompleteError} When the encoding is truncated.
7
+ * @throws {VarintMalformedError} When bytes follow the value, or as
8
+ * {@link readUleb128} does.
9
+ * @throws {RangeError} As {@link readUleb128} does.
10
+ */
11
+ export declare function decodeUleb128(bytes: Uint8Array, options?: Leb128ReadOptions): number;
12
+ /**
13
+ * Decodes a buffer holding exactly one signed LEB128 — the one-shot counterpart
14
+ * of {@link readSleb128}.
15
+ *
16
+ * @throws {VarintIncompleteError} When the encoding is truncated.
17
+ * @throws {VarintMalformedError} When bytes follow the value, or as
18
+ * {@link readSleb128} does.
19
+ * @throws {RangeError} As {@link readSleb128} does.
20
+ */
21
+ export declare function decodeSleb128(bytes: Uint8Array, options?: Leb128ReadOptions): number;
22
+ /**
23
+ * Decodes a buffer holding exactly one unsigned LEB128 as a `bigint` — the
24
+ * one-shot counterpart of {@link readBigUleb128}.
25
+ *
26
+ * @throws {VarintIncompleteError} When the encoding is truncated.
27
+ * @throws {VarintMalformedError} When bytes follow the value, or as
28
+ * {@link readBigUleb128} does.
29
+ */
30
+ export declare function decodeBigUleb128(bytes: Uint8Array, options?: Leb128ReadOptions): bigint;
31
+ /**
32
+ * Decodes a buffer holding exactly one signed LEB128 as a `bigint` — the
33
+ * one-shot counterpart of {@link readBigSleb128}.
34
+ *
35
+ * @throws {VarintIncompleteError} When the encoding is truncated.
36
+ * @throws {VarintMalformedError} When bytes follow the value, or as
37
+ * {@link readBigSleb128} does.
38
+ */
39
+ export declare function decodeBigSleb128(bytes: Uint8Array, options?: Leb128ReadOptions): bigint;
40
+ //# sourceMappingURL=decode-leb128.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"decode-leb128.d.ts","sourceRoot":"","sources":["../../src/leb128/decode-leb128.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,0BAA0B,CAAC;AAsBlE;;;;;;;;GAQG;AACH,wBAAgB,aAAa,CAC5B,KAAK,EAAE,UAAU,EACjB,OAAO,CAAC,EAAE,iBAAiB,GACzB,MAAM,CAER;AAED;;;;;;;;GAQG;AACH,wBAAgB,aAAa,CAC5B,KAAK,EAAE,UAAU,EACjB,OAAO,CAAC,EAAE,iBAAiB,GACzB,MAAM,CAER;AAED;;;;;;;GAOG;AACH,wBAAgB,gBAAgB,CAC/B,KAAK,EAAE,UAAU,EACjB,OAAO,CAAC,EAAE,iBAAiB,GACzB,MAAM,CAER;AAED;;;;;;;GAOG;AACH,wBAAgB,gBAAgB,CAC/B,KAAK,EAAE,UAAU,EACjB,OAAO,CAAC,EAAE,iBAAiB,GACzB,MAAM,CAER"}
@@ -0,0 +1,61 @@
1
+ import { ByteReader } from "@ac-kit/core";
2
+ import { VarintMalformedError } from "../errors.js";
3
+ import { readBigSleb128 } from "./read-big-sleb128.js";
4
+ import { readBigUleb128 } from "./read-big-uleb128.js";
5
+ import { readSleb128 } from "./read-sleb128.js";
6
+ import { readUleb128 } from "./read-uleb128.js";
7
+ function decodeWhole_(caller, bytes, options, read) {
8
+ const reader = new ByteReader(bytes);
9
+ const value = read(reader, options);
10
+ if (!reader.atEnd) {
11
+ throw new VarintMalformedError(`${caller}: ${reader.remaining} byte(s) left after a complete value`);
12
+ }
13
+ return value;
14
+ }
15
+ /**
16
+ * Decodes a buffer holding exactly one unsigned LEB128 — the one-shot
17
+ * counterpart of {@link readUleb128}, which reads a run of values.
18
+ *
19
+ * @throws {VarintIncompleteError} When the encoding is truncated.
20
+ * @throws {VarintMalformedError} When bytes follow the value, or as
21
+ * {@link readUleb128} does.
22
+ * @throws {RangeError} As {@link readUleb128} does.
23
+ */
24
+ export function decodeUleb128(bytes, options) {
25
+ return decodeWhole_("decodeUleb128", bytes, options, readUleb128);
26
+ }
27
+ /**
28
+ * Decodes a buffer holding exactly one signed LEB128 — the one-shot counterpart
29
+ * of {@link readSleb128}.
30
+ *
31
+ * @throws {VarintIncompleteError} When the encoding is truncated.
32
+ * @throws {VarintMalformedError} When bytes follow the value, or as
33
+ * {@link readSleb128} does.
34
+ * @throws {RangeError} As {@link readSleb128} does.
35
+ */
36
+ export function decodeSleb128(bytes, options) {
37
+ return decodeWhole_("decodeSleb128", bytes, options, readSleb128);
38
+ }
39
+ /**
40
+ * Decodes a buffer holding exactly one unsigned LEB128 as a `bigint` — the
41
+ * one-shot counterpart of {@link readBigUleb128}.
42
+ *
43
+ * @throws {VarintIncompleteError} When the encoding is truncated.
44
+ * @throws {VarintMalformedError} When bytes follow the value, or as
45
+ * {@link readBigUleb128} does.
46
+ */
47
+ export function decodeBigUleb128(bytes, options) {
48
+ return decodeWhole_("decodeBigUleb128", bytes, options, readBigUleb128);
49
+ }
50
+ /**
51
+ * Decodes a buffer holding exactly one signed LEB128 as a `bigint` — the
52
+ * one-shot counterpart of {@link readBigSleb128}.
53
+ *
54
+ * @throws {VarintIncompleteError} When the encoding is truncated.
55
+ * @throws {VarintMalformedError} When bytes follow the value, or as
56
+ * {@link readBigSleb128} does.
57
+ */
58
+ export function decodeBigSleb128(bytes, options) {
59
+ return decodeWhole_("decodeBigSleb128", bytes, options, readBigSleb128);
60
+ }
61
+ //# sourceMappingURL=decode-leb128.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"decode-leb128.js","sourceRoot":"","sources":["../../src/leb128/decode-leb128.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAE1C,OAAO,EAAE,oBAAoB,EAAE,MAAM,cAAc,CAAC;AAEpD,OAAO,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAC;AACvD,OAAO,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAC;AACvD,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAChD,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAEhD,SAAS,YAAY,CACpB,MAAc,EACd,KAAiB,EACjB,OAAsC,EACtC,IAA4D;IAE5D,MAAM,MAAM,GAAG,IAAI,UAAU,CAAC,KAAK,CAAC,CAAC;IACrC,MAAM,KAAK,GAAG,IAAI,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IACpC,IAAI,CAAC,MAAM,CAAC,KAAK,EAAE,CAAC;QACnB,MAAM,IAAI,oBAAoB,CAC7B,GAAG,MAAM,KAAK,MAAM,CAAC,SAAS,sCAAsC,CACpE,CAAC;IACH,CAAC;IACD,OAAO,KAAK,CAAC;AACd,CAAC;AAED;;;;;;;;GAQG;AACH,MAAM,UAAU,aAAa,CAC5B,KAAiB,EACjB,OAA2B;IAE3B,OAAO,YAAY,CAAC,eAAe,EAAE,KAAK,EAAE,OAAO,EAAE,WAAW,CAAC,CAAC;AACnE,CAAC;AAED;;;;;;;;GAQG;AACH,MAAM,UAAU,aAAa,CAC5B,KAAiB,EACjB,OAA2B;IAE3B,OAAO,YAAY,CAAC,eAAe,EAAE,KAAK,EAAE,OAAO,EAAE,WAAW,CAAC,CAAC;AACnE,CAAC;AAED;;;;;;;GAOG;AACH,MAAM,UAAU,gBAAgB,CAC/B,KAAiB,EACjB,OAA2B;IAE3B,OAAO,YAAY,CAAC,kBAAkB,EAAE,KAAK,EAAE,OAAO,EAAE,cAAc,CAAC,CAAC;AACzE,CAAC;AAED;;;;;;;GAOG;AACH,MAAM,UAAU,gBAAgB,CAC/B,KAAiB,EACjB,OAA2B;IAE3B,OAAO,YAAY,CAAC,kBAAkB,EAAE,KAAK,EAAE,OAAO,EAAE,cAAc,CAAC,CAAC;AACzE,CAAC"}
@@ -0,0 +1,10 @@
1
+ /**
2
+ * Encodes a `bigint` as a signed LEB128 in the fewest bytes — the unbounded
3
+ * counterpart of {@link encodeSleb128}, for WebAssembly's `s64`.
4
+ *
5
+ * Time complexity: O(log₁₂₈ |value|).
6
+ *
7
+ * @returns A fresh buffer holding the encoding, never empty.
8
+ */
9
+ export declare function encodeBigSleb128(value: bigint): Uint8Array<ArrayBuffer>;
10
+ //# sourceMappingURL=encode-big-sleb128.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"encode-big-sleb128.d.ts","sourceRoot":"","sources":["../../src/leb128/encode-big-sleb128.ts"],"names":[],"mappings":"AAMA;;;;;;;GAOG;AACH,wBAAgB,gBAAgB,CAAC,KAAK,EAAE,MAAM,GAAG,UAAU,CAAC,WAAW,CAAC,CAevE"}
@@ -0,0 +1,25 @@
1
+ import { CONTINUATION_BIT, PAYLOAD_BITS, PAYLOAD_MASK_BIG, } from "../_base128.js";
2
+ /**
3
+ * Encodes a `bigint` as a signed LEB128 in the fewest bytes — the unbounded
4
+ * counterpart of {@link encodeSleb128}, for WebAssembly's `s64`.
5
+ *
6
+ * Time complexity: O(log₁₂₈ |value|).
7
+ *
8
+ * @returns A fresh buffer holding the encoding, never empty.
9
+ */
10
+ export function encodeBigSleb128(value) {
11
+ const groups = [];
12
+ let remaining = value;
13
+ for (;;) {
14
+ const group = Number(remaining & PAYLOAD_MASK_BIG);
15
+ // `>>` on a bigint is arithmetic, so a negative value tends to -1.
16
+ remaining >>= PAYLOAD_BITS;
17
+ const isDone = (remaining === 0n && (group & 0x40) === 0) ||
18
+ (remaining === -1n && (group & 0x40) !== 0);
19
+ groups.push(isDone ? group : group | CONTINUATION_BIT);
20
+ if (isDone) {
21
+ return Uint8Array.from(groups);
22
+ }
23
+ }
24
+ }
25
+ //# sourceMappingURL=encode-big-sleb128.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"encode-big-sleb128.js","sourceRoot":"","sources":["../../src/leb128/encode-big-sleb128.ts"],"names":[],"mappings":"AAAA,OAAO,EACN,gBAAgB,EAChB,YAAY,EACZ,gBAAgB,GAChB,MAAM,gBAAgB,CAAC;AAExB;;;;;;;GAOG;AACH,MAAM,UAAU,gBAAgB,CAAC,KAAa;IAC7C,MAAM,MAAM,GAAa,EAAE,CAAC;IAC5B,IAAI,SAAS,GAAG,KAAK,CAAC;IACtB,SAAS,CAAC;QACT,MAAM,KAAK,GAAG,MAAM,CAAC,SAAS,GAAG,gBAAgB,CAAC,CAAC;QACnD,mEAAmE;QACnE,SAAS,KAAK,YAAY,CAAC;QAC3B,MAAM,MAAM,GACX,CAAC,SAAS,KAAK,EAAE,IAAI,CAAC,KAAK,GAAG,IAAI,CAAC,KAAK,CAAC,CAAC;YAC1C,CAAC,SAAS,KAAK,CAAC,EAAE,IAAI,CAAC,KAAK,GAAG,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC;QAC7C,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,KAAK,GAAG,gBAAgB,CAAC,CAAC;QACvD,IAAI,MAAM,EAAE,CAAC;YACZ,OAAO,UAAU,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;QAChC,CAAC;IACF,CAAC;AACF,CAAC"}
@@ -0,0 +1,11 @@
1
+ /**
2
+ * Encodes a non-negative `bigint` as an unsigned LEB128 in the fewest bytes —
3
+ * the unbounded counterpart of {@link encodeUleb128}, for WebAssembly's `u64`.
4
+ *
5
+ * Time complexity: O(log₁₂₈ value).
6
+ *
7
+ * @returns A fresh buffer holding the encoding, never empty.
8
+ * @throws {RangeError} When `value` is negative.
9
+ */
10
+ export declare function encodeBigUleb128(value: bigint): Uint8Array<ArrayBuffer>;
11
+ //# sourceMappingURL=encode-big-uleb128.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"encode-big-uleb128.d.ts","sourceRoot":"","sources":["../../src/leb128/encode-big-uleb128.ts"],"names":[],"mappings":"AASA;;;;;;;;GAQG;AACH,wBAAgB,gBAAgB,CAAC,KAAK,EAAE,MAAM,GAAG,UAAU,CAAC,WAAW,CAAC,CAsBvE"}
@@ -0,0 +1,29 @@
1
+ import { describeValue } from "@ac-kit/core";
2
+ import { CONTINUATION_BIT, PAYLOAD_BITS, PAYLOAD_MASK_BIG, RADIX_BIG, } from "../_base128.js";
3
+ /**
4
+ * Encodes a non-negative `bigint` as an unsigned LEB128 in the fewest bytes —
5
+ * the unbounded counterpart of {@link encodeUleb128}, for WebAssembly's `u64`.
6
+ *
7
+ * Time complexity: O(log₁₂₈ value).
8
+ *
9
+ * @returns A fresh buffer holding the encoding, never empty.
10
+ * @throws {RangeError} When `value` is negative.
11
+ */
12
+ export function encodeBigUleb128(value) {
13
+ if (value < 0n) {
14
+ throw new RangeError(`encodeBigUleb128: value must be non-negative, got ${describeValue(value)}`);
15
+ }
16
+ let length = 1;
17
+ for (let remaining = value; remaining >= RADIX_BIG; remaining >>= PAYLOAD_BITS) {
18
+ length++;
19
+ }
20
+ const out = new Uint8Array(length);
21
+ let remaining = value;
22
+ for (let index = 0; index < length; index++) {
23
+ const group = Number(remaining & PAYLOAD_MASK_BIG);
24
+ remaining >>= PAYLOAD_BITS;
25
+ out[index] = index === length - 1 ? group : group | CONTINUATION_BIT;
26
+ }
27
+ return out;
28
+ }
29
+ //# sourceMappingURL=encode-big-uleb128.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"encode-big-uleb128.js","sourceRoot":"","sources":["../../src/leb128/encode-big-uleb128.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,cAAc,CAAC;AAE7C,OAAO,EACN,gBAAgB,EAChB,YAAY,EACZ,gBAAgB,EAChB,SAAS,GACT,MAAM,gBAAgB,CAAC;AAExB;;;;;;;;GAQG;AACH,MAAM,UAAU,gBAAgB,CAAC,KAAa;IAC7C,IAAI,KAAK,GAAG,EAAE,EAAE,CAAC;QAChB,MAAM,IAAI,UAAU,CACnB,qDAAqD,aAAa,CAAC,KAAK,CAAC,EAAE,CAC3E,CAAC;IACH,CAAC;IACD,IAAI,MAAM,GAAG,CAAC,CAAC;IACf,KACC,IAAI,SAAS,GAAG,KAAK,EACrB,SAAS,IAAI,SAAS,EACtB,SAAS,KAAK,YAAY,EACzB,CAAC;QACF,MAAM,EAAE,CAAC;IACV,CAAC;IACD,MAAM,GAAG,GAAG,IAAI,UAAU,CAAC,MAAM,CAAC,CAAC;IACnC,IAAI,SAAS,GAAG,KAAK,CAAC;IACtB,KAAK,IAAI,KAAK,GAAG,CAAC,EAAE,KAAK,GAAG,MAAM,EAAE,KAAK,EAAE,EAAE,CAAC;QAC7C,MAAM,KAAK,GAAG,MAAM,CAAC,SAAS,GAAG,gBAAgB,CAAC,CAAC;QACnD,SAAS,KAAK,YAAY,CAAC;QAC3B,GAAG,CAAC,KAAK,CAAC,GAAG,KAAK,KAAK,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,KAAK,GAAG,gBAAgB,CAAC;IACtE,CAAC;IACD,OAAO,GAAG,CAAC;AACZ,CAAC"}
@@ -0,0 +1,14 @@
1
+ /**
2
+ * Encodes an integer as a signed LEB128, two's complement, least significant
3
+ * group first, in the fewest bytes — DWARF's `SLEB128` and WebAssembly's `sN`.
4
+ *
5
+ * Time complexity: O(log₁₂₈ |value|).
6
+ *
7
+ * @example
8
+ * encodeSleb128(-123_456); // Uint8Array [0xc0, 0xbb, 0x78]
9
+ *
10
+ * @returns A fresh buffer holding the encoding, never empty.
11
+ * @throws {RangeError} When `value` is fractional or not a safe integer.
12
+ */
13
+ export declare function encodeSleb128(value: number): Uint8Array<ArrayBuffer>;
14
+ //# sourceMappingURL=encode-sleb128.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"encode-sleb128.d.ts","sourceRoot":"","sources":["../../src/leb128/encode-sleb128.ts"],"names":[],"mappings":"AAGA;;;;;;;;;;;GAWG;AACH,wBAAgB,aAAa,CAAC,KAAK,EAAE,MAAM,GAAG,UAAU,CAAC,WAAW,CAAC,CAIpE"}
@@ -0,0 +1,20 @@
1
+ import { sleb128ByteLength } from "./sleb128-byte-length.js";
2
+ import { writeSleb128 } from "./write-sleb128.js";
3
+ /**
4
+ * Encodes an integer as a signed LEB128, two's complement, least significant
5
+ * group first, in the fewest bytes — DWARF's `SLEB128` and WebAssembly's `sN`.
6
+ *
7
+ * Time complexity: O(log₁₂₈ |value|).
8
+ *
9
+ * @example
10
+ * encodeSleb128(-123_456); // Uint8Array [0xc0, 0xbb, 0x78]
11
+ *
12
+ * @returns A fresh buffer holding the encoding, never empty.
13
+ * @throws {RangeError} When `value` is fractional or not a safe integer.
14
+ */
15
+ export function encodeSleb128(value) {
16
+ const out = new Uint8Array(sleb128ByteLength(value));
17
+ writeSleb128(out, 0, value);
18
+ return out;
19
+ }
20
+ //# sourceMappingURL=encode-sleb128.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"encode-sleb128.js","sourceRoot":"","sources":["../../src/leb128/encode-sleb128.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,MAAM,0BAA0B,CAAC;AAC7D,OAAO,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAElD;;;;;;;;;;;GAWG;AACH,MAAM,UAAU,aAAa,CAAC,KAAa;IAC1C,MAAM,GAAG,GAAG,IAAI,UAAU,CAAC,iBAAiB,CAAC,KAAK,CAAC,CAAC,CAAC;IACrD,YAAY,CAAC,GAAG,EAAE,CAAC,EAAE,KAAK,CAAC,CAAC;IAC5B,OAAO,GAAG,CAAC;AACZ,CAAC"}
@@ -0,0 +1,17 @@
1
+ /**
2
+ * Encodes a non-negative integer as an unsigned LEB128, least significant group
3
+ * first, in the fewest bytes — DWARF's `ULEB128`, WebAssembly's `uN`, a
4
+ * Protocol Buffers varint. A protobuf `sint` field zigzag-maps its value to an
5
+ * unsigned one first.
6
+ *
7
+ * Time complexity: O(log₁₂₈ value).
8
+ *
9
+ * @example
10
+ * encodeUleb128(624_485); // Uint8Array [0xe5, 0x8e, 0x26]
11
+ *
12
+ * @returns A fresh buffer holding the encoding, never empty.
13
+ * @throws {RangeError} When `value` is negative, fractional, or beyond
14
+ * `Number.MAX_SAFE_INTEGER`.
15
+ */
16
+ export declare function encodeUleb128(value: number): Uint8Array<ArrayBuffer>;
17
+ //# sourceMappingURL=encode-uleb128.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"encode-uleb128.d.ts","sourceRoot":"","sources":["../../src/leb128/encode-uleb128.ts"],"names":[],"mappings":"AAGA;;;;;;;;;;;;;;GAcG;AACH,wBAAgB,aAAa,CAAC,KAAK,EAAE,MAAM,GAAG,UAAU,CAAC,WAAW,CAAC,CAIpE"}
@@ -0,0 +1,23 @@
1
+ import { uleb128ByteLength } from "./uleb128-byte-length.js";
2
+ import { writeUleb128 } from "./write-uleb128.js";
3
+ /**
4
+ * Encodes a non-negative integer as an unsigned LEB128, least significant group
5
+ * first, in the fewest bytes — DWARF's `ULEB128`, WebAssembly's `uN`, a
6
+ * Protocol Buffers varint. A protobuf `sint` field zigzag-maps its value to an
7
+ * unsigned one first.
8
+ *
9
+ * Time complexity: O(log₁₂₈ value).
10
+ *
11
+ * @example
12
+ * encodeUleb128(624_485); // Uint8Array [0xe5, 0x8e, 0x26]
13
+ *
14
+ * @returns A fresh buffer holding the encoding, never empty.
15
+ * @throws {RangeError} When `value` is negative, fractional, or beyond
16
+ * `Number.MAX_SAFE_INTEGER`.
17
+ */
18
+ export function encodeUleb128(value) {
19
+ const out = new Uint8Array(uleb128ByteLength(value));
20
+ writeUleb128(out, 0, value);
21
+ return out;
22
+ }
23
+ //# sourceMappingURL=encode-uleb128.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"encode-uleb128.js","sourceRoot":"","sources":["../../src/leb128/encode-uleb128.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,MAAM,0BAA0B,CAAC;AAC7D,OAAO,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAElD;;;;;;;;;;;;;;GAcG;AACH,MAAM,UAAU,aAAa,CAAC,KAAa;IAC1C,MAAM,GAAG,GAAG,IAAI,UAAU,CAAC,iBAAiB,CAAC,KAAK,CAAC,CAAC,CAAC;IACrD,YAAY,CAAC,GAAG,EAAE,CAAC,EAAE,KAAK,CAAC,CAAC;IAC5B,OAAO,GAAG,CAAC;AACZ,CAAC"}
@@ -0,0 +1,23 @@
1
+ import { type Decoder, type Encoder } from "@ac-kit/format-core";
2
+ /**
3
+ * An unsigned LEB128 as a streaming {@link Decoder}: a truncated value is
4
+ * `incomplete`, so a driver waits for more input; a value too large for a
5
+ * `number` is `fatal`. Stateless. Prefer {@link readUleb128} wherever the bytes
6
+ * are already in memory: the streaming form allocates a result per value.
7
+ */
8
+ export declare const uleb128Decoder: Decoder<number>;
9
+ /** A signed LEB128 as a streaming {@link Decoder}, as {@link uleb128Decoder}. */
10
+ export declare const sleb128Decoder: Decoder<number>;
11
+ /** An unsigned LEB128 as a streaming {@link Decoder} producing `bigint`. */
12
+ export declare const bigUleb128Decoder: Decoder<bigint>;
13
+ /** A signed LEB128 as a streaming {@link Decoder} producing `bigint`. */
14
+ export declare const bigSleb128Decoder: Decoder<bigint>;
15
+ /** An unsigned LEB128 as a streaming {@link Encoder}. Stateless. */
16
+ export declare const uleb128Encoder: Encoder<number>;
17
+ /** A signed LEB128 as a streaming {@link Encoder}. Stateless. */
18
+ export declare const sleb128Encoder: Encoder<number>;
19
+ /** An unsigned LEB128 `bigint` as a streaming {@link Encoder}. Stateless. */
20
+ export declare const bigUleb128Encoder: Encoder<bigint>;
21
+ /** A signed LEB128 `bigint` as a streaming {@link Encoder}. Stateless. */
22
+ export declare const bigSleb128Encoder: Encoder<bigint>;
23
+ //# sourceMappingURL=leb128-codecs.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"leb128-codecs.d.ts","sourceRoot":"","sources":["../../src/leb128/leb128-codecs.ts"],"names":[],"mappings":"AACA,OAAO,EAGN,KAAK,OAAO,EACZ,KAAK,OAAO,EACZ,MAAM,qBAAqB,CAAC;AAmC7B;;;;;GAKG;AACH,eAAO,MAAM,cAAc,EAAE,OAAO,CAAC,MAAM,CAA2B,CAAC;AAEvE,iFAAiF;AACjF,eAAO,MAAM,cAAc,EAAE,OAAO,CAAC,MAAM,CAA2B,CAAC;AAEvE,4EAA4E;AAC5E,eAAO,MAAM,iBAAiB,EAAE,OAAO,CAAC,MAAM,CAA8B,CAAC;AAE7E,yEAAyE;AACzE,eAAO,MAAM,iBAAiB,EAAE,OAAO,CAAC,MAAM,CAA8B,CAAC;AAE7E,oEAAoE;AACpE,eAAO,MAAM,cAAc,EAAE,OAAO,CAAC,MAAM,CAA6B,CAAC;AAEzE,iEAAiE;AACjE,eAAO,MAAM,cAAc,EAAE,OAAO,CAAC,MAAM,CAA6B,CAAC;AAEzE,6EAA6E;AAC7E,eAAO,MAAM,iBAAiB,EAAE,OAAO,CAAC,MAAM,CAAgC,CAAC;AAE/E,0EAA0E;AAC1E,eAAO,MAAM,iBAAiB,EAAE,OAAO,CAAC,MAAM,CAAgC,CAAC"}
@@ -0,0 +1,53 @@
1
+ import { ByteReader } from "@ac-kit/core";
2
+ import { DECODE_INCOMPLETE, } from "@ac-kit/format-core";
3
+ import { VarintIncompleteError } from "../errors.js";
4
+ import { encodeBigSleb128 } from "./encode-big-sleb128.js";
5
+ import { encodeBigUleb128 } from "./encode-big-uleb128.js";
6
+ import { encodeSleb128 } from "./encode-sleb128.js";
7
+ import { encodeUleb128 } from "./encode-uleb128.js";
8
+ import { readBigSleb128 } from "./read-big-sleb128.js";
9
+ import { readBigUleb128 } from "./read-big-uleb128.js";
10
+ import { readSleb128 } from "./read-sleb128.js";
11
+ import { readUleb128 } from "./read-uleb128.js";
12
+ function decoderOf_(read) {
13
+ return {
14
+ decode(view) {
15
+ const reader = new ByteReader(view);
16
+ try {
17
+ const value = read(reader);
18
+ return { status: "decoded", value, consumed: reader.position };
19
+ }
20
+ catch (error) {
21
+ if (error instanceof VarintIncompleteError) {
22
+ return DECODE_INCOMPLETE;
23
+ }
24
+ return {
25
+ status: "fatal",
26
+ error: error instanceof Error ? error : new Error(String(error)),
27
+ };
28
+ }
29
+ },
30
+ };
31
+ }
32
+ /**
33
+ * An unsigned LEB128 as a streaming {@link Decoder}: a truncated value is
34
+ * `incomplete`, so a driver waits for more input; a value too large for a
35
+ * `number` is `fatal`. Stateless. Prefer {@link readUleb128} wherever the bytes
36
+ * are already in memory: the streaming form allocates a result per value.
37
+ */
38
+ export const uleb128Decoder = decoderOf_(readUleb128);
39
+ /** A signed LEB128 as a streaming {@link Decoder}, as {@link uleb128Decoder}. */
40
+ export const sleb128Decoder = decoderOf_(readSleb128);
41
+ /** An unsigned LEB128 as a streaming {@link Decoder} producing `bigint`. */
42
+ export const bigUleb128Decoder = decoderOf_(readBigUleb128);
43
+ /** A signed LEB128 as a streaming {@link Decoder} producing `bigint`. */
44
+ export const bigSleb128Decoder = decoderOf_(readBigSleb128);
45
+ /** An unsigned LEB128 as a streaming {@link Encoder}. Stateless. */
46
+ export const uleb128Encoder = { encode: encodeUleb128 };
47
+ /** A signed LEB128 as a streaming {@link Encoder}. Stateless. */
48
+ export const sleb128Encoder = { encode: encodeSleb128 };
49
+ /** An unsigned LEB128 `bigint` as a streaming {@link Encoder}. Stateless. */
50
+ export const bigUleb128Encoder = { encode: encodeBigUleb128 };
51
+ /** A signed LEB128 `bigint` as a streaming {@link Encoder}. Stateless. */
52
+ export const bigSleb128Encoder = { encode: encodeBigSleb128 };
53
+ //# sourceMappingURL=leb128-codecs.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"leb128-codecs.js","sourceRoot":"","sources":["../../src/leb128/leb128-codecs.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAC1C,OAAO,EACN,iBAAiB,GAIjB,MAAM,qBAAqB,CAAC;AAE7B,OAAO,EAAE,qBAAqB,EAAE,MAAM,cAAc,CAAC;AACrD,OAAO,EAAE,gBAAgB,EAAE,MAAM,yBAAyB,CAAC;AAC3D,OAAO,EAAE,gBAAgB,EAAE,MAAM,yBAAyB,CAAC;AAC3D,OAAO,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AACpD,OAAO,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AAEpD,OAAO,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAC;AACvD,OAAO,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAC;AACvD,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAChD,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAEhD,SAAS,UAAU,CAClB,IAA4D;IAE5D,OAAO;QACN,MAAM,CAAC,IAAgB;YACtB,MAAM,MAAM,GAAG,IAAI,UAAU,CAAC,IAAI,CAAC,CAAC;YACpC,IAAI,CAAC;gBACJ,MAAM,KAAK,GAAG,IAAI,CAAC,MAAM,CAAC,CAAC;gBAC3B,OAAO,EAAE,MAAM,EAAE,SAAS,EAAE,KAAK,EAAE,QAAQ,EAAE,MAAM,CAAC,QAAQ,EAAE,CAAC;YAChE,CAAC;YAAC,OAAO,KAAK,EAAE,CAAC;gBAChB,IAAI,KAAK,YAAY,qBAAqB,EAAE,CAAC;oBAC5C,OAAO,iBAAiB,CAAC;gBAC1B,CAAC;gBACD,OAAO;oBACN,MAAM,EAAE,OAAO;oBACf,KAAK,EAAE,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,IAAI,KAAK,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;iBAChE,CAAC;YACH,CAAC;QACF,CAAC;KACD,CAAC;AACH,CAAC;AAED;;;;;GAKG;AACH,MAAM,CAAC,MAAM,cAAc,GAAoB,UAAU,CAAC,WAAW,CAAC,CAAC;AAEvE,iFAAiF;AACjF,MAAM,CAAC,MAAM,cAAc,GAAoB,UAAU,CAAC,WAAW,CAAC,CAAC;AAEvE,4EAA4E;AAC5E,MAAM,CAAC,MAAM,iBAAiB,GAAoB,UAAU,CAAC,cAAc,CAAC,CAAC;AAE7E,yEAAyE;AACzE,MAAM,CAAC,MAAM,iBAAiB,GAAoB,UAAU,CAAC,cAAc,CAAC,CAAC;AAE7E,oEAAoE;AACpE,MAAM,CAAC,MAAM,cAAc,GAAoB,EAAE,MAAM,EAAE,aAAa,EAAE,CAAC;AAEzE,iEAAiE;AACjE,MAAM,CAAC,MAAM,cAAc,GAAoB,EAAE,MAAM,EAAE,aAAa,EAAE,CAAC;AAEzE,6EAA6E;AAC7E,MAAM,CAAC,MAAM,iBAAiB,GAAoB,EAAE,MAAM,EAAE,gBAAgB,EAAE,CAAC;AAE/E,0EAA0E;AAC1E,MAAM,CAAC,MAAM,iBAAiB,GAAoB,EAAE,MAAM,EAAE,gBAAgB,EAAE,CAAC"}
@@ -0,0 +1,17 @@
1
+ /** Options of the LEB128 readers. */
2
+ export type Leb128ReadOptions = {
3
+ /**
4
+ * Reject an encoding longer than the value needs: a final `0x00` group after
5
+ * another for `uleb128`, or a final group that only repeats the sign of the
6
+ * one before for `sleb128`. False by default, since DWARF, WebAssembly and
7
+ * Protocol Buffers all allow the padded form a fixed-width writer produces.
8
+ */
9
+ readonly canonical?: boolean;
10
+ /**
11
+ * The most bytes one value may take, a positive integer; unbounded by
12
+ * default. WebAssembly's `uN` and `sN` take at most ⌈N / 7⌉ bytes, so 5 for a
13
+ * 32-bit integer and 10 for a 64-bit one.
14
+ */
15
+ readonly maxByteLength?: number;
16
+ };
17
+ //# sourceMappingURL=leb128-read-options.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"leb128-read-options.d.ts","sourceRoot":"","sources":["../../src/leb128/leb128-read-options.ts"],"names":[],"mappings":"AAAA,qCAAqC;AACrC,MAAM,MAAM,iBAAiB,GAAG;IAC/B;;;;;OAKG;IACH,QAAQ,CAAC,SAAS,CAAC,EAAE,OAAO,CAAC;IAC7B;;;;OAIG;IACH,QAAQ,CAAC,aAAa,CAAC,EAAE,MAAM,CAAC;CAChC,CAAC"}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=leb128-read-options.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"leb128-read-options.js","sourceRoot":"","sources":["../../src/leb128/leb128-read-options.ts"],"names":[],"mappings":""}