dybuf 0.2.0__tar.gz → 0.4.0__tar.gz
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.
- {dybuf-0.2.0/src/dybuf.egg-info → dybuf-0.4.0}/PKG-INFO +32 -20
- {dybuf-0.2.0 → dybuf-0.4.0}/README.md +30 -2
- {dybuf-0.2.0 → dybuf-0.4.0}/pyproject.toml +2 -3
- {dybuf-0.2.0 → dybuf-0.4.0}/src/dybuf/__init__.py +17 -1
- {dybuf-0.2.0 → dybuf-0.4.0}/src/dybuf/_core.c +2460 -1592
- {dybuf-0.2.0 → dybuf-0.4.0}/src/dybuf/_core.pyx +38 -4
- dybuf-0.4.0/src/dybuf/tests/fixtures.py +31 -0
- dybuf-0.4.0/src/dybuf/tests/test_fixtures.py +94 -0
- {dybuf-0.2.0 → dybuf-0.4.0}/src/dybuf/tests/test_roundtrip.py +53 -14
- {dybuf-0.2.0 → dybuf-0.4.0/src/dybuf.egg-info}/PKG-INFO +32 -20
- {dybuf-0.2.0 → dybuf-0.4.0}/src/dybuf.egg-info/SOURCES.txt +2 -0
- {dybuf-0.2.0 → dybuf-0.4.0}/LICENSE +0 -0
- {dybuf-0.2.0 → dybuf-0.4.0}/MANIFEST.in +0 -0
- {dybuf-0.2.0 → dybuf-0.4.0}/include/dybuf/dybuf.h +0 -0
- {dybuf-0.2.0 → dybuf-0.4.0}/include/dybuf/plat_mem.h +0 -0
- {dybuf-0.2.0 → dybuf-0.4.0}/include/dybuf/plat_string.h +0 -0
- {dybuf-0.2.0 → dybuf-0.4.0}/include/dybuf/plat_type.h +0 -0
- {dybuf-0.2.0 → dybuf-0.4.0}/setup.cfg +0 -0
- {dybuf-0.2.0 → dybuf-0.4.0}/setup.py +0 -0
- {dybuf-0.2.0 → dybuf-0.4.0}/src/dybuf/_core.pxd +0 -0
- {dybuf-0.2.0 → dybuf-0.4.0}/src/dybuf/tests/__init__.py +0 -0
- {dybuf-0.2.0 → dybuf-0.4.0}/src/dybuf.egg-info/dependency_links.txt +0 -0
- {dybuf-0.2.0 → dybuf-0.4.0}/src/dybuf.egg-info/top_level.txt +0 -0
|
@@ -1,31 +1,15 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: dybuf
|
|
3
|
-
Version: 0.
|
|
3
|
+
Version: 0.4.0
|
|
4
4
|
Summary: Python bindings for the dybuf dynamic buffer library.
|
|
5
5
|
Author-email: Yuchi <yuchi518@gmail.com>
|
|
6
6
|
Maintainer-email: Yuchi <yuchi518@gmail.com>
|
|
7
|
-
License:
|
|
8
|
-
Copyright (C) 2015-2016 Yuchi (yuchi518@gmail.com)
|
|
9
|
-
|
|
10
|
-
This program is free software; you can redistribute it and/or modify
|
|
11
|
-
it under the terms of the GNU General Public License version 2 as
|
|
12
|
-
published by the Free Software Foundation. For the terms of this
|
|
13
|
-
license, see <http://www.gnu.org/licenses>.
|
|
14
|
-
|
|
15
|
-
This program is distributed in the hope that it will be useful,
|
|
16
|
-
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
17
|
-
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
18
|
-
GNU General Public License for more details.
|
|
19
|
-
|
|
20
|
-
You should have received a copy of the GNU General Public License along
|
|
21
|
-
with this program; if not, write to the Free Software Foundation, Inc.,
|
|
22
|
-
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
|
7
|
+
License: GPL-2.0-only
|
|
23
8
|
Project-URL: Homepage, https://github.com/yuchi518/dybuf
|
|
24
9
|
Project-URL: Issues, https://github.com/yuchi518/dybuf/issues
|
|
25
10
|
Keywords: buffer,binary,cython
|
|
26
11
|
Classifier: Development Status :: 3 - Alpha
|
|
27
12
|
Classifier: Intended Audience :: Developers
|
|
28
|
-
Classifier: License :: OSI Approved :: GNU General Public License v2 (GPLv2)
|
|
29
13
|
Classifier: Operating System :: OS Independent
|
|
30
14
|
Classifier: Programming Language :: Python :: 3
|
|
31
15
|
Classifier: Programming Language :: Python :: 3 :: Only
|
|
@@ -44,7 +28,8 @@ Python bindings for the [`dybuf`](../c/dybuf.h) dynamic buffer library implement
|
|
|
44
28
|
## Key features
|
|
45
29
|
|
|
46
30
|
- Thin, fast wrapper around the original `dybuf` implementation.
|
|
47
|
-
- Supports reading and writing unsigned integers (8–64 bits), booleans,
|
|
31
|
+
- Supports reading and writing unsigned integers (8–64 bits), booleans, raw byte payloads, and the library’s compact `var_u64`/`var_s64` varints.
|
|
32
|
+
- Exposes typdex markers so higher-level protocols can tag fields without hauling in a full protobuf-style schema.
|
|
48
33
|
- Compatible with Windows, Linux, and macOS thanks to compiled extension modules.
|
|
49
34
|
- Designed for publishing on PyPI with automated release workflows.
|
|
50
35
|
|
|
@@ -76,6 +61,29 @@ print(buf.next_bool()) # True
|
|
|
76
61
|
|
|
77
62
|
`write()` and `read()` let you work directly with arbitrary byte payloads, while `position`, `limit`, and `capacity` expose the cursor-style API provided by the original library.
|
|
78
63
|
|
|
64
|
+
## Variable-length integers
|
|
65
|
+
|
|
66
|
+
`DyBuf` supports zig-zag encoded signed integers and unsigned integers using the same compact varint scheme the C library exposes. These helpers keep the payload small for numbers that fit in a few bits.
|
|
67
|
+
|
|
68
|
+
```python
|
|
69
|
+
from dybuf import DyBuf
|
|
70
|
+
|
|
71
|
+
buf = (
|
|
72
|
+
DyBuf(capacity=32)
|
|
73
|
+
.append_var_s64(-123)
|
|
74
|
+
.append_var_u64(300)
|
|
75
|
+
)
|
|
76
|
+
|
|
77
|
+
buf.flip()
|
|
78
|
+
|
|
79
|
+
print(buf.next_var_s64()) # -123
|
|
80
|
+
print(buf.next_var_u64()) # 300
|
|
81
|
+
```
|
|
82
|
+
|
|
83
|
+
Use `append_var_s64` / `next_var_s64` when you need negative values; the encoding automatically performs zig-zag conversion under the hood. For values that are always non-negative, stick to `append_var_u64` / `next_var_u64` to avoid the extra zig-zag step. The legacy `append_var_int` / `next_var_int` and `append_var_uint` / `next_var_uint` aliases still work but emit `DeprecationWarning` so callers can migrate. The same encoding also powers `append_var_bytes` and `append_var_string`, which prefix their payload with a varint length field for round-tripping arbitrary byte sequences.
|
|
84
|
+
|
|
85
|
+
When you need compatibility with the C helpers that treat strings as NUL-terminated c-strings, call `append_var_cstring` / `next_var_cstring`. Those helpers append the trailing `\0` byte on write (and strip it on read) so buffers line up with `dyb_append_cstring_with_var_len` / `dyb_next_cstring_with_var_len`.
|
|
86
|
+
|
|
79
87
|
## Typdex markers
|
|
80
88
|
|
|
81
89
|
`DyBuf` also exposes helpers for working with the library's **typdex** encodings—a compact representation of a logical type paired with an index. These markers are commonly used by higher-level protocols such as `dypkt` to describe field layouts or function identifiers.
|
|
@@ -112,6 +120,10 @@ pip install -e .
|
|
|
112
120
|
pytest
|
|
113
121
|
```
|
|
114
122
|
|
|
123
|
+
The pytest suite loads the golden vectors generated from the canonical C library
|
|
124
|
+
(`fixtures/v1/*.json`). If the fixtures are missing, run `tools/generate_fixtures.sh`
|
|
125
|
+
from the repository root before executing the tests.
|
|
126
|
+
|
|
115
127
|
The project is configured to build wheels via `python -m build`, producing both source and binary distributions:
|
|
116
128
|
|
|
117
129
|
```bash
|
|
@@ -128,7 +140,7 @@ open docs/_build/html/index.html # or use your preferred viewer
|
|
|
128
140
|
|
|
129
141
|
## Automated releases
|
|
130
142
|
|
|
131
|
-
A GitHub Actions workflow under `.github/workflows/pypi-release.yml` drives [cibuildwheel](https://github.com/pypa/cibuildwheel) to produce Windows, Linux, and macOS artifacts and publish them to PyPI. Provide a `PYPI_API_TOKEN` secret in your repository and tag releases with a semantic version (e.g. `v0.
|
|
143
|
+
A GitHub Actions workflow under `.github/workflows/pypi-release.yml` drives [cibuildwheel](https://github.com/pypa/cibuildwheel) to produce Windows, Linux, and macOS artifacts and publish them to PyPI. Provide a `PYPI_API_TOKEN` secret in your repository and tag releases with a semantic version (e.g. `v0.4.0`) to trigger the pipeline.
|
|
132
144
|
|
|
133
145
|
## Licensing
|
|
134
146
|
|
|
@@ -5,7 +5,8 @@ Python bindings for the [`dybuf`](../c/dybuf.h) dynamic buffer library implement
|
|
|
5
5
|
## Key features
|
|
6
6
|
|
|
7
7
|
- Thin, fast wrapper around the original `dybuf` implementation.
|
|
8
|
-
- Supports reading and writing unsigned integers (8–64 bits), booleans,
|
|
8
|
+
- Supports reading and writing unsigned integers (8–64 bits), booleans, raw byte payloads, and the library’s compact `var_u64`/`var_s64` varints.
|
|
9
|
+
- Exposes typdex markers so higher-level protocols can tag fields without hauling in a full protobuf-style schema.
|
|
9
10
|
- Compatible with Windows, Linux, and macOS thanks to compiled extension modules.
|
|
10
11
|
- Designed for publishing on PyPI with automated release workflows.
|
|
11
12
|
|
|
@@ -37,6 +38,29 @@ print(buf.next_bool()) # True
|
|
|
37
38
|
|
|
38
39
|
`write()` and `read()` let you work directly with arbitrary byte payloads, while `position`, `limit`, and `capacity` expose the cursor-style API provided by the original library.
|
|
39
40
|
|
|
41
|
+
## Variable-length integers
|
|
42
|
+
|
|
43
|
+
`DyBuf` supports zig-zag encoded signed integers and unsigned integers using the same compact varint scheme the C library exposes. These helpers keep the payload small for numbers that fit in a few bits.
|
|
44
|
+
|
|
45
|
+
```python
|
|
46
|
+
from dybuf import DyBuf
|
|
47
|
+
|
|
48
|
+
buf = (
|
|
49
|
+
DyBuf(capacity=32)
|
|
50
|
+
.append_var_s64(-123)
|
|
51
|
+
.append_var_u64(300)
|
|
52
|
+
)
|
|
53
|
+
|
|
54
|
+
buf.flip()
|
|
55
|
+
|
|
56
|
+
print(buf.next_var_s64()) # -123
|
|
57
|
+
print(buf.next_var_u64()) # 300
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
Use `append_var_s64` / `next_var_s64` when you need negative values; the encoding automatically performs zig-zag conversion under the hood. For values that are always non-negative, stick to `append_var_u64` / `next_var_u64` to avoid the extra zig-zag step. The legacy `append_var_int` / `next_var_int` and `append_var_uint` / `next_var_uint` aliases still work but emit `DeprecationWarning` so callers can migrate. The same encoding also powers `append_var_bytes` and `append_var_string`, which prefix their payload with a varint length field for round-tripping arbitrary byte sequences.
|
|
61
|
+
|
|
62
|
+
When you need compatibility with the C helpers that treat strings as NUL-terminated c-strings, call `append_var_cstring` / `next_var_cstring`. Those helpers append the trailing `\0` byte on write (and strip it on read) so buffers line up with `dyb_append_cstring_with_var_len` / `dyb_next_cstring_with_var_len`.
|
|
63
|
+
|
|
40
64
|
## Typdex markers
|
|
41
65
|
|
|
42
66
|
`DyBuf` also exposes helpers for working with the library's **typdex** encodings—a compact representation of a logical type paired with an index. These markers are commonly used by higher-level protocols such as `dypkt` to describe field layouts or function identifiers.
|
|
@@ -73,6 +97,10 @@ pip install -e .
|
|
|
73
97
|
pytest
|
|
74
98
|
```
|
|
75
99
|
|
|
100
|
+
The pytest suite loads the golden vectors generated from the canonical C library
|
|
101
|
+
(`fixtures/v1/*.json`). If the fixtures are missing, run `tools/generate_fixtures.sh`
|
|
102
|
+
from the repository root before executing the tests.
|
|
103
|
+
|
|
76
104
|
The project is configured to build wheels via `python -m build`, producing both source and binary distributions:
|
|
77
105
|
|
|
78
106
|
```bash
|
|
@@ -89,7 +117,7 @@ open docs/_build/html/index.html # or use your preferred viewer
|
|
|
89
117
|
|
|
90
118
|
## Automated releases
|
|
91
119
|
|
|
92
|
-
A GitHub Actions workflow under `.github/workflows/pypi-release.yml` drives [cibuildwheel](https://github.com/pypa/cibuildwheel) to produce Windows, Linux, and macOS artifacts and publish them to PyPI. Provide a `PYPI_API_TOKEN` secret in your repository and tag releases with a semantic version (e.g. `v0.
|
|
120
|
+
A GitHub Actions workflow under `.github/workflows/pypi-release.yml` drives [cibuildwheel](https://github.com/pypa/cibuildwheel) to produce Windows, Linux, and macOS artifacts and publish them to PyPI. Provide a `PYPI_API_TOKEN` secret in your repository and tag releases with a semantic version (e.g. `v0.4.0`) to trigger the pipeline.
|
|
93
121
|
|
|
94
122
|
## Licensing
|
|
95
123
|
|
|
@@ -8,17 +8,16 @@ build-backend = "setuptools.build_meta"
|
|
|
8
8
|
|
|
9
9
|
[project]
|
|
10
10
|
name = "dybuf"
|
|
11
|
-
version = "0.
|
|
11
|
+
version = "0.4.0"
|
|
12
12
|
description = "Python bindings for the dybuf dynamic buffer library."
|
|
13
13
|
readme = "README.md"
|
|
14
14
|
authors = [{ name = "Yuchi", email = "yuchi518@gmail.com" }]
|
|
15
15
|
maintainers = [{ name = "Yuchi", email = "yuchi518@gmail.com" }]
|
|
16
|
-
license = {
|
|
16
|
+
license = { text = "GPL-2.0-only" }
|
|
17
17
|
keywords = ["buffer", "binary", "cython"]
|
|
18
18
|
classifiers = [
|
|
19
19
|
"Development Status :: 3 - Alpha",
|
|
20
20
|
"Intended Audience :: Developers",
|
|
21
|
-
"License :: OSI Approved :: GNU General Public License v2 (GPLv2)",
|
|
22
21
|
"Operating System :: OS Independent",
|
|
23
22
|
"Programming Language :: Python :: 3",
|
|
24
23
|
"Programming Language :: Python :: 3 :: Only",
|
|
@@ -15,6 +15,8 @@ from ._core import (
|
|
|
15
15
|
|
|
16
16
|
__all__ = [
|
|
17
17
|
"DyBuf",
|
|
18
|
+
"append_var_cstring",
|
|
19
|
+
"next_var_cstring",
|
|
18
20
|
"TYPDEX_TYP_NONE",
|
|
19
21
|
"TYPDEX_TYP_BOOL",
|
|
20
22
|
"TYPDEX_TYP_INT",
|
|
@@ -27,4 +29,18 @@ __all__ = [
|
|
|
27
29
|
"TYPDEX_TYP_MAP",
|
|
28
30
|
"TYPDEX_TYP_F",
|
|
29
31
|
]
|
|
30
|
-
|
|
32
|
+
|
|
33
|
+
__version__ = "0.4.0"
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
def append_var_cstring(buf: DyBuf, text: str, *, encoding: str = "utf-8") -> DyBuf:
|
|
37
|
+
data = text.encode(encoding) + b"\x00"
|
|
38
|
+
buf.append_var_bytes(data)
|
|
39
|
+
return buf
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
def next_var_cstring(buf: DyBuf, *, encoding: str = "utf-8") -> str:
|
|
43
|
+
data = buf.next_var_bytes()
|
|
44
|
+
if data.endswith(b"\x00"):
|
|
45
|
+
data = data[:-1]
|
|
46
|
+
return data.decode(encoding)
|