structwire 0.1.0__py3-none-any.whl

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.

Potentially problematic release.


This version of structwire might be problematic. Click here for more details.

@@ -0,0 +1,148 @@
1
+ Metadata-Version: 2.4
2
+ Name: structwire
3
+ Version: 0.1.0
4
+ Summary: A small schema-driven binary payload codec for Python.
5
+ Author: Nidhal Abidi
6
+ License-Expression: MIT
7
+ Project-URL: Homepage, https://github.com/nidops/structwire
8
+ Project-URL: Documentation, https://github.com/nidops/structwire/blob/master/docs/SCHEMA.md
9
+ Project-URL: Source, https://github.com/nidops/structwire
10
+ Project-URL: Issues, https://github.com/nidops/structwire/issues
11
+ Keywords: binary,codec,schema,embedded,payload,bitfield,yaml
12
+ Classifier: Development Status :: 3 - Alpha
13
+ Classifier: Intended Audience :: Developers
14
+ Classifier: Operating System :: OS Independent
15
+ Classifier: Programming Language :: Python :: 3
16
+ Classifier: Programming Language :: Python :: 3.11
17
+ Classifier: Programming Language :: Python :: 3.12
18
+ Classifier: Programming Language :: Python :: 3.13
19
+ Classifier: Programming Language :: Python :: 3.14
20
+ Classifier: Topic :: Software Development :: Libraries :: Python Modules
21
+ Classifier: Typing :: Typed
22
+ Requires-Python: >=3.11
23
+ Description-Content-Type: text/markdown
24
+ License-File: LICENSE
25
+ Requires-Dist: PyYAML>=6.0
26
+ Provides-Extra: test
27
+ Requires-Dist: pytest>=8; extra == "test"
28
+ Requires-Dist: hypothesis>=6; extra == "test"
29
+ Requires-Dist: readme-renderer[md]>=44; extra == "test"
30
+ Provides-Extra: dev
31
+ Requires-Dist: build>=1.2; extra == "dev"
32
+ Requires-Dist: coverage>=7; extra == "dev"
33
+ Requires-Dist: mypy>=1.13; extra == "dev"
34
+ Requires-Dist: pytest>=8; extra == "dev"
35
+ Requires-Dist: hypothesis>=6; extra == "dev"
36
+ Requires-Dist: ruff>=0.8; extra == "dev"
37
+ Requires-Dist: twine>=6.2; extra == "dev"
38
+ Requires-Dist: packaging>=24.2; extra == "dev"
39
+ Requires-Dist: readme-renderer[md]>=44; extra == "dev"
40
+ Requires-Dist: types-PyYAML>=6.0.12; extra == "dev"
41
+ Dynamic: license-file
42
+
43
+ # StructWire
44
+
45
+ StructWire converts fixed-layout binary payloads to Python values and back.
46
+ Use it when a device message, file record or test fixture has a known byte layout.
47
+ Define fields in Python or YAML, then reuse a compiled codec to encode and decode.
48
+ Your application supplies the bytes and handles transport I/O and routing.
49
+
50
+ ## Install
51
+
52
+ Python 3.11 or newer is required. Install from the source checkout:
53
+
54
+ ```bash
55
+ git clone https://github.com/nidops/structwire.git
56
+ cd structwire
57
+ python -m pip install .
58
+ ```
59
+
60
+ Version `0.1.0` is an alpha API. PyYAML is installed automatically for YAML loading.
61
+
62
+ ## Quick start
63
+
64
+ ```python
65
+ from structwire import Field, Layout
66
+
67
+ codec = Layout(
68
+ Field("temperature_c", "i16le", scale=0.1),
69
+ Field("state", "u8"),
70
+ ).compile()
71
+
72
+ payload = codec.encode({"temperature_c": 23.5, "state": 1})
73
+ assert payload == bytes.fromhex("eb 00 01")
74
+ assert codec.decode(payload) == {"temperature_c": 23.5, "state": 1}
75
+ ```
76
+
77
+ Compile a layout once and reuse its codec.
78
+
79
+ ## YAML example
80
+
81
+ Save this as `codecs.yaml`:
82
+
83
+ ```yaml
84
+ version: 1
85
+ codecs:
86
+ node_status:
87
+ size: 4
88
+ fields:
89
+ - name: mode
90
+ type: enum
91
+ values: {0: asleep, 1: awake, 2: fault}
92
+ - name: supply_voltage
93
+ type: uint16_le
94
+ offset: 2
95
+ scale: 0.001
96
+ unit: V
97
+ ```
98
+
99
+ ```python
100
+ from structwire import catalog_from_yaml
101
+
102
+ catalog = catalog_from_yaml("codecs.yaml")
103
+ payload = bytes.fromhex("01 00 88 13")
104
+ values = catalog.decode("node_status", payload)
105
+ assert values == {"mode": "awake", "supply_voltage": 5.0}
106
+ assert catalog.encode("node_status", values) == payload
107
+ ```
108
+
109
+ Offsets and sizes are in bytes. Here, byte 1 is unused and encodes as zero.
110
+ `unit` is display metadata; it does not change the conversion.
111
+
112
+ ## Supported layouts
113
+
114
+ - Signed and unsigned 8/16/24/32/64-bit integers, with explicit byte order.
115
+ - IEEE-754 32/64-bit floats, BCD, fixed ASCII, bytes and MAC addresses.
116
+ - Enums, named flags, booleans and masked sub-fields.
117
+ - Numeric scaling and bias, explicit offsets and optional total payload size.
118
+ - Immutable layouts and reusable compiled codecs, with exact-length decoding by default.
119
+ - Named catalogs and single-layout loaders for YAML or Python mappings.
120
+
121
+ ## Limitations
122
+
123
+ Unscaled integers preserve their full range, including 64-bit values. Scaling uses
124
+ Python floats, so some values cannot be represented exactly. Integer encoding
125
+ rejects values between raw counts, allowing small rounding errors; decoding raises
126
+ `DecodeError` if scaling loses the original count. For exact arithmetic, decode
127
+ unscaled integers and convert them in your application.
128
+
129
+ Encoding zeroes unused bytes and bits, encodes booleans as 0 or 1, and writes only
130
+ declared masks from flags mappings. Arbitrary payloads may therefore change after
131
+ decoding and re-encoding. See the
132
+ [compatibility contract](https://github.com/nidops/structwire/blob/master/docs/COMPATIBILITY.md)
133
+ for precise round-trip and floating-point guarantees.
134
+
135
+ Variable-length fields, nested/repeated layouts and checksums are not supported.
136
+
137
+ Schemas are trusted configuration. Safe YAML loading does not impose resource
138
+ limits; applications must bound untrusted schema and payload sizes. See
139
+ [schema resource limits](https://github.com/nidops/structwire/blob/master/docs/SCHEMA.md#trusted-schemas-and-resource-limits).
140
+
141
+ ## Documentation and examples
142
+
143
+ - [Python API](https://github.com/nidops/structwire/blob/master/docs/API.md)
144
+ - [Schema reference](https://github.com/nidops/structwire/blob/master/docs/SCHEMA.md)
145
+ - [Examples](https://github.com/nidops/structwire/tree/master/examples)
146
+ - [Questions and bug reports](https://github.com/nidops/structwire/issues)
147
+
148
+ MIT. See [LICENSE](https://github.com/nidops/structwire/blob/master/LICENSE).
@@ -0,0 +1,13 @@
1
+ structwire/__init__.py,sha256=MYXCMFaFH5fPatANf_LyRdQRGJcZ5V4beZcyGRssh2I,754
2
+ structwire/catalog.py,sha256=wD-5wFf-7lhD8GpC8JJUqBZMxBEClOlfwrQJCp7tUGo,2963
3
+ structwire/codec.py,sha256=ri3fRHrKo1fmVF-FbxKURwoxdzieGJBnAVF-d8G30MA,20496
4
+ structwire/errors.py,sha256=-6doiS2IKfJHxxK9yQWiCJuXKfHogvLS9oZwGNLK1HE,446
5
+ structwire/formatting.py,sha256=zFpPBPLq2-LcPzJQmztezwrupjBgTpkBa5IUuKs54CI,1521
6
+ structwire/loaders.py,sha256=iN9EdIlxiSldMQZiIGd3fGQ4z7S2lMu1y708byR3Jho,8514
7
+ structwire/model.py,sha256=nOeIfh1EUzs8lUaXBqfmmvWibfQoYM9o2zb_ND20ykQ,12843
8
+ structwire/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
9
+ structwire-0.1.0.dist-info/licenses/LICENSE,sha256=KFddXCxmD9sDTqn0VsPrLlPYV3mY3GEalsh6R5TVQnc,1069
10
+ structwire-0.1.0.dist-info/METADATA,sha256=Bqijc6yrdXKBc-xRYzDcKIwaviVKCgv8FQ478d5HO4M,5491
11
+ structwire-0.1.0.dist-info/WHEEL,sha256=mOdXR9C3wMVov7cSY8PY-XCzo3SmmWCHvGQr5csJoao,91
12
+ structwire-0.1.0.dist-info/top_level.txt,sha256=qyW0KIvvor5jlrfPURznpySP9Wb5omxBZwWK680WE3s,11
13
+ structwire-0.1.0.dist-info/RECORD,,
@@ -0,0 +1,5 @@
1
+ Wheel-Version: 1.0
2
+ Generator: setuptools (84.2.1)
3
+ Root-Is-Purelib: true
4
+ Tag: py3-none-any
5
+
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Nidhal Abidi
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1 @@
1
+ structwire