xvcio 0.0.0__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.
- xvcio-0.0.0/.gitignore +43 -0
- xvcio-0.0.0/LICENSE.txt +9 -0
- xvcio-0.0.0/PKG-INFO +265 -0
- xvcio-0.0.0/README.md +246 -0
- xvcio-0.0.0/pyproject.toml +45 -0
- xvcio-0.0.0/xvcio/__init__.py +0 -0
xvcio-0.0.0/.gitignore
ADDED
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
__pycache__/
|
|
2
|
+
*.py[cod]
|
|
3
|
+
*$py.class
|
|
4
|
+
|
|
5
|
+
# Python build artifacts
|
|
6
|
+
.pytest_cache/
|
|
7
|
+
.venv/
|
|
8
|
+
venv/
|
|
9
|
+
env/
|
|
10
|
+
ENV/
|
|
11
|
+
dist/
|
|
12
|
+
build/
|
|
13
|
+
*.egg-info/
|
|
14
|
+
.eggs/
|
|
15
|
+
wheels/
|
|
16
|
+
pip-wheel-metadata/
|
|
17
|
+
|
|
18
|
+
# Test and coverage output
|
|
19
|
+
.coverage
|
|
20
|
+
.coverage.*
|
|
21
|
+
htmlcov/
|
|
22
|
+
.tox/
|
|
23
|
+
.nox/
|
|
24
|
+
.hypothesis/
|
|
25
|
+
|
|
26
|
+
# Type checker and tool caches
|
|
27
|
+
.mypy_cache/
|
|
28
|
+
.pyre/
|
|
29
|
+
.ruff_cache/
|
|
30
|
+
.cache/
|
|
31
|
+
|
|
32
|
+
# Editors and OS files
|
|
33
|
+
.idea/
|
|
34
|
+
.vscode/
|
|
35
|
+
*.swp
|
|
36
|
+
*.swo
|
|
37
|
+
.DS_Store
|
|
38
|
+
Thumbs.db
|
|
39
|
+
|
|
40
|
+
# Logs and local environment
|
|
41
|
+
*.log
|
|
42
|
+
.env
|
|
43
|
+
.env.*
|
xvcio-0.0.0/LICENSE.txt
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Anthony Donlon
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
|
6
|
+
|
|
7
|
+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
|
8
|
+
|
|
9
|
+
THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
xvcio-0.0.0/PKG-INFO
ADDED
|
@@ -0,0 +1,265 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: xvcio
|
|
3
|
+
Version: 0.0.0
|
|
4
|
+
Summary: Protocol library for Xilinx Virtual Cable (XVC).
|
|
5
|
+
Author: Anthony Donlon
|
|
6
|
+
License: MIT
|
|
7
|
+
License-File: LICENSE.txt
|
|
8
|
+
Classifier: Programming Language :: Python :: 3
|
|
9
|
+
Classifier: Programming Language :: Python :: 3 :: Only
|
|
10
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
11
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
12
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
13
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
14
|
+
Classifier: Programming Language :: Python :: 3.14
|
|
15
|
+
Requires-Python: >=3.10
|
|
16
|
+
Provides-Extra: test
|
|
17
|
+
Requires-Dist: pytest>=8; extra == 'test'
|
|
18
|
+
Description-Content-Type: text/markdown
|
|
19
|
+
|
|
20
|
+
# bitbuf
|
|
21
|
+
|
|
22
|
+
A fast and lightweight bit-level mutation library for Python.
|
|
23
|
+
|
|
24
|
+
> Notice: `bitbuf` is currently a beta proof of concept. The public API is
|
|
25
|
+
> still settling, and performance is not fully optimized yet. A future version
|
|
26
|
+
> is expected to optimize the internal implementation with a native programming
|
|
27
|
+
> language backend.
|
|
28
|
+
|
|
29
|
+
## Installation
|
|
30
|
+
|
|
31
|
+
```bash
|
|
32
|
+
pip install bitbuf
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
## Quick Start
|
|
36
|
+
|
|
37
|
+
```python
|
|
38
|
+
from bitbuf import bitbuf
|
|
39
|
+
|
|
40
|
+
buf = bitbuf.from_bytes(b"\x34\x12")
|
|
41
|
+
|
|
42
|
+
buf[4:12] = 0xAB
|
|
43
|
+
buf <<= 3
|
|
44
|
+
buf.append_msb(0b1010, 4)
|
|
45
|
+
|
|
46
|
+
value = int(buf)
|
|
47
|
+
payload = bytes(buf)
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
Bit position `0` is the least significant bit. Byte conversion always uses
|
|
51
|
+
little-endian order.
|
|
52
|
+
|
|
53
|
+
## Examples
|
|
54
|
+
|
|
55
|
+
### Create Buffers
|
|
56
|
+
|
|
57
|
+
```python
|
|
58
|
+
from bitbuf import bitbuf
|
|
59
|
+
|
|
60
|
+
empty = bitbuf()
|
|
61
|
+
fixed = bitbuf(0b1010_0101, 8)
|
|
62
|
+
from_int = bitbuf.from_int(0x1234, size=16)
|
|
63
|
+
from_bytes = bitbuf.from_bytes(b"\x34\x12")
|
|
64
|
+
zeros = bitbuf.zeros(16)
|
|
65
|
+
ones = bitbuf.ones(8)
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
### Read and Write Bits
|
|
69
|
+
|
|
70
|
+
```python
|
|
71
|
+
buf = bitbuf(0b1010_0101, 8)
|
|
72
|
+
|
|
73
|
+
lowest = buf[0] # 1
|
|
74
|
+
highest = buf[-1] # 1
|
|
75
|
+
buf[1] = 1 # set bit 1
|
|
76
|
+
buf.set_bit(7, 0) # clear bit 7
|
|
77
|
+
```
|
|
78
|
+
|
|
79
|
+
### Read and Write Bit Ranges
|
|
80
|
+
|
|
81
|
+
Slices use `[start:stop]`, where `start` is the LSB-first bit position and
|
|
82
|
+
`stop - start` is the width.
|
|
83
|
+
|
|
84
|
+
```python
|
|
85
|
+
buf = bitbuf(0x1234, 16)
|
|
86
|
+
|
|
87
|
+
field = buf[4:12]
|
|
88
|
+
field_bytes = buf.get_bits_as_bytes(4, 8)
|
|
89
|
+
field_bytearray = buf.get_bits_as_bytearray(4, 8)
|
|
90
|
+
field_slice = buf.slice(4, 8) # return a slice as bitbuf
|
|
91
|
+
buf[4:12] = 0xAB
|
|
92
|
+
|
|
93
|
+
same_field = buf.get_bits(4, 8)
|
|
94
|
+
buf.set_bits(0, 0b1111, 4)
|
|
95
|
+
```
|
|
96
|
+
|
|
97
|
+
### Set or Clear Ranges
|
|
98
|
+
|
|
99
|
+
```python
|
|
100
|
+
buf = bitbuf(0, 8)
|
|
101
|
+
|
|
102
|
+
buf.set_ones(2, 4) # 0b0011_1100
|
|
103
|
+
buf.set_zeros(3, 2) # 0b0010_0100
|
|
104
|
+
```
|
|
105
|
+
|
|
106
|
+
### Shift In Place
|
|
107
|
+
|
|
108
|
+
All operations mutate the current buffer.
|
|
109
|
+
|
|
110
|
+
```python
|
|
111
|
+
buf = bitbuf(0b0000_1111, 8)
|
|
112
|
+
|
|
113
|
+
buf <<= 2 # same as buf.lshift(2)
|
|
114
|
+
buf >>= 1 # same as buf.rshift(1)
|
|
115
|
+
```
|
|
116
|
+
|
|
117
|
+
### Append and Delete Bits
|
|
118
|
+
|
|
119
|
+
```python
|
|
120
|
+
buf = bitbuf(0b0011, 4)
|
|
121
|
+
|
|
122
|
+
buf.append_high(0b101, 3) # 0b101_0011
|
|
123
|
+
buf.append_low(0b10, 2) # 0b1010011_10
|
|
124
|
+
|
|
125
|
+
buf.delete_low(2) # discard low bits
|
|
126
|
+
high = buf.pop_high(3) # remove and return high bits
|
|
127
|
+
```
|
|
128
|
+
|
|
129
|
+
### Replace or Clear Contents
|
|
130
|
+
|
|
131
|
+
```python
|
|
132
|
+
buf = bitbuf(0x1234, 16)
|
|
133
|
+
|
|
134
|
+
buf.assign(0xAB, 8)
|
|
135
|
+
buf.toggle() # flips all 8 bits
|
|
136
|
+
buf.clear() # keeps len(buf) == 8
|
|
137
|
+
```
|
|
138
|
+
|
|
139
|
+
### Convert Back to Python Types
|
|
140
|
+
|
|
141
|
+
```python
|
|
142
|
+
buf = bitbuf.from_bytes(b"\x34\x12")
|
|
143
|
+
|
|
144
|
+
as_int = int(buf)
|
|
145
|
+
as_bytes = bytes(buf)
|
|
146
|
+
as_bytearray = buf.bytearray()
|
|
147
|
+
as_hex = hex(buf)
|
|
148
|
+
|
|
149
|
+
assert as_int == buf.int()
|
|
150
|
+
assert as_bytes == buf.bytes()
|
|
151
|
+
assert as_bytearray == bytearray(as_bytes)
|
|
152
|
+
assert as_hex == buf.hex()
|
|
153
|
+
```
|
|
154
|
+
|
|
155
|
+
## API Reference
|
|
156
|
+
|
|
157
|
+
```python
|
|
158
|
+
input_types: TypeAlias = int | bytes | bytearray | memoryview | bitbuf
|
|
159
|
+
|
|
160
|
+
class bitbuf:
|
|
161
|
+
def __init__(self, value: input_types = 0, width: int | None = None) -> None: ...
|
|
162
|
+
# Create a mutable LSB-first buffer from an int, bytes-like object, or bitbuf.
|
|
163
|
+
|
|
164
|
+
@classmethod
|
|
165
|
+
def from_int(cls, data: int, width: int | None = None) -> bitbuf: ...
|
|
166
|
+
# Build a buffer from an integer, inferring width from bit_length when omitted.
|
|
167
|
+
@classmethod
|
|
168
|
+
def from_bytes(cls, data: bytes | bytearray | memoryview, width: int | None = None) -> bitbuf: ...
|
|
169
|
+
# Build a buffer from little-endian bytes-like data.
|
|
170
|
+
@classmethod
|
|
171
|
+
def zeros(cls, width: int) -> bitbuf: ...
|
|
172
|
+
# Build a zero-filled buffer with the requested width.
|
|
173
|
+
@classmethod
|
|
174
|
+
def ones(cls, width: int) -> bitbuf: ...
|
|
175
|
+
# Build a one-filled buffer with the requested width.
|
|
176
|
+
|
|
177
|
+
def __len__(self) -> int: ...
|
|
178
|
+
# Return width in bits.
|
|
179
|
+
def __int__(self) -> int: ...
|
|
180
|
+
# Convert the buffer to an integer.
|
|
181
|
+
def __index__(self) -> int: ...
|
|
182
|
+
# Allow numeric helpers such as hex(buf).
|
|
183
|
+
def __bytes__(self) -> bytes: ...
|
|
184
|
+
# Convert the buffer to little-endian bytes.
|
|
185
|
+
def __repr__(self) -> str: ...
|
|
186
|
+
# Return a concise debug representation with width and hex data.
|
|
187
|
+
def __getitem__(self, key: int | slice) -> int: ...
|
|
188
|
+
# Read one bit or an integer-valued bit range.
|
|
189
|
+
def __setitem__(self, key: int | slice, value: input_types) -> None: ...
|
|
190
|
+
# Write one bit or replace a bit range.
|
|
191
|
+
def __ilshift__(self, bits: int) -> bitbuf: ...
|
|
192
|
+
# Shift left in place.
|
|
193
|
+
def __irshift__(self, bits: int) -> bitbuf: ...
|
|
194
|
+
# Shift right in place.
|
|
195
|
+
|
|
196
|
+
def assign(self, value: input_types = 0, width: int | None = None) -> None: ...
|
|
197
|
+
# Replace the entire buffer contents and width.
|
|
198
|
+
def resize(self, width: int) -> None: ...
|
|
199
|
+
# Change width, trimming discarded high bits when shrinking.
|
|
200
|
+
def clear(self) -> None: ...
|
|
201
|
+
# Zero all bits while keeping the current width.
|
|
202
|
+
|
|
203
|
+
def get_bit(self, pos: int) -> int: ...
|
|
204
|
+
# Return one bit at the given LSB-first position.
|
|
205
|
+
def get_bits(self, pos: int, width: int) -> int: ...
|
|
206
|
+
# Return a bit range as an integer.
|
|
207
|
+
def get_bits_as_bytes(self, pos: int, width: int) -> bytes: ...
|
|
208
|
+
# Return a bit range as little-endian bytes.
|
|
209
|
+
def get_bits_as_bytearray(self, pos: int, width: int) -> bytearray: ...
|
|
210
|
+
# Return a bit range as little-endian bytearray.
|
|
211
|
+
def slice(self, pos: int, width: int) -> bitbuf: ...
|
|
212
|
+
# Return a bit range as a new bitbuf.
|
|
213
|
+
|
|
214
|
+
def set_bit(self, pos: int, value: int = 1) -> None: ...
|
|
215
|
+
# Set or clear one bit.
|
|
216
|
+
def set_bits(self, pos: int, value: input_types = 0, width: int | None = None) -> None: ...
|
|
217
|
+
# Replace a bit range with a sized value.
|
|
218
|
+
def set_ones(self, pos: int, width: int) -> None: ...
|
|
219
|
+
# Fill a bit range with ones.
|
|
220
|
+
def set_zeros(self, pos: int, width: int) -> None: ...
|
|
221
|
+
# Fill a bit range with zeros.
|
|
222
|
+
def toggle(self, pos: int = 0, width: int | None = None) -> None: ...
|
|
223
|
+
# Flip all bits from pos upward, or a specific range when width is given.
|
|
224
|
+
|
|
225
|
+
def lshift(self, bits: int) -> None: ...
|
|
226
|
+
# Shift bits toward the high side while preserving width.
|
|
227
|
+
def rshift(self, bits: int) -> None: ...
|
|
228
|
+
# Shift bits toward the low side while preserving width.
|
|
229
|
+
|
|
230
|
+
def append_low(self, value: input_types = 0, width: int | None = None) -> None: ...
|
|
231
|
+
# Grow the buffer by appending bits on the low side.
|
|
232
|
+
def append_high(self, value: input_types = 0, width: int | None = None) -> None: ...
|
|
233
|
+
# Grow the buffer by appending bits on the high side.
|
|
234
|
+
def delete_low(self, width: int) -> None: ...
|
|
235
|
+
# Discard low-side bits without returning them.
|
|
236
|
+
def delete_high(self, width: int) -> None: ...
|
|
237
|
+
# Discard high-side bits without returning them.
|
|
238
|
+
def pop_low(self, width: int) -> int: ...
|
|
239
|
+
# Remove and return low-side bits.
|
|
240
|
+
def pop_high(self, width: int) -> int: ...
|
|
241
|
+
# Remove and return high-side bits.
|
|
242
|
+
|
|
243
|
+
def bytearray(self) -> bytearray: ...
|
|
244
|
+
# Return the whole buffer as little-endian bytearray.
|
|
245
|
+
def bytes(self) -> bytes: ...
|
|
246
|
+
# Return the whole buffer as little-endian bytes.
|
|
247
|
+
def hex(self) -> str: ...
|
|
248
|
+
# Return hex(self.int()).
|
|
249
|
+
def int(self) -> int: ...
|
|
250
|
+
# Return the whole buffer as an integer.
|
|
251
|
+
|
|
252
|
+
@property
|
|
253
|
+
def width(self) -> int: ...
|
|
254
|
+
# Width of the buffer in bits.
|
|
255
|
+
@property
|
|
256
|
+
def size_bytes(self) -> int: ...
|
|
257
|
+
# Minimum byte count needed to store the buffer width.
|
|
258
|
+
```
|
|
259
|
+
|
|
260
|
+
## Development
|
|
261
|
+
|
|
262
|
+
```bash
|
|
263
|
+
python -m pip install -e ".[test]"
|
|
264
|
+
python -m pytest
|
|
265
|
+
```
|
xvcio-0.0.0/README.md
ADDED
|
@@ -0,0 +1,246 @@
|
|
|
1
|
+
# bitbuf
|
|
2
|
+
|
|
3
|
+
A fast and lightweight bit-level mutation library for Python.
|
|
4
|
+
|
|
5
|
+
> Notice: `bitbuf` is currently a beta proof of concept. The public API is
|
|
6
|
+
> still settling, and performance is not fully optimized yet. A future version
|
|
7
|
+
> is expected to optimize the internal implementation with a native programming
|
|
8
|
+
> language backend.
|
|
9
|
+
|
|
10
|
+
## Installation
|
|
11
|
+
|
|
12
|
+
```bash
|
|
13
|
+
pip install bitbuf
|
|
14
|
+
```
|
|
15
|
+
|
|
16
|
+
## Quick Start
|
|
17
|
+
|
|
18
|
+
```python
|
|
19
|
+
from bitbuf import bitbuf
|
|
20
|
+
|
|
21
|
+
buf = bitbuf.from_bytes(b"\x34\x12")
|
|
22
|
+
|
|
23
|
+
buf[4:12] = 0xAB
|
|
24
|
+
buf <<= 3
|
|
25
|
+
buf.append_msb(0b1010, 4)
|
|
26
|
+
|
|
27
|
+
value = int(buf)
|
|
28
|
+
payload = bytes(buf)
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
Bit position `0` is the least significant bit. Byte conversion always uses
|
|
32
|
+
little-endian order.
|
|
33
|
+
|
|
34
|
+
## Examples
|
|
35
|
+
|
|
36
|
+
### Create Buffers
|
|
37
|
+
|
|
38
|
+
```python
|
|
39
|
+
from bitbuf import bitbuf
|
|
40
|
+
|
|
41
|
+
empty = bitbuf()
|
|
42
|
+
fixed = bitbuf(0b1010_0101, 8)
|
|
43
|
+
from_int = bitbuf.from_int(0x1234, size=16)
|
|
44
|
+
from_bytes = bitbuf.from_bytes(b"\x34\x12")
|
|
45
|
+
zeros = bitbuf.zeros(16)
|
|
46
|
+
ones = bitbuf.ones(8)
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
### Read and Write Bits
|
|
50
|
+
|
|
51
|
+
```python
|
|
52
|
+
buf = bitbuf(0b1010_0101, 8)
|
|
53
|
+
|
|
54
|
+
lowest = buf[0] # 1
|
|
55
|
+
highest = buf[-1] # 1
|
|
56
|
+
buf[1] = 1 # set bit 1
|
|
57
|
+
buf.set_bit(7, 0) # clear bit 7
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
### Read and Write Bit Ranges
|
|
61
|
+
|
|
62
|
+
Slices use `[start:stop]`, where `start` is the LSB-first bit position and
|
|
63
|
+
`stop - start` is the width.
|
|
64
|
+
|
|
65
|
+
```python
|
|
66
|
+
buf = bitbuf(0x1234, 16)
|
|
67
|
+
|
|
68
|
+
field = buf[4:12]
|
|
69
|
+
field_bytes = buf.get_bits_as_bytes(4, 8)
|
|
70
|
+
field_bytearray = buf.get_bits_as_bytearray(4, 8)
|
|
71
|
+
field_slice = buf.slice(4, 8) # return a slice as bitbuf
|
|
72
|
+
buf[4:12] = 0xAB
|
|
73
|
+
|
|
74
|
+
same_field = buf.get_bits(4, 8)
|
|
75
|
+
buf.set_bits(0, 0b1111, 4)
|
|
76
|
+
```
|
|
77
|
+
|
|
78
|
+
### Set or Clear Ranges
|
|
79
|
+
|
|
80
|
+
```python
|
|
81
|
+
buf = bitbuf(0, 8)
|
|
82
|
+
|
|
83
|
+
buf.set_ones(2, 4) # 0b0011_1100
|
|
84
|
+
buf.set_zeros(3, 2) # 0b0010_0100
|
|
85
|
+
```
|
|
86
|
+
|
|
87
|
+
### Shift In Place
|
|
88
|
+
|
|
89
|
+
All operations mutate the current buffer.
|
|
90
|
+
|
|
91
|
+
```python
|
|
92
|
+
buf = bitbuf(0b0000_1111, 8)
|
|
93
|
+
|
|
94
|
+
buf <<= 2 # same as buf.lshift(2)
|
|
95
|
+
buf >>= 1 # same as buf.rshift(1)
|
|
96
|
+
```
|
|
97
|
+
|
|
98
|
+
### Append and Delete Bits
|
|
99
|
+
|
|
100
|
+
```python
|
|
101
|
+
buf = bitbuf(0b0011, 4)
|
|
102
|
+
|
|
103
|
+
buf.append_high(0b101, 3) # 0b101_0011
|
|
104
|
+
buf.append_low(0b10, 2) # 0b1010011_10
|
|
105
|
+
|
|
106
|
+
buf.delete_low(2) # discard low bits
|
|
107
|
+
high = buf.pop_high(3) # remove and return high bits
|
|
108
|
+
```
|
|
109
|
+
|
|
110
|
+
### Replace or Clear Contents
|
|
111
|
+
|
|
112
|
+
```python
|
|
113
|
+
buf = bitbuf(0x1234, 16)
|
|
114
|
+
|
|
115
|
+
buf.assign(0xAB, 8)
|
|
116
|
+
buf.toggle() # flips all 8 bits
|
|
117
|
+
buf.clear() # keeps len(buf) == 8
|
|
118
|
+
```
|
|
119
|
+
|
|
120
|
+
### Convert Back to Python Types
|
|
121
|
+
|
|
122
|
+
```python
|
|
123
|
+
buf = bitbuf.from_bytes(b"\x34\x12")
|
|
124
|
+
|
|
125
|
+
as_int = int(buf)
|
|
126
|
+
as_bytes = bytes(buf)
|
|
127
|
+
as_bytearray = buf.bytearray()
|
|
128
|
+
as_hex = hex(buf)
|
|
129
|
+
|
|
130
|
+
assert as_int == buf.int()
|
|
131
|
+
assert as_bytes == buf.bytes()
|
|
132
|
+
assert as_bytearray == bytearray(as_bytes)
|
|
133
|
+
assert as_hex == buf.hex()
|
|
134
|
+
```
|
|
135
|
+
|
|
136
|
+
## API Reference
|
|
137
|
+
|
|
138
|
+
```python
|
|
139
|
+
input_types: TypeAlias = int | bytes | bytearray | memoryview | bitbuf
|
|
140
|
+
|
|
141
|
+
class bitbuf:
|
|
142
|
+
def __init__(self, value: input_types = 0, width: int | None = None) -> None: ...
|
|
143
|
+
# Create a mutable LSB-first buffer from an int, bytes-like object, or bitbuf.
|
|
144
|
+
|
|
145
|
+
@classmethod
|
|
146
|
+
def from_int(cls, data: int, width: int | None = None) -> bitbuf: ...
|
|
147
|
+
# Build a buffer from an integer, inferring width from bit_length when omitted.
|
|
148
|
+
@classmethod
|
|
149
|
+
def from_bytes(cls, data: bytes | bytearray | memoryview, width: int | None = None) -> bitbuf: ...
|
|
150
|
+
# Build a buffer from little-endian bytes-like data.
|
|
151
|
+
@classmethod
|
|
152
|
+
def zeros(cls, width: int) -> bitbuf: ...
|
|
153
|
+
# Build a zero-filled buffer with the requested width.
|
|
154
|
+
@classmethod
|
|
155
|
+
def ones(cls, width: int) -> bitbuf: ...
|
|
156
|
+
# Build a one-filled buffer with the requested width.
|
|
157
|
+
|
|
158
|
+
def __len__(self) -> int: ...
|
|
159
|
+
# Return width in bits.
|
|
160
|
+
def __int__(self) -> int: ...
|
|
161
|
+
# Convert the buffer to an integer.
|
|
162
|
+
def __index__(self) -> int: ...
|
|
163
|
+
# Allow numeric helpers such as hex(buf).
|
|
164
|
+
def __bytes__(self) -> bytes: ...
|
|
165
|
+
# Convert the buffer to little-endian bytes.
|
|
166
|
+
def __repr__(self) -> str: ...
|
|
167
|
+
# Return a concise debug representation with width and hex data.
|
|
168
|
+
def __getitem__(self, key: int | slice) -> int: ...
|
|
169
|
+
# Read one bit or an integer-valued bit range.
|
|
170
|
+
def __setitem__(self, key: int | slice, value: input_types) -> None: ...
|
|
171
|
+
# Write one bit or replace a bit range.
|
|
172
|
+
def __ilshift__(self, bits: int) -> bitbuf: ...
|
|
173
|
+
# Shift left in place.
|
|
174
|
+
def __irshift__(self, bits: int) -> bitbuf: ...
|
|
175
|
+
# Shift right in place.
|
|
176
|
+
|
|
177
|
+
def assign(self, value: input_types = 0, width: int | None = None) -> None: ...
|
|
178
|
+
# Replace the entire buffer contents and width.
|
|
179
|
+
def resize(self, width: int) -> None: ...
|
|
180
|
+
# Change width, trimming discarded high bits when shrinking.
|
|
181
|
+
def clear(self) -> None: ...
|
|
182
|
+
# Zero all bits while keeping the current width.
|
|
183
|
+
|
|
184
|
+
def get_bit(self, pos: int) -> int: ...
|
|
185
|
+
# Return one bit at the given LSB-first position.
|
|
186
|
+
def get_bits(self, pos: int, width: int) -> int: ...
|
|
187
|
+
# Return a bit range as an integer.
|
|
188
|
+
def get_bits_as_bytes(self, pos: int, width: int) -> bytes: ...
|
|
189
|
+
# Return a bit range as little-endian bytes.
|
|
190
|
+
def get_bits_as_bytearray(self, pos: int, width: int) -> bytearray: ...
|
|
191
|
+
# Return a bit range as little-endian bytearray.
|
|
192
|
+
def slice(self, pos: int, width: int) -> bitbuf: ...
|
|
193
|
+
# Return a bit range as a new bitbuf.
|
|
194
|
+
|
|
195
|
+
def set_bit(self, pos: int, value: int = 1) -> None: ...
|
|
196
|
+
# Set or clear one bit.
|
|
197
|
+
def set_bits(self, pos: int, value: input_types = 0, width: int | None = None) -> None: ...
|
|
198
|
+
# Replace a bit range with a sized value.
|
|
199
|
+
def set_ones(self, pos: int, width: int) -> None: ...
|
|
200
|
+
# Fill a bit range with ones.
|
|
201
|
+
def set_zeros(self, pos: int, width: int) -> None: ...
|
|
202
|
+
# Fill a bit range with zeros.
|
|
203
|
+
def toggle(self, pos: int = 0, width: int | None = None) -> None: ...
|
|
204
|
+
# Flip all bits from pos upward, or a specific range when width is given.
|
|
205
|
+
|
|
206
|
+
def lshift(self, bits: int) -> None: ...
|
|
207
|
+
# Shift bits toward the high side while preserving width.
|
|
208
|
+
def rshift(self, bits: int) -> None: ...
|
|
209
|
+
# Shift bits toward the low side while preserving width.
|
|
210
|
+
|
|
211
|
+
def append_low(self, value: input_types = 0, width: int | None = None) -> None: ...
|
|
212
|
+
# Grow the buffer by appending bits on the low side.
|
|
213
|
+
def append_high(self, value: input_types = 0, width: int | None = None) -> None: ...
|
|
214
|
+
# Grow the buffer by appending bits on the high side.
|
|
215
|
+
def delete_low(self, width: int) -> None: ...
|
|
216
|
+
# Discard low-side bits without returning them.
|
|
217
|
+
def delete_high(self, width: int) -> None: ...
|
|
218
|
+
# Discard high-side bits without returning them.
|
|
219
|
+
def pop_low(self, width: int) -> int: ...
|
|
220
|
+
# Remove and return low-side bits.
|
|
221
|
+
def pop_high(self, width: int) -> int: ...
|
|
222
|
+
# Remove and return high-side bits.
|
|
223
|
+
|
|
224
|
+
def bytearray(self) -> bytearray: ...
|
|
225
|
+
# Return the whole buffer as little-endian bytearray.
|
|
226
|
+
def bytes(self) -> bytes: ...
|
|
227
|
+
# Return the whole buffer as little-endian bytes.
|
|
228
|
+
def hex(self) -> str: ...
|
|
229
|
+
# Return hex(self.int()).
|
|
230
|
+
def int(self) -> int: ...
|
|
231
|
+
# Return the whole buffer as an integer.
|
|
232
|
+
|
|
233
|
+
@property
|
|
234
|
+
def width(self) -> int: ...
|
|
235
|
+
# Width of the buffer in bits.
|
|
236
|
+
@property
|
|
237
|
+
def size_bytes(self) -> int: ...
|
|
238
|
+
# Minimum byte count needed to store the buffer width.
|
|
239
|
+
```
|
|
240
|
+
|
|
241
|
+
## Development
|
|
242
|
+
|
|
243
|
+
```bash
|
|
244
|
+
python -m pip install -e ".[test]"
|
|
245
|
+
python -m pytest
|
|
246
|
+
```
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
requires = ["hatchling"]
|
|
3
|
+
build-backend = "hatchling.build"
|
|
4
|
+
|
|
5
|
+
[project]
|
|
6
|
+
name = "xvcio"
|
|
7
|
+
version = "0.0.0"
|
|
8
|
+
description = "Protocol library for Xilinx Virtual Cable (XVC)."
|
|
9
|
+
readme = "README.md"
|
|
10
|
+
requires-python = ">=3.10"
|
|
11
|
+
license = { text = "MIT" }
|
|
12
|
+
authors = [
|
|
13
|
+
{ name = "Anthony Donlon" }
|
|
14
|
+
]
|
|
15
|
+
classifiers = [
|
|
16
|
+
"Programming Language :: Python :: 3",
|
|
17
|
+
"Programming Language :: Python :: 3 :: Only",
|
|
18
|
+
"Programming Language :: Python :: 3.10",
|
|
19
|
+
"Programming Language :: Python :: 3.11",
|
|
20
|
+
"Programming Language :: Python :: 3.12",
|
|
21
|
+
"Programming Language :: Python :: 3.13",
|
|
22
|
+
"Programming Language :: Python :: 3.14",
|
|
23
|
+
]
|
|
24
|
+
|
|
25
|
+
[project.optional-dependencies]
|
|
26
|
+
test = ["pytest>=8"]
|
|
27
|
+
|
|
28
|
+
[tool.pytest.ini_options]
|
|
29
|
+
addopts = "-p no:cacheprovider"
|
|
30
|
+
testpaths = ["tests"]
|
|
31
|
+
pythonpath = ["."]
|
|
32
|
+
|
|
33
|
+
[tool.hatch.build.targets.wheel]
|
|
34
|
+
packages = ["xvcio"]
|
|
35
|
+
|
|
36
|
+
[tool.ruff]
|
|
37
|
+
line-length = 120
|
|
38
|
+
target-version = "py310"
|
|
39
|
+
|
|
40
|
+
[tool.ruff.lint]
|
|
41
|
+
ignore = [
|
|
42
|
+
'E722', # Bare-except
|
|
43
|
+
]
|
|
44
|
+
|
|
45
|
+
[tool.ruff.format]
|
|
File without changes
|