sltcodec 1.2.0__tar.gz → 1.2.1__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.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.5
2
2
  Name: sltcodec
3
- Version: 1.2.0
3
+ Version: 1.2.1
4
4
  Summary: Decode and encode bytearrays according to struct layout definitions using sltcore.
5
5
  Project-URL: Homepage, https://github.com/fangface-hub/StructLayoutToolkitCodec
6
6
  Project-URL: Documentation, https://readthedocs.org
@@ -145,7 +145,7 @@ Output:
145
145
  ```python
146
146
  bytearray(b"\x03\x04")
147
147
  StructInstance(struct_def=StructDef(...), field_instances=[...])
148
- [FieldInstance(field_def=FieldDef(name='pair', offset=InfoSize(byte=0, bit=0), size=InfoSize(byte=2, bit=0), type=[...], scale=1.0, repeat=None),
148
+ [FieldInstance(field_def=FieldDef(name='pair', offset=InfoSize(byte=0, bit=0), size=InfoSize(byte=2, bit=0), type=StructDef(...), scale=1.0, repeat=None),
149
149
  value=StructInstance(struct_def=StructDef(...), field_instances=[...]))]
150
150
  ```
151
151
 
@@ -204,6 +204,10 @@ print(encoded_float, decoded_float)
204
204
  You can persist reusable structure definitions by name with
205
205
  `save_struct_def_dict` / `load_struct_def_dict`.
206
206
 
207
+ `InfoSize` values in `offset` and `size` are saved as typed dictionaries in
208
+ JSON. Expression-based offsets and sizes remain strings and are resolved when
209
+ the definition is used.
210
+
207
211
  ```python
208
212
  from pathlib import Path
209
213
 
@@ -232,8 +236,8 @@ print(loaded["Header"].description)
232
236
  Example output:
233
237
 
234
238
  ```python
235
- bytearray(b"\x01\x07") StructInstance(struct_def=StructDef(...), field_instances=[...])
236
- bytearray(b"\x02?\xc0\x00\x00") StructInstance(struct_def=StructDef(...), field_instances=[...])
239
+ Header
240
+ Simple header
237
241
  ```
238
242
 
239
243
  ## Enum Definitions
@@ -128,7 +128,7 @@ Output:
128
128
  ```python
129
129
  bytearray(b"\x03\x04")
130
130
  StructInstance(struct_def=StructDef(...), field_instances=[...])
131
- [FieldInstance(field_def=FieldDef(name='pair', offset=InfoSize(byte=0, bit=0), size=InfoSize(byte=2, bit=0), type=[...], scale=1.0, repeat=None),
131
+ [FieldInstance(field_def=FieldDef(name='pair', offset=InfoSize(byte=0, bit=0), size=InfoSize(byte=2, bit=0), type=StructDef(...), scale=1.0, repeat=None),
132
132
  value=StructInstance(struct_def=StructDef(...), field_instances=[...]))]
133
133
  ```
134
134
 
@@ -187,6 +187,10 @@ print(encoded_float, decoded_float)
187
187
  You can persist reusable structure definitions by name with
188
188
  `save_struct_def_dict` / `load_struct_def_dict`.
189
189
 
190
+ `InfoSize` values in `offset` and `size` are saved as typed dictionaries in
191
+ JSON. Expression-based offsets and sizes remain strings and are resolved when
192
+ the definition is used.
193
+
190
194
  ```python
191
195
  from pathlib import Path
192
196
 
@@ -215,8 +219,8 @@ print(loaded["Header"].description)
215
219
  Example output:
216
220
 
217
221
  ```python
218
- bytearray(b"\x01\x07") StructInstance(struct_def=StructDef(...), field_instances=[...])
219
- bytearray(b"\x02?\xc0\x00\x00") StructInstance(struct_def=StructDef(...), field_instances=[...])
222
+ Header
223
+ Simple header
220
224
  ```
221
225
 
222
226
  ## Enum Definitions
@@ -1,6 +1,6 @@
1
1
  [project]
2
2
  name = "sltcodec"
3
- version = "1.2.0"
3
+ version = "1.2.1"
4
4
  description = "Decode and encode bytearrays according to struct layout definitions using sltcore."
5
5
  readme = "README.md"
6
6
  requires-python = ">=3.12"
@@ -159,17 +159,19 @@ class FieldDef:
159
159
 
160
160
  def to_dict(self) -> dict[str, Any]:
161
161
  """Convert this field definition to a JSON-serializable dictionary."""
162
+
163
+ def _serialize_info_like(value: Any) -> Any:
164
+ if isinstance(value, (Info, InfoSize)):
165
+ return json.loads(value.to_json())
166
+ return value
167
+
162
168
  return {
163
169
  "name":
164
170
  self.name,
165
171
  "offset":
166
- self.offset.serialize() if isinstance(self.offset,
167
- (Info,
168
- InfoSize)) else self.offset,
172
+ _serialize_info_like(self.offset),
169
173
  "size":
170
- self.size.serialize() if isinstance(self.size,
171
- (Info,
172
- InfoSize)) else self.size,
174
+ _serialize_info_like(self.size),
173
175
  "type": {
174
176
  "__type__": "StructDef",
175
177
  "fields": self.type.to_dict(),
@@ -1,4 +1,5 @@
1
1
  """Tests for the sltcodec module."""
2
+ import json
2
3
  from enum import Enum
3
4
  from pathlib import Path
4
5
 
@@ -473,6 +474,10 @@ def test_struct_def_dict_load_and_save(tmp_path: Path):
473
474
  path = tmp_path / "field_defs.json"
474
475
 
475
476
  save_struct_def_dict(path, {"value": struct_def})
477
+ saved_field = json.loads(path.read_text())["value"]["fields"][0]
478
+
479
+ assert isinstance(saved_field["offset"], dict)
480
+ assert isinstance(saved_field["size"], dict)
476
481
  loaded = load_struct_def_dict(path)
477
482
 
478
483
  assert loaded["value"] == struct_def
@@ -74,7 +74,7 @@ wheels = [
74
74
 
75
75
  [[package]]
76
76
  name = "sltcodec"
77
- version = "1.1.0"
77
+ version = "1.2.0"
78
78
  source = { editable = "." }
79
79
  dependencies = [
80
80
  { name = "sltcalc" },
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes