moat-lib-codec 0.4.22__tar.gz → 0.4.23__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.
Files changed (37) hide show
  1. {moat_lib_codec-0.4.22/src/moat_lib_codec.egg-info → moat_lib_codec-0.4.23}/PKG-INFO +20 -4
  2. {moat_lib_codec-0.4.22 → moat_lib_codec-0.4.23}/README.md +15 -0
  3. {moat_lib_codec-0.4.22 → moat_lib_codec-0.4.23}/debian/changelog +12 -0
  4. {moat_lib_codec-0.4.22 → moat_lib_codec-0.4.23}/pyproject.toml +5 -4
  5. {moat_lib_codec-0.4.22 → moat_lib_codec-0.4.23}/src/moat/lib/codec/_cbor.py +28 -10
  6. {moat_lib_codec-0.4.22 → moat_lib_codec-0.4.23/src/moat_lib_codec.egg-info}/PKG-INFO +20 -4
  7. moat_lib_codec-0.4.23/src/moat_lib_codec.egg-info/requires.txt +6 -0
  8. moat_lib_codec-0.4.22/src/moat_lib_codec.egg-info/requires.txt +0 -5
  9. {moat_lib_codec-0.4.22 → moat_lib_codec-0.4.23}/LICENSE.txt +0 -0
  10. {moat_lib_codec-0.4.22 → moat_lib_codec-0.4.23}/Makefile +0 -0
  11. {moat_lib_codec-0.4.22 → moat_lib_codec-0.4.23}/debian/.gitignore +0 -0
  12. {moat_lib_codec-0.4.22 → moat_lib_codec-0.4.23}/debian/control +0 -0
  13. {moat_lib_codec-0.4.22 → moat_lib_codec-0.4.23}/debian/py3dist-overrides +0 -0
  14. {moat_lib_codec-0.4.22 → moat_lib_codec-0.4.23}/debian/rules +0 -0
  15. {moat_lib_codec-0.4.22 → moat_lib_codec-0.4.23}/setup.cfg +0 -0
  16. {moat_lib_codec-0.4.22 → moat_lib_codec-0.4.23}/src/moat/lib/codec/__init__.py +0 -0
  17. {moat_lib_codec-0.4.22 → moat_lib_codec-0.4.23}/src/moat/lib/codec/_base.py +0 -0
  18. {moat_lib_codec-0.4.22 → moat_lib_codec-0.4.23}/src/moat/lib/codec/_moat_cbor.py +0 -0
  19. {moat_lib_codec-0.4.22 → moat_lib_codec-0.4.23}/src/moat/lib/codec/_moat_msgpack.py +0 -0
  20. {moat_lib_codec-0.4.22 → moat_lib_codec-0.4.23}/src/moat/lib/codec/binary.py +0 -0
  21. {moat_lib_codec-0.4.22 → moat_lib_codec-0.4.23}/src/moat/lib/codec/bool.py +0 -0
  22. {moat_lib_codec-0.4.22 → moat_lib_codec-0.4.23}/src/moat/lib/codec/cbor.py +0 -0
  23. {moat_lib_codec-0.4.22 → moat_lib_codec-0.4.23}/src/moat/lib/codec/errors.py +0 -0
  24. {moat_lib_codec-0.4.22 → moat_lib_codec-0.4.23}/src/moat/lib/codec/json.py +0 -0
  25. {moat_lib_codec-0.4.22 → moat_lib_codec-0.4.23}/src/moat/lib/codec/jsonvalstr.py +0 -0
  26. {moat_lib_codec-0.4.22 → moat_lib_codec-0.4.23}/src/moat/lib/codec/jsonvalue.py +0 -0
  27. {moat_lib_codec-0.4.22 → moat_lib_codec-0.4.23}/src/moat/lib/codec/moat_cbor.py +0 -0
  28. {moat_lib_codec-0.4.22 → moat_lib_codec-0.4.23}/src/moat/lib/codec/moat_kv.py +0 -0
  29. {moat_lib_codec-0.4.22 → moat_lib_codec-0.4.23}/src/moat/lib/codec/moat_msgpack.py +0 -0
  30. {moat_lib_codec-0.4.22 → moat_lib_codec-0.4.23}/src/moat/lib/codec/msgpack.py +0 -0
  31. {moat_lib_codec-0.4.22 → moat_lib_codec-0.4.23}/src/moat/lib/codec/noop.py +0 -0
  32. {moat_lib_codec-0.4.22 → moat_lib_codec-0.4.23}/src/moat/lib/codec/null.py +0 -0
  33. {moat_lib_codec-0.4.22 → moat_lib_codec-0.4.23}/src/moat/lib/codec/utf8.py +0 -0
  34. {moat_lib_codec-0.4.22 → moat_lib_codec-0.4.23}/src/moat/lib/codec/yaml.py +0 -0
  35. {moat_lib_codec-0.4.22 → moat_lib_codec-0.4.23}/src/moat_lib_codec.egg-info/SOURCES.txt +0 -0
  36. {moat_lib_codec-0.4.22 → moat_lib_codec-0.4.23}/src/moat_lib_codec.egg-info/dependency_links.txt +0 -0
  37. {moat_lib_codec-0.4.22 → moat_lib_codec-0.4.23}/src/moat_lib_codec.egg-info/top_level.txt +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: moat-lib-codec
3
- Version: 0.4.22
3
+ Version: 0.4.23
4
4
  Summary: A simple command/stream multiplexer
5
5
  Author-email: Matthias Urlichs <matthias@urlichs.de>
6
6
  Maintainer-email: Matthias Urlichs <matthias@urlichs.de>
@@ -17,10 +17,11 @@ Requires-Python: >=3.8
17
17
  Description-Content-Type: text/markdown
18
18
  License-File: LICENSE.txt
19
19
  Requires-Dist: anyio~=4.2
20
- Requires-Dist: moat-lib-rpc~=0.7.6
21
- Requires-Dist: moat-lib-micro~=0.3.4
20
+ Requires-Dist: moat-lib-rpc~=0.7.23
21
+ Requires-Dist: moat-lib-micro~=0.3.7
22
22
  Requires-Dist: moat-lib-proxy~=0.1.3
23
- Requires-Dist: moat-util~=0.64.0
23
+ Requires-Dist: moat-util~=0.64.13
24
+ Requires-Dist: moat-lib-path~=0.4.4
24
25
  Dynamic: license-file
25
26
 
26
27
  # The MoaT-Codec library
@@ -42,6 +43,21 @@ in a way that's reason- and stream-able.
42
43
  - JSON
43
44
  - YAML
44
45
 
46
+ On CPython the CBOR codec is implemented in pure Python. MicroPython
47
+ uses the [ccbor](https://github.com/M-o-a-T/micropython-ccbor) C module
48
+ instead (compiled into the firmware; `moat micro prep` builds it into the
49
+ test interpreters). The wire format is identical; the C decoder is stricter
50
+ than the pure-Python one in a few places:
51
+
52
+ - duplicate map keys are an error instead of silently overwriting the
53
+ earlier value,
54
+ - unassigned CBOR simple values are an error instead of a `Tag`,
55
+ - half/single-precision floats decode to their exact value instead of
56
+ being rounded to a fixed number of significant digits,
57
+ - the nesting depth is limited (default 32),
58
+ - a not-well-formed byte in an incremental stream is skipped after the
59
+ error is reported, so decoding can resynchronise.
60
+
45
61
  % end main
46
62
 
47
63
  ## Interface
@@ -17,6 +17,21 @@ in a way that's reason- and stream-able.
17
17
  - JSON
18
18
  - YAML
19
19
 
20
+ On CPython the CBOR codec is implemented in pure Python. MicroPython
21
+ uses the [ccbor](https://github.com/M-o-a-T/micropython-ccbor) C module
22
+ instead (compiled into the firmware; `moat micro prep` builds it into the
23
+ test interpreters). The wire format is identical; the C decoder is stricter
24
+ than the pure-Python one in a few places:
25
+
26
+ - duplicate map keys are an error instead of silently overwriting the
27
+ earlier value,
28
+ - unassigned CBOR simple values are an error instead of a `Tag`,
29
+ - half/single-precision floats decode to their exact value instead of
30
+ being rounded to a fixed number of significant digits,
31
+ - the nesting depth is limited (default 32),
32
+ - a not-well-formed byte in an incremental stream is skipped after the
33
+ error is reported, so decoding can resynchronise.
34
+
20
35
  % end main
21
36
 
22
37
  ## Interface
@@ -1,3 +1,15 @@
1
+ moat-lib-codec (0.4.23-1) unstable; urgency=medium
2
+
3
+ * New release for 26.5.49
4
+
5
+ -- Matthias Urlichs <matthias@urlichs.de> Fri, 06 Nov 2026 11:29:06 +0100
6
+
7
+ moat-lib-codec (0.4.22-2) unstable; urgency=medium
8
+
9
+ * New release for 26.5.35
10
+
11
+ -- Matthias Urlichs <matthias@urlichs.de> Wed, 04 Nov 2026 19:27:19 +0100
12
+
1
13
  moat-lib-codec (0.4.22-1) unstable; urgency=medium
2
14
 
3
15
  * New release for 26.4.26
@@ -13,10 +13,11 @@ classifiers = [
13
13
  ]
14
14
  dependencies = [
15
15
  "anyio ~= 4.2",
16
- "moat-lib-rpc ~= 0.7.6",
17
- "moat-lib-micro ~= 0.3.4",
16
+ "moat-lib-rpc ~= 0.7.23",
17
+ "moat-lib-micro ~= 0.3.7",
18
18
  "moat-lib-proxy ~= 0.1.3",
19
- "moat-util ~= 0.64.0",
19
+ "moat-util ~= 0.64.13",
20
+ "moat-lib-path ~= 0.4.4",
20
21
  ]
21
22
  keywords = ["MoaT"]
22
23
  requires-python = ">=3.8"
@@ -25,7 +26,7 @@ maintainers = [{email = "matthias@urlichs.de",name = "Matthias Urlichs"}]
25
26
  description='A simple command/stream multiplexer'
26
27
  readme = "README.md"
27
28
  authors = [{email = "matthias@urlichs.de",name = "Matthias Urlichs"}]
28
- version = "0.4.22"
29
+ version = "0.4.23"
29
30
 
30
31
  [project.urls]
31
32
  homepage = "https://m-o-a-t.org"
@@ -111,6 +111,32 @@ class ExtraData(ValueError):
111
111
  return "decoder received extra data."
112
112
 
113
113
 
114
+ def _shortest(data: bytes, fmt: str, digits: int) -> float:
115
+ """
116
+ Decode a half or single precision float.
117
+
118
+ The result is the shortest decimal number that encodes to the same
119
+ value, so that e.g. single precision 100.2 doesn't decode to
120
+ 100.19999694824219.
121
+
122
+ Args:
123
+ data: the encoded value.
124
+ fmt: its `struct` format.
125
+ digits: the number of significant digits that is always sufficient.
126
+ """
127
+ pf = struct.unpack(fmt, data)[0]
128
+ if pf == 0 or not math.isfinite(pf):
129
+ return pf
130
+ for n in range(1, digits):
131
+ res = float(f"{pf:.{n}g}")
132
+ try:
133
+ if struct.pack(fmt, res) == data:
134
+ return res
135
+ except OverflowError:
136
+ pass
137
+ return pf
138
+
139
+
114
140
  class Codec(_Codec):
115
141
  "Basic CBOR codec"
116
142
 
@@ -405,17 +431,9 @@ class Codec(_Codec):
405
431
  def _dec_tagged(self, tb):
406
432
  # Some special cases of CBOR_7 best handled by special struct.unpack logic here
407
433
  if tb == CBOR_FLOAT16:
408
- data = self._read(2)
409
- pf = struct.unpack_from("!e", data, 0)[0]
410
- if pf != 0:
411
- pf = round(pf, int(4 - math.log10(abs(pf))))
412
- return pf
434
+ return _shortest(self._read(2), "!e", 5)
413
435
  elif tb == CBOR_FLOAT32:
414
- data = self._read(4)
415
- pf = struct.unpack_from("!f", data, 0)[0]
416
- if pf != 0:
417
- pf = round(pf, int(8 - math.log10(abs(pf))))
418
- return pf
436
+ return _shortest(self._read(4), "!f", 9)
419
437
  elif tb == CBOR_FLOAT64:
420
438
  data = self._read(8)
421
439
  pf = struct.unpack_from("!d", data, 0)[0]
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: moat-lib-codec
3
- Version: 0.4.22
3
+ Version: 0.4.23
4
4
  Summary: A simple command/stream multiplexer
5
5
  Author-email: Matthias Urlichs <matthias@urlichs.de>
6
6
  Maintainer-email: Matthias Urlichs <matthias@urlichs.de>
@@ -17,10 +17,11 @@ Requires-Python: >=3.8
17
17
  Description-Content-Type: text/markdown
18
18
  License-File: LICENSE.txt
19
19
  Requires-Dist: anyio~=4.2
20
- Requires-Dist: moat-lib-rpc~=0.7.6
21
- Requires-Dist: moat-lib-micro~=0.3.4
20
+ Requires-Dist: moat-lib-rpc~=0.7.23
21
+ Requires-Dist: moat-lib-micro~=0.3.7
22
22
  Requires-Dist: moat-lib-proxy~=0.1.3
23
- Requires-Dist: moat-util~=0.64.0
23
+ Requires-Dist: moat-util~=0.64.13
24
+ Requires-Dist: moat-lib-path~=0.4.4
24
25
  Dynamic: license-file
25
26
 
26
27
  # The MoaT-Codec library
@@ -42,6 +43,21 @@ in a way that's reason- and stream-able.
42
43
  - JSON
43
44
  - YAML
44
45
 
46
+ On CPython the CBOR codec is implemented in pure Python. MicroPython
47
+ uses the [ccbor](https://github.com/M-o-a-T/micropython-ccbor) C module
48
+ instead (compiled into the firmware; `moat micro prep` builds it into the
49
+ test interpreters). The wire format is identical; the C decoder is stricter
50
+ than the pure-Python one in a few places:
51
+
52
+ - duplicate map keys are an error instead of silently overwriting the
53
+ earlier value,
54
+ - unassigned CBOR simple values are an error instead of a `Tag`,
55
+ - half/single-precision floats decode to their exact value instead of
56
+ being rounded to a fixed number of significant digits,
57
+ - the nesting depth is limited (default 32),
58
+ - a not-well-formed byte in an incremental stream is skipped after the
59
+ error is reported, so decoding can resynchronise.
60
+
45
61
  % end main
46
62
 
47
63
  ## Interface
@@ -0,0 +1,6 @@
1
+ anyio~=4.2
2
+ moat-lib-micro~=0.3.7
3
+ moat-lib-path~=0.4.4
4
+ moat-lib-proxy~=0.1.3
5
+ moat-lib-rpc~=0.7.23
6
+ moat-util~=0.64.13
@@ -1,5 +0,0 @@
1
- anyio~=4.2
2
- moat-lib-micro~=0.3.4
3
- moat-lib-proxy~=0.1.3
4
- moat-lib-rpc~=0.7.6
5
- moat-util~=0.64.0