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.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: sltcore
3
- Version: 0.2.3
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
@@ -1,6 +1,6 @@
1
1
  [project]
2
2
  name = "sltcore"
3
- version = "0.2.3"
3
+ version = "0.2.4"
4
4
  license = "MIT"
5
5
  license-files = ["LICENSE"]
6
6
  description = "A toolkit for handling structured data layouts and bit-level operations."
@@ -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 ((self.byte << 3) | self.bit)
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 ((self.bits + 7) >> 3) # round up
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 (self.bits >> 2)
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
@@ -65,7 +65,7 @@ wheels = [
65
65
 
66
66
  [[package]]
67
67
  name = "sltcore"
68
- version = "0.2.2"
68
+ version = "0.2.3"
69
69
  source = { editable = "." }
70
70
 
71
71
  [package.dev-dependencies]
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