Skip to content

Commit b7b5ac7

Browse files
committed
Bump to v0.2.13 with leb128
1 parent 1705c6d commit b7b5ac7

3 files changed

Lines changed: 15 additions & 14 deletions

File tree

pyproject.toml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,16 @@ build-backend = "hatchling.build"
44

55
[project]
66
name = "numcodecs-combinators"
7-
version = "0.2.12"
7+
version = "0.2.13"
88
description = "Combinator codecs for the `numcodecs` buffer compression API"
99
readme = "README.md"
1010
license = "MPL-2.0"
1111
requires-python = ">=3.10"
1212
dependencies = [
13+
"leb128~=1.0.8",
1314
"numcodecs>=0.13.0,<0.17",
1415
"numpy~=2.0",
1516
"typing-extensions~=4.6",
16-
"varint~=1.0.2",
1717
]
1818
optional-dependencies.xarray = [ "xarray>=2024.06", "dask>=2024.6" ]
1919

@@ -39,5 +39,5 @@ addopts = ["--import-mode=importlib"]
3939
xfail_strict = true
4040

4141
[[tool.mypy.overrides]]
42-
module = ["numcodecs.*", "varint.*"]
42+
module = ["leb128.*", "numcodecs.*"]
4343
follow_untyped_imports = true

src/numcodecs_combinators/best.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,11 @@
77
from io import BytesIO
88
from typing import Callable, Optional
99

10+
import leb128
1011
import numcodecs
1112
import numcodecs.compat
1213
import numcodecs.registry
1314
import numpy as np
14-
import varint
1515
from numcodecs.abc import Codec
1616
from typing_extensions import Buffer, Self # MSPV 3.12
1717

@@ -90,7 +90,7 @@ def encode(self, buf: Buffer) -> bytes:
9090
best_index = i
9191
best_encoded = encoded
9292

93-
encoded_index = varint.encode(best_index)
93+
encoded_index = leb128.u.encode(best_index)
9494
encoded_bytes = numcodecs.compat.ensure_bytes(best_encoded)
9595

9696
if len(self) == 1:
@@ -126,7 +126,7 @@ def decode(self, buf: Buffer, out: Optional[Buffer] = None) -> Buffer:
126126
if len(self) == 1:
127127
best_index = 0
128128
else:
129-
best_index = varint.decode_stream(b_io)
129+
best_index = leb128.u.decode_reader(b_io)
130130

131131
return self[best_index].decode(b_io.read(), out=out)
132132

src/numcodecs_combinators/framed.py

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,11 @@
77
from io import BytesIO
88
from typing import Callable, Optional
99

10+
import leb128
1011
import numcodecs
1112
import numcodecs.compat
1213
import numcodecs.registry
1314
import numpy as np
14-
import varint
1515
from numcodecs.abc import Codec
1616
from typing_extensions import Buffer, Self # MSPV 3.12
1717

@@ -97,15 +97,15 @@ def encode(self, buf: Buffer) -> bytes:
9797
encoded_ndarray.dtype.newbyteorder("<")
9898
).tobytes()
9999

100-
message = [varint.encode(len(frames))]
100+
message = [leb128.u.encode(len(frames))]
101101

102102
for dtype, shape in frames:
103-
message.append(varint.encode(len(dtype.str)))
103+
message.append(leb128.u.encode(len(dtype.str)))
104104
message.append(dtype.str.encode("ascii"))
105105

106-
message.append(varint.encode(len(shape)))
106+
message.append(leb128.u.encode(len(shape)))
107107
for s in shape:
108-
message.append(varint.encode(s))
108+
message.append(leb128.u.encode(s))
109109

110110
message.append(encoded_bytes)
111111

@@ -136,16 +136,17 @@ def decode(self, buf: Buffer, out: Optional[Buffer] = None) -> Buffer:
136136

137137
b_io = BytesIO(b)
138138

139-
n_frames = varint.decode_stream(b_io)
139+
n_frames = leb128.u.decode_reader(b_io)
140140
assert n_frames == len(self) + 1, (
141141
f"encoded data must contain {len(self) + 1} frames, found {n_frames}"
142142
)
143143

144144
frames = []
145145
for _ in range(n_frames):
146-
dtype = np.dtype(b_io.read(varint.decode_stream(b_io)).decode("ascii"))
146+
dtype = np.dtype(b_io.read(leb128.u.decode_reader(b_io)).decode("ascii"))
147147
shape = tuple(
148-
varint.decode_stream(b_io) for _ in range(varint.decode_stream(b_io))
148+
leb128.u.decode_reader(b_io)
149+
for _ in range(leb128.u.decode_reader(b_io))
149150
)
150151
frames.append((dtype, shape))
151152

0 commit comments

Comments
 (0)