Skip to content

Commit 76041e5

Browse files
authored
Update to kaitaistruct 0.11 (#1518)
Add support for version 0.11 of the kaitaistruct python runtime. Starting from v0.11, KaitaiStream::size() calls seek() with whence=SEEK_END to determine the amount of remaining data. This commit rolls back the changes from cd5403c and updates the implementation of BufferKaitaiStruct::IOBytes::seek() to support the whence argument.
1 parent 47355b2 commit 76041e5

File tree

4 files changed

+15
-9
lines changed

4 files changed

+15
-9
lines changed

kaitai/python/kaitai_sbp/parse_utils.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import binascii
77
import sys
88
import base64
9+
from io import SEEK_SET, SEEK_CUR, SEEK_END
910

1011

1112
SBP_HEADER_LEN = 6
@@ -28,8 +29,14 @@ def read(self, size=-1):
2829
self.pos += size
2930
return buf
3031

31-
def seek(self, pos):
32-
self.pos = pos
32+
def seek(self, offset, whence=SEEK_SET):
33+
if whence == SEEK_SET:
34+
self.pos = offset
35+
elif whence == SEEK_CUR:
36+
self.pos += offset
37+
elif whence == SEEK_END:
38+
self.pos = len(self.buf) + offset
39+
return self.pos
3340

3441
def tell(self):
3542
return self.pos

kaitai/python/kaitai_sbp/tests/tox.ini

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ envlist = py
66
[testenv]
77
deps =
88
pytest
9-
kaitaistruct==0.10.0
9+
kaitaistruct
1010
construct
1111
python-rapidjson
1212
changedir = ../../../..

python/Dockerfile.benchmark

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,7 @@ ADD . /work
1919

2020
RUN pip3 install -r /work/setup_requirements.txt
2121
RUN pip3 install -r /work/requirements.txt
22-
# keep in sync with above
23-
RUN pip3 install kaitaistruct==0.10.0
22+
RUN pip3 install kaitaistruct
2423

2524
RUN pip3 install wheel setuptools
2625

test_data/benchmark_main.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,18 +11,18 @@
1111

1212
# How much faster Rust should be than other implementations
1313
RATIOS_SBP2JSON = {
14-
"haskell": 3.2,
15-
"python": 23.38,
14+
"haskell": 4.02,
15+
"python": 18.7,
1616
"kaitai_python": 5.00,
17-
"kaitai_perl": 20,
17+
"kaitai_perl": 24.05,
1818
}
1919

2020
RATIOS_JSON2SBP = {
2121
"haskell": 2.05,
2222
}
2323

2424
RATIOS_JSON2JSON = {
25-
"haskell": 2.40,
25+
"haskell": 3.12,
2626
}
2727

2828
FAILED = [False]

0 commit comments

Comments
 (0)