sltcore 0.2.3__tar.gz → 0.2.4__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.
- {sltcore-0.2.3 → sltcore-0.2.4}/PKG-INFO +1 -1
- {sltcore-0.2.3 → sltcore-0.2.4}/pyproject.toml +1 -1
- {sltcore-0.2.3 → sltcore-0.2.4}/src/sltcore/types.py +44 -3
- {sltcore-0.2.3 → sltcore-0.2.4}/uv.lock +1 -1
- {sltcore-0.2.3 → sltcore-0.2.4}/.github/FUNDING.yml +0 -0
- {sltcore-0.2.3 → sltcore-0.2.4}/.github/workflows/publish_to_pypi.yml +0 -0
- {sltcore-0.2.3 → sltcore-0.2.4}/.github/workflows/publish_to_testpypi.yml +0 -0
- {sltcore-0.2.3 → sltcore-0.2.4}/.gitignore +0 -0
- {sltcore-0.2.3 → sltcore-0.2.4}/.python-version +0 -0
- {sltcore-0.2.3 → sltcore-0.2.4}/.vscode/launch.json +0 -0
- {sltcore-0.2.3 → sltcore-0.2.4}/.vscode/settings.json +0 -0
- {sltcore-0.2.3 → sltcore-0.2.4}/LICENSE +0 -0
- {sltcore-0.2.3 → sltcore-0.2.4}/README.md +0 -0
- {sltcore-0.2.3 → sltcore-0.2.4}/bump_major.ps1 +0 -0
- {sltcore-0.2.3 → sltcore-0.2.4}/bump_minor.ps1 +0 -0
- {sltcore-0.2.3 → sltcore-0.2.4}/bump_patch.ps1 +0 -0
- {sltcore-0.2.3 → sltcore-0.2.4}/src/sltcore/__init__.py +0 -0
- {sltcore-0.2.3 → sltcore-0.2.4}/src/sltcore/bits.py +0 -0
- {sltcore-0.2.3 → sltcore-0.2.4}/tests/test_bits.py +0 -0
- {sltcore-0.2.3 → sltcore-0.2.4}/tests/test_types.py +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: sltcore
|
|
3
|
-
Version: 0.2.
|
|
3
|
+
Version: 0.2.4
|
|
4
4
|
Summary: A toolkit for handling structured data layouts and bit-level operations.
|
|
5
5
|
Project-URL: Homepage, https://github.com/fangface-hub/StructLayoutToolkitCore
|
|
6
6
|
Project-URL: Documentation, https://readthedocs.org
|
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
import math
|
|
3
3
|
import struct
|
|
4
4
|
from dataclasses import dataclass, field
|
|
5
|
+
from functools import total_ordering
|
|
5
6
|
|
|
6
7
|
|
|
7
8
|
def _has_struct_half():
|
|
@@ -17,6 +18,7 @@ def _has_struct_half():
|
|
|
17
18
|
HAS_STRUCT_HALF = _has_struct_half() # ← 一度だけ実行
|
|
18
19
|
|
|
19
20
|
|
|
21
|
+
@total_ordering
|
|
20
22
|
@dataclass(frozen=True)
|
|
21
23
|
class InfoSize:
|
|
22
24
|
"""Represents a size in bytes and bits."""
|
|
@@ -31,22 +33,38 @@ class InfoSize:
|
|
|
31
33
|
object.__setattr__(self, "byte", self.byte + extra_bytes)
|
|
32
34
|
object.__setattr__(self, "bit", new_bits)
|
|
33
35
|
|
|
36
|
+
def __str__(self) -> str:
|
|
37
|
+
"""Returns a string representation of the size
|
|
38
|
+
in the format 'X bytes, Y bits'."""
|
|
39
|
+
return f"{self.byte} bytes, {self.bit} bits"
|
|
40
|
+
|
|
41
|
+
def __eq__(self, other: object) -> bool:
|
|
42
|
+
"""Checks equality between two InfoSize instances
|
|
43
|
+
based on their total size in bits."""
|
|
44
|
+
if not isinstance(other, InfoSize):
|
|
45
|
+
return NotImplemented
|
|
46
|
+
return self.bits == other.bits
|
|
47
|
+
|
|
48
|
+
def __lt__(self, other: "InfoSize") -> bool:
|
|
49
|
+
"""Compares two InfoSize instances based on their total size in bits."""
|
|
50
|
+
return self.bits < other.bits
|
|
51
|
+
|
|
34
52
|
@property
|
|
35
53
|
def bits(self) -> int:
|
|
36
54
|
"""Returns the total size in bits."""
|
|
37
|
-
return (
|
|
55
|
+
return (self.byte << 3) | self.bit
|
|
38
56
|
|
|
39
57
|
@property
|
|
40
58
|
def bytes(self) -> int:
|
|
41
59
|
"""Returns the total size in bytes,
|
|
42
60
|
rounding up if there are leftover bits."""
|
|
43
|
-
return (
|
|
61
|
+
return (self.bits + 7) >> 3
|
|
44
62
|
|
|
45
63
|
@property
|
|
46
64
|
def hex_digits(self) -> int:
|
|
47
65
|
"""Returns the number of hexadecimal digits
|
|
48
66
|
needed to represent the size in bits."""
|
|
49
|
-
return
|
|
67
|
+
return self.bits >> 2
|
|
50
68
|
|
|
51
69
|
@property
|
|
52
70
|
def mask(self) -> int:
|
|
@@ -70,6 +88,7 @@ class InfoSize:
|
|
|
70
88
|
return InfoSize(0, total_bits)
|
|
71
89
|
|
|
72
90
|
|
|
91
|
+
@total_ordering
|
|
73
92
|
@dataclass(frozen=True)
|
|
74
93
|
class Info:
|
|
75
94
|
"""Represents a slice of bits extracted from a bytearray,
|
|
@@ -78,6 +97,28 @@ class Info:
|
|
|
78
97
|
info_size: InfoSize = field(default_factory=InfoSize,
|
|
79
98
|
metadata={"desc": "size information"})
|
|
80
99
|
|
|
100
|
+
def __str__(self) -> str:
|
|
101
|
+
"""Returns a string representation of the Info instance,
|
|
102
|
+
showing the raw value and its size."""
|
|
103
|
+
return f"Info(raw_value={self.raw_value}, info_size={self.info_size})"
|
|
104
|
+
|
|
105
|
+
def __eq__(self, other: object) -> bool:
|
|
106
|
+
"""Checks equality between two Info instances based on their raw values
|
|
107
|
+
and size information."""
|
|
108
|
+
if not isinstance(other, Info):
|
|
109
|
+
return NotImplemented
|
|
110
|
+
return (self.raw_value == other.raw_value
|
|
111
|
+
and self.info_size == other.info_size)
|
|
112
|
+
|
|
113
|
+
def __lt__(self, other: "Info") -> bool:
|
|
114
|
+
"""Compares two Info instances based on their raw values
|
|
115
|
+
and size information."""
|
|
116
|
+
if not isinstance(other, Info):
|
|
117
|
+
return NotImplemented
|
|
118
|
+
if self.info_size != other.info_size:
|
|
119
|
+
return self.info_size < other.info_size
|
|
120
|
+
return self.raw_value < other.raw_value
|
|
121
|
+
|
|
81
122
|
@classmethod
|
|
82
123
|
def from_int(cls, value: int, size: InfoSize):
|
|
83
124
|
"""Creates an Info instance from an integer value, ensuring that
|
|
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
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|