sltcore 0.2.1__tar.gz → 0.2.2__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.2/PKG-INFO ADDED
@@ -0,0 +1,151 @@
1
+ Metadata-Version: 2.4
2
+ Name: sltcore
3
+ Version: 0.2.2
4
+ Summary: A toolkit for handling structured data layouts and bit-level operations.
5
+ Project-URL: Homepage, https://github.com/fangface-hub/StructLayoutToolkitCore
6
+ Project-URL: Documentation, https://readthedocs.org
7
+ Project-URL: Repository, https://github.com/fangface-hub/StructLayoutToolkitCore
8
+ Project-URL: Issues, https://github.com/fangface-hub/StructLayoutToolkitCore/issues
9
+ Author: fangface
10
+ License-Expression: MIT
11
+ License-File: LICENSE
12
+ Keywords: bit,byte,data,deserialization,layout,serialization,struct
13
+ Requires-Python: >=3.12
14
+ Description-Content-Type: text/markdown
15
+
16
+ # StructLayoutToolkitCore
17
+
18
+ stlcore is a minimal, high‑cohesion core library for bit‑accurate binary slicing. It provides the fundamental primitives (bits_get, bits_set, InfoSize) required to build struct layout analyzers, binary editors, protocol inspectors, and low‑level testing tools. Designed for clarity, correctness, and composability.
19
+
20
+ ## What You Can Do After Installing sltcore
21
+
22
+ sltcore provides a minimal and consistent bit-level abstraction layer for building higher‑level tools such as binary editors, protocol analyzers, and structured layout systems.
23
+
24
+ After installing the package, you can:
25
+
26
+ - Extract arbitrary bit ranges from a bytearray using bits_get
27
+ - Write arbitrary bit ranges into a bytearray using bits_set
28
+ - Represent sizes and offsets uniformly with InfoSize
29
+ - Build structured binary layouts on top of a stable bit‑operation core
30
+
31
+ ## Quick Examples: bits_get / bits_set
32
+
33
+ ```python
34
+
35
+ from sltcore import InfoSize, Info , bits_get, bits_set
36
+
37
+ buf = bytearray(b"\x12\x34\x56\x78")
38
+
39
+ # Extract 4 bits at offset (1 byte, 0 bits)
40
+ value = bits_get(buf, InfoSize(1, 0), InfoSize(0, 4))
41
+ print(value.to_hex) # 0x3
42
+
43
+ # Write 5 bits at offset (2 bytes, 3 bits)
44
+ bits_set(buf, InfoSize(2, 3), InfoSize(0, 5), 0b10101)
45
+ print(buf.hex()) # 12345578
46
+
47
+ ```
48
+
49
+ ## sltcore.InfoSize
50
+
51
+ InfoSize is a type that represents offsets and sizes in a unified way.
52
+ It supports addition and subtraction, and stores both byte and bit components.
53
+
54
+ It is used for both offset and size, allowing consistent structural layout definitions.
55
+
56
+ - __Field List__
57
+
58
+ | Field | Type | Description |
59
+ | --- | --- | --- |
60
+ | byte | int | the byte size |
61
+ | bit | int | the bit size (0–7)<br> always normalized so that bit < 8 |
62
+
63
+ - __Property List__
64
+
65
+ | Property | Type | Description |
66
+ | --- | --- | --- |
67
+ | bits | int | Total bit length.<br> This property converts the stored byte and bit components into a single bit count using the formula byte * 8 + bit |
68
+ | bytes | int | Total byte length.<br> This property converts the combined bit length (byte * 8 + bit) into a byte count using integer division (bits // 8) |
69
+ | hex_digits | int | Number of hexadecimal digits needed to represent the field.<br>Since one hex digit corresponds to 4 bits, the value is calculated as ceil(bits / 4) |
70
+ | mask | int | Bitmask for the field size.<br>It produces a mask that covers exactly bits bits, using the formula (1 << bits) - 1.<br>This mask is typically used for extracting or normalizing values. |
71
+
72
+ ## sltcore.Info
73
+
74
+ Info stores an InfoSize and a raw integer value.
75
+
76
+ This allows higher‑level code to treat extracted fields as structured units rather than plain integers.
77
+
78
+ - __Field List__
79
+
80
+ | Field | Type | Description |
81
+ | --- | --- | --- |
82
+ | raw_value | int | The internal integer representation of the field.<br>It is obtained by converting the corresponding bytes into an integer and applying the size mask so that the value fits within the bit width specified by InfoSize. |
83
+ | info_size | InfoSize | Size descriptor for this value.<br>It provides the byte and bit length of the field and determines how the raw_value is masked, extracted, and written back into the byte sequence. |
84
+
85
+ - __Classmethod List__
86
+
87
+ | Classmethod | Description |
88
+ | --- | --- |
89
+ | from_int | Creates an Info instance from an integer value, ensuring that the value fits within the specified size by applying a bitmask. |
90
+ | from_bytes | Creates an Info instance from a bytes object, ensuring that the value fits within the specified size by applying a bitmask. |
91
+ | from_bytearray | Creates an Info instance from a bytearray, ensuring that the value fits within the specified size by applying a bitmask. |
92
+ | from_float | Creates an Info instance from a float value, converting it to its raw bit representation based on the specified size. |
93
+
94
+ Example: Creating an Info from a float value
95
+
96
+ ```python
97
+ size = InfoSize(byte=0, bit=32) # 32-bit float
98
+ info = Info.from_float(3.14, size)
99
+
100
+ print(info.raw_value) # IEEE754 raw bits (e.g., 0x4048F5C3)
101
+ print(info.info_size.bits) # 32
102
+ ```
103
+
104
+ - __Property List__
105
+
106
+ | Property | Type | Description |
107
+ | --- | --- | --- |
108
+ | to_unsigned_int | int | Returns the extracted bits as an unsigned integer. |
109
+ | to_signed_int | int | Returns the extracted bits as a signed integer. |
110
+ | to_hex | str | Returns the extracted bits as a hexadecimal string. |
111
+ | to_bytes | bytes | Returns the extracted bits as a bytes object. |
112
+ | to_bool | bool | Returns the extracted bits as a boolean value. |
113
+ | to_float | float | Returns the extracted bits as a float. |
114
+ | byte_swap | Info | Returns a new Info instance with the byte order reversed. |
115
+
116
+ ## sltcore.bits_get
117
+
118
+ bits_get extracts a field from a bytearray using an offset and size, and returns an Info object.
119
+
120
+ Input:
121
+
122
+ - bytearray buffer
123
+ - InfoSize offset
124
+ - InfoSize size
125
+
126
+ Output:
127
+
128
+ - Info containing the extracted value and its size
129
+
130
+ ## sltcore.bits_set
131
+
132
+ bits_set writes a value into a bytearray at the specified offset.
133
+
134
+ Input:
135
+
136
+ - bytearray buffer
137
+ - InfoSize offset
138
+ - Info value (which includes its size)
139
+
140
+ The function masks and replaces the target bit range inside the buffer.
141
+
142
+ ## Documentation
143
+
144
+ For detailed usage, examples, and parameter descriptions, refer to the docstrings via:
145
+
146
+ python
147
+
148
+ - help(sltcore.InfoSize)
149
+ - help(sltcore.Info)
150
+ - help(sltcore.bits_get)
151
+ - help(sltcore.bits_set)
@@ -0,0 +1,136 @@
1
+ # StructLayoutToolkitCore
2
+
3
+ stlcore is a minimal, high‑cohesion core library for bit‑accurate binary slicing. It provides the fundamental primitives (bits_get, bits_set, InfoSize) required to build struct layout analyzers, binary editors, protocol inspectors, and low‑level testing tools. Designed for clarity, correctness, and composability.
4
+
5
+ ## What You Can Do After Installing sltcore
6
+
7
+ sltcore provides a minimal and consistent bit-level abstraction layer for building higher‑level tools such as binary editors, protocol analyzers, and structured layout systems.
8
+
9
+ After installing the package, you can:
10
+
11
+ - Extract arbitrary bit ranges from a bytearray using bits_get
12
+ - Write arbitrary bit ranges into a bytearray using bits_set
13
+ - Represent sizes and offsets uniformly with InfoSize
14
+ - Build structured binary layouts on top of a stable bit‑operation core
15
+
16
+ ## Quick Examples: bits_get / bits_set
17
+
18
+ ```python
19
+
20
+ from sltcore import InfoSize, Info , bits_get, bits_set
21
+
22
+ buf = bytearray(b"\x12\x34\x56\x78")
23
+
24
+ # Extract 4 bits at offset (1 byte, 0 bits)
25
+ value = bits_get(buf, InfoSize(1, 0), InfoSize(0, 4))
26
+ print(value.to_hex) # 0x3
27
+
28
+ # Write 5 bits at offset (2 bytes, 3 bits)
29
+ bits_set(buf, InfoSize(2, 3), InfoSize(0, 5), 0b10101)
30
+ print(buf.hex()) # 12345578
31
+
32
+ ```
33
+
34
+ ## sltcore.InfoSize
35
+
36
+ InfoSize is a type that represents offsets and sizes in a unified way.
37
+ It supports addition and subtraction, and stores both byte and bit components.
38
+
39
+ It is used for both offset and size, allowing consistent structural layout definitions.
40
+
41
+ - __Field List__
42
+
43
+ | Field | Type | Description |
44
+ | --- | --- | --- |
45
+ | byte | int | the byte size |
46
+ | bit | int | the bit size (0–7)<br> always normalized so that bit < 8 |
47
+
48
+ - __Property List__
49
+
50
+ | Property | Type | Description |
51
+ | --- | --- | --- |
52
+ | bits | int | Total bit length.<br> This property converts the stored byte and bit components into a single bit count using the formula byte * 8 + bit |
53
+ | bytes | int | Total byte length.<br> This property converts the combined bit length (byte * 8 + bit) into a byte count using integer division (bits // 8) |
54
+ | hex_digits | int | Number of hexadecimal digits needed to represent the field.<br>Since one hex digit corresponds to 4 bits, the value is calculated as ceil(bits / 4) |
55
+ | mask | int | Bitmask for the field size.<br>It produces a mask that covers exactly bits bits, using the formula (1 << bits) - 1.<br>This mask is typically used for extracting or normalizing values. |
56
+
57
+ ## sltcore.Info
58
+
59
+ Info stores an InfoSize and a raw integer value.
60
+
61
+ This allows higher‑level code to treat extracted fields as structured units rather than plain integers.
62
+
63
+ - __Field List__
64
+
65
+ | Field | Type | Description |
66
+ | --- | --- | --- |
67
+ | raw_value | int | The internal integer representation of the field.<br>It is obtained by converting the corresponding bytes into an integer and applying the size mask so that the value fits within the bit width specified by InfoSize. |
68
+ | info_size | InfoSize | Size descriptor for this value.<br>It provides the byte and bit length of the field and determines how the raw_value is masked, extracted, and written back into the byte sequence. |
69
+
70
+ - __Classmethod List__
71
+
72
+ | Classmethod | Description |
73
+ | --- | --- |
74
+ | from_int | Creates an Info instance from an integer value, ensuring that the value fits within the specified size by applying a bitmask. |
75
+ | from_bytes | Creates an Info instance from a bytes object, ensuring that the value fits within the specified size by applying a bitmask. |
76
+ | from_bytearray | Creates an Info instance from a bytearray, ensuring that the value fits within the specified size by applying a bitmask. |
77
+ | from_float | Creates an Info instance from a float value, converting it to its raw bit representation based on the specified size. |
78
+
79
+ Example: Creating an Info from a float value
80
+
81
+ ```python
82
+ size = InfoSize(byte=0, bit=32) # 32-bit float
83
+ info = Info.from_float(3.14, size)
84
+
85
+ print(info.raw_value) # IEEE754 raw bits (e.g., 0x4048F5C3)
86
+ print(info.info_size.bits) # 32
87
+ ```
88
+
89
+ - __Property List__
90
+
91
+ | Property | Type | Description |
92
+ | --- | --- | --- |
93
+ | to_unsigned_int | int | Returns the extracted bits as an unsigned integer. |
94
+ | to_signed_int | int | Returns the extracted bits as a signed integer. |
95
+ | to_hex | str | Returns the extracted bits as a hexadecimal string. |
96
+ | to_bytes | bytes | Returns the extracted bits as a bytes object. |
97
+ | to_bool | bool | Returns the extracted bits as a boolean value. |
98
+ | to_float | float | Returns the extracted bits as a float. |
99
+ | byte_swap | Info | Returns a new Info instance with the byte order reversed. |
100
+
101
+ ## sltcore.bits_get
102
+
103
+ bits_get extracts a field from a bytearray using an offset and size, and returns an Info object.
104
+
105
+ Input:
106
+
107
+ - bytearray buffer
108
+ - InfoSize offset
109
+ - InfoSize size
110
+
111
+ Output:
112
+
113
+ - Info containing the extracted value and its size
114
+
115
+ ## sltcore.bits_set
116
+
117
+ bits_set writes a value into a bytearray at the specified offset.
118
+
119
+ Input:
120
+
121
+ - bytearray buffer
122
+ - InfoSize offset
123
+ - Info value (which includes its size)
124
+
125
+ The function masks and replaces the target bit range inside the buffer.
126
+
127
+ ## Documentation
128
+
129
+ For detailed usage, examples, and parameter descriptions, refer to the docstrings via:
130
+
131
+ python
132
+
133
+ - help(sltcore.InfoSize)
134
+ - help(sltcore.Info)
135
+ - help(sltcore.bits_get)
136
+ - help(sltcore.bits_set)
@@ -1,6 +1,6 @@
1
1
  [project]
2
2
  name = "sltcore"
3
- version = "0.2.1"
3
+ version = "0.2.2"
4
4
  license = "MIT"
5
5
  license-files = ["LICENSE"]
6
6
  description = "A toolkit for handling structured data layouts and bit-level operations."
@@ -0,0 +1,4 @@
1
+ from .bits import bits_get, bits_set
2
+ from .types import Info, InfoSize
3
+
4
+ __all__ = ["bits_get", "bits_set", "InfoSize", "Info"]
@@ -1,13 +1,13 @@
1
1
  """Type definitions for structured data layouts and bit-level operations."""
2
2
  import math
3
- from dataclasses import dataclass
3
+ from dataclasses import dataclass, field
4
4
 
5
5
 
6
6
  @dataclass(frozen=True)
7
7
  class InfoSize:
8
8
  """Represents a size in bytes and bits."""
9
- byte: int = 0
10
- bit: int = 0
9
+ byte: int = field(default=0, metadata={"desc": "byte size"})
10
+ bit: int = field(default=0, metadata={"desc": "bit size"})
11
11
 
12
12
  def __post_init__(self):
13
13
  """Ensures that the bit count is normalized to be less than 8,
@@ -59,8 +59,9 @@ class InfoSize:
59
59
  class Info:
60
60
  """Represents a slice of bits extracted from a bytearray,
61
61
  along with its size information."""
62
- raw_value: int
63
- info_size: InfoSize
62
+ raw_value: int = field(default=0, metadata={"desc": "raw integer value"})
63
+ info_size: InfoSize = field(default_factory=InfoSize,
64
+ metadata={"desc": "size information"})
64
65
 
65
66
  @classmethod
66
67
  def from_int(cls, value: int, size: InfoSize):
sltcore-0.2.1/PKG-INFO DELETED
@@ -1,106 +0,0 @@
1
- Metadata-Version: 2.4
2
- Name: sltcore
3
- Version: 0.2.1
4
- Summary: A toolkit for handling structured data layouts and bit-level operations.
5
- Project-URL: Homepage, https://github.com/fangface-hub/StructLayoutToolkitCore
6
- Project-URL: Documentation, https://readthedocs.org
7
- Project-URL: Repository, https://github.com/fangface-hub/StructLayoutToolkitCore
8
- Project-URL: Issues, https://github.com/fangface-hub/StructLayoutToolkitCore/issues
9
- Author: fangface
10
- License-Expression: MIT
11
- License-File: LICENSE
12
- Keywords: bit,byte,data,deserialization,layout,serialization,struct
13
- Requires-Python: >=3.12
14
- Description-Content-Type: text/markdown
15
-
16
- # StructLayoutToolkitCore
17
-
18
- stlcore is a minimal, high‑cohesion core library for bit‑accurate binary slicing. It provides the fundamental primitives (bits_get, bits_set, InfoSize) required to build struct layout analyzers, binary editors, protocol inspectors, and low‑level testing tools. Designed for clarity, correctness, and composability.
19
-
20
- ## What You Can Do After Installing sltcore
21
-
22
- sltcore provides a minimal and consistent bit-level abstraction layer for building higher‑level tools such as binary editors, protocol analyzers, and structured layout systems.
23
-
24
- After installing the package, you can:
25
-
26
- - Extract arbitrary bit ranges from a bytearray using bits_get
27
- - Write arbitrary bit ranges into a bytearray using bits_set
28
- - Represent sizes and offsets uniformly with InfoSize
29
- - Build structured binary layouts on top of a stable bit‑operation core
30
-
31
- ## Quick Examples: bits_get / bits_set
32
-
33
- ```python
34
-
35
- from sltcore.types import InfoSize, Info
36
- from sltcore.bits import bits_get, bits_set
37
-
38
- buf = bytearray(b"\x12\x34\x56\x78")
39
-
40
- # Extract 4 bits at offset (1 byte, 0 bits)
41
- value = bits_get(buf, InfoSize(1, 0), InfoSize(0, 4))
42
- print(value.to_hex) # 0x3
43
-
44
- # Write 5 bits at offset (2 bytes, 3 bits)
45
- bits_set(buf, InfoSize(2, 3), InfoSize(0, 5), 0b10101)
46
- print(buf.hex()) # 12345578
47
-
48
- ```
49
-
50
- ## sltcore.type.InfoSize
51
-
52
- InfoSize is a type that represents offsets and sizes in a unified way.
53
- It supports addition and subtraction, and stores both byte and bit components.
54
-
55
- - byte: the byte component
56
- - bit: the bit component (0–7)
57
-
58
- always normalized so that bit < 8
59
-
60
- It is used for both offset and size, allowing consistent structural layout definitions.
61
-
62
- ## sltcore.type.Info
63
-
64
- Info stores an InfoSize and a raw integer value.
65
-
66
- - The value returned by bits_get is an Info instance
67
- - The value passed to bits_set is also an Info instance
68
-
69
- This allows higher‑level code to treat extracted fields as structured units rather than plain integers.
70
-
71
- ## sltcore.bits.bits_get
72
-
73
- bits_get extracts a field from a bytearray using an offset and size, and returns an Info object.
74
-
75
- Input:
76
-
77
- - bytearray buffer
78
- - InfoSize offset
79
- - InfoSize size
80
-
81
- Output:
82
-
83
- - Info containing the extracted value and its size
84
-
85
- ## sltcore.bits.bits_set
86
-
87
- bits_set writes a value into a bytearray at the specified offset.
88
-
89
- Input:
90
-
91
- - bytearray buffer
92
- - InfoSize offset
93
- - Info value (which includes its size)
94
-
95
- The function masks and replaces the target bit range inside the buffer.
96
-
97
- ## Documentation
98
-
99
- For detailed usage, examples, and parameter descriptions, refer to the docstrings via:
100
-
101
- python
102
-
103
- - help(sltcore.type.InfoSize)
104
- - help(sltcore.type.Info)
105
- - help(sltcore.bits.bits_get)
106
- - help(sltcore.bits.bits_set)
sltcore-0.2.1/README.md DELETED
@@ -1,91 +0,0 @@
1
- # StructLayoutToolkitCore
2
-
3
- stlcore is a minimal, high‑cohesion core library for bit‑accurate binary slicing. It provides the fundamental primitives (bits_get, bits_set, InfoSize) required to build struct layout analyzers, binary editors, protocol inspectors, and low‑level testing tools. Designed for clarity, correctness, and composability.
4
-
5
- ## What You Can Do After Installing sltcore
6
-
7
- sltcore provides a minimal and consistent bit-level abstraction layer for building higher‑level tools such as binary editors, protocol analyzers, and structured layout systems.
8
-
9
- After installing the package, you can:
10
-
11
- - Extract arbitrary bit ranges from a bytearray using bits_get
12
- - Write arbitrary bit ranges into a bytearray using bits_set
13
- - Represent sizes and offsets uniformly with InfoSize
14
- - Build structured binary layouts on top of a stable bit‑operation core
15
-
16
- ## Quick Examples: bits_get / bits_set
17
-
18
- ```python
19
-
20
- from sltcore.types import InfoSize, Info
21
- from sltcore.bits import bits_get, bits_set
22
-
23
- buf = bytearray(b"\x12\x34\x56\x78")
24
-
25
- # Extract 4 bits at offset (1 byte, 0 bits)
26
- value = bits_get(buf, InfoSize(1, 0), InfoSize(0, 4))
27
- print(value.to_hex) # 0x3
28
-
29
- # Write 5 bits at offset (2 bytes, 3 bits)
30
- bits_set(buf, InfoSize(2, 3), InfoSize(0, 5), 0b10101)
31
- print(buf.hex()) # 12345578
32
-
33
- ```
34
-
35
- ## sltcore.type.InfoSize
36
-
37
- InfoSize is a type that represents offsets and sizes in a unified way.
38
- It supports addition and subtraction, and stores both byte and bit components.
39
-
40
- - byte: the byte component
41
- - bit: the bit component (0–7)
42
-
43
- always normalized so that bit < 8
44
-
45
- It is used for both offset and size, allowing consistent structural layout definitions.
46
-
47
- ## sltcore.type.Info
48
-
49
- Info stores an InfoSize and a raw integer value.
50
-
51
- - The value returned by bits_get is an Info instance
52
- - The value passed to bits_set is also an Info instance
53
-
54
- This allows higher‑level code to treat extracted fields as structured units rather than plain integers.
55
-
56
- ## sltcore.bits.bits_get
57
-
58
- bits_get extracts a field from a bytearray using an offset and size, and returns an Info object.
59
-
60
- Input:
61
-
62
- - bytearray buffer
63
- - InfoSize offset
64
- - InfoSize size
65
-
66
- Output:
67
-
68
- - Info containing the extracted value and its size
69
-
70
- ## sltcore.bits.bits_set
71
-
72
- bits_set writes a value into a bytearray at the specified offset.
73
-
74
- Input:
75
-
76
- - bytearray buffer
77
- - InfoSize offset
78
- - Info value (which includes its size)
79
-
80
- The function masks and replaces the target bit range inside the buffer.
81
-
82
- ## Documentation
83
-
84
- For detailed usage, examples, and parameter descriptions, refer to the docstrings via:
85
-
86
- python
87
-
88
- - help(sltcore.type.InfoSize)
89
- - help(sltcore.type.Info)
90
- - help(sltcore.bits.bits_get)
91
- - help(sltcore.bits.bits_set)
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