@thi.ng/leb128 3.0.20 → 3.0.22

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/CHANGELOG.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # Change Log
2
2
 
3
- - **Last updated**: 2023-06-14T07:58:51Z
3
+ - **Last updated**: 2023-06-29T07:13:03Z
4
4
  - **Generator**: [thi.ng/monopub](https://thi.ng/monopub)
5
5
 
6
6
  All notable changes to this project will be documented in this file.
@@ -9,6 +9,12 @@ See [Conventional Commits](https://conventionalcommits.org/) for commit guidelin
9
9
  **Note:** Unlisted _patch_ versions only involve non-code or otherwise excluded changes
10
10
  and/or version bumps of transitive dependencies.
11
11
 
12
+ ### [3.0.21](https://github.com/thi-ng/umbrella/tree/@thi.ng/leb128@3.0.21) (2023-06-29)
13
+
14
+ #### ♻️ Refactoring
15
+
16
+ - Zig v0.11-dev syntax & build updates ([cae6541](https://github.com/thi-ng/umbrella/commit/cae6541))
17
+
12
18
  # [3.0.0](https://github.com/thi-ng/umbrella/tree/@thi.ng/leb128@3.0.0) (2022-12-02)
13
19
 
14
20
  #### 🛑 Breaking changes
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@thi.ng/leb128",
3
- "version": "3.0.20",
3
+ "version": "3.0.22",
4
4
  "description": "WASM based LEB128 encoder / decoder (signed & unsigned)",
5
5
  "type": "module",
6
6
  "module": "./index.js",
@@ -37,7 +37,7 @@
37
37
  "dependencies": {
38
38
  "@thi.ng/checks": "^3.3.14",
39
39
  "@thi.ng/errors": "^2.2.17",
40
- "@thi.ng/transducers-binary": "^2.1.50"
40
+ "@thi.ng/transducers-binary": "^2.1.51"
41
41
  },
42
42
  "devDependencies": {
43
43
  "@microsoft/api-extractor": "^7.35.3",
@@ -80,5 +80,5 @@
80
80
  "thi.ng": {
81
81
  "year": 2019
82
82
  },
83
- "gitHead": "54e825a976c72067a244cff8725ca98f5416d26d\n"
83
+ "gitHead": "88cfe77770f3b07c788301dccefcb9547cd4aff6\n"
84
84
  }
package/zig/leb128.zig CHANGED
@@ -4,13 +4,13 @@ export var buf: [10]u8 = undefined;
4
4
  /// have at least 10 bytes capacity)
5
5
  pub fn leb128EncodeU(src: u64, dest: []u8) u8 {
6
6
  if (src < 0x80) {
7
- dest[0] = @intCast(u8, src & 0x7f);
7
+ dest[0] = @intCast(src & 0x7f);
8
8
  return 1;
9
9
  }
10
10
  var n: u8 = 0;
11
11
  var x: u64 = src;
12
12
  while (true) {
13
- var byte: u8 = @intCast(u8, x & 0x7f);
13
+ var byte: u8 = @intCast(x & 0x7f);
14
14
  x = x >> 7;
15
15
  if (x != 0) {
16
16
  byte |= 0x80;
@@ -30,7 +30,7 @@ pub fn leb128DecodeU(src: []u8, num: *u8) u64 {
30
30
  var n: u8 = 0;
31
31
  while (n < 10) {
32
32
  var byte = src[n];
33
- res |= @intCast(u64, byte & 0x7f) << shift;
33
+ res |= @as(u64, @intCast(byte & 0x7f)) << shift;
34
34
  shift += 7;
35
35
  n += 1;
36
36
  if (byte < 0x80) {
@@ -45,15 +45,15 @@ pub fn leb128DecodeU(src: []u8, num: *u8) u64 {
45
45
  pub fn leb128EncodeI(src: i64, dest: []u8) u8 {
46
46
  const neg: bool = src < 0;
47
47
  if (src >= -64 and src < 64) {
48
- dest[0] = @intCast(u8, src & 0x3f) |
49
- @intCast(u8, @boolToInt(neg)) << 6;
48
+ dest[0] = @as(u8, @intCast(src & 0x3f)) |
49
+ @as(u8, @intCast(@intFromBool(neg))) << 6;
50
50
  return 1;
51
51
  }
52
52
  var n: u8 = 0;
53
53
  var x: i64 = src;
54
54
  var more: bool = true;
55
55
  while (more) {
56
- var byte: u8 = @intCast(u8, x & 0x7f);
56
+ var byte: u8 = @intCast(x & 0x7f);
57
57
  var sign: bool = (byte & 0x40) > 0;
58
58
  x >>= 7;
59
59
  if ((x == 0 and !sign) or (x == -1 and sign)) {
@@ -75,7 +75,7 @@ pub fn leb128DecodeI(src: []u8, num: *u8) i64 {
75
75
  var byte: u8 = 0;
76
76
  while (true) {
77
77
  byte = src[n];
78
- res |= @intCast(i64, byte & 0x7f) << shift;
78
+ res |= @as(i64, @intCast(byte & 0x7f)) << shift;
79
79
  shift += 7;
80
80
  n += 1;
81
81
  if ((byte & 0x80) == 0 or n > 9) {
@@ -83,7 +83,7 @@ pub fn leb128DecodeI(src: []u8, num: *u8) i64 {
83
83
  }
84
84
  }
85
85
  if (n < 10 and (byte & 0x40) > 0) {
86
- res |= @intCast(i64, -1) << shift;
86
+ res |= @as(i64, @intCast(-1)) << shift;
87
87
  }
88
88
  num.* = n;
89
89
  return res;
@@ -92,24 +92,24 @@ pub fn leb128DecodeI(src: []u8, num: *u8) i64 {
92
92
  /// WASM only. JS interop to exchange data via f64 (for lack of i64/u64
93
93
  /// on JS side). Writes results to exported `buf` array and returns
94
94
  /// number of bytes used.
95
- export fn leb128EncodeU64(x: u64) u8 {
95
+ pub export fn leb128EncodeU64(x: u64) u8 {
96
96
  return leb128EncodeU(x, buf[0..]);
97
97
  }
98
98
 
99
99
  /// WASM only. JS interop to exchange data via f64 (for lack of i64/u64
100
100
  /// on JS side). Consumes bytes from the exported `buf` array and returns
101
101
  /// decoded value. Writes number of bytes consumed into `buf[0]`
102
- export fn leb128DecodeU64() u64 {
102
+ pub export fn leb128DecodeU64() u64 {
103
103
  return leb128DecodeU(buf[0..], &buf[0]);
104
104
  }
105
105
 
106
106
  /// See `leb128_encode_u_js`
107
- export fn leb128EncodeI64(x: i64) u8 {
107
+ pub export fn leb128EncodeI64(x: i64) u8 {
108
108
  return leb128EncodeI(x, buf[0..]);
109
109
  }
110
110
 
111
111
  /// See `leb128_decode_u_js`
112
- export fn leb128DecodeI64() i64 {
112
+ pub export fn leb128DecodeI64() i64 {
113
113
  return leb128DecodeI(buf[0..], &buf[0]);
114
114
  }
115
115