Python BinField implementation for binary data manipulation
Project description
binfield
Python binfield implementation for binary data manipulation.
Pros:
Free software: Apache license
Open Source: https://github.com/penguinolog/binfield
Self-documented code: docstrings with types in comments
Tested: see bages on top
Support miltiple Python versions:
Python 2.7 Python 3.4 Python 3.5 Python 3.6 PyPy
Usage
Not mapped objects could be created simply from BinField class:
bf = BinField(42)
Data with fixed size should be created as new class (type):
class TwoBytes(BinField):
_size_ = 16 # Size in bits
bf = TwoBytes(42)
2 == len(bf) # Length is in bytes for easier conversion to bytes
Also binary mask could be attached and data will be always conform with it:
class MyBinField(BinField):
_mask_ = 0b11
_size_ = 8
bf = MyBinField(5)
0b001 == bf # Mask was applied and 0b101 & 0b011 = 0b001
Mapped objects is also should be created as new class (type):
class MyBinField(BinField):
first = 0 # Single bit
two_bits = [1, 3] # Also could be mapped as tuple and slice
_mask_ = 0b1011
bf = MyBinField(0b1101)
0b1001 == bf
4 == bf._size_ # Size is generated during creation from mask
0b01 == bf.two_bits._mask_ # Mask is inherited from parent object
Nested mapping is supported:
class MyBinField(BinField):
first = 0 # Single bit
two_bits = [1, 3] # Also could be mapped as tuple and slice
nested = {
'_index_': [3, 8], # Index is mandatory, it should be slice, list or tuple
'nested_bit': 0, # In nested objects use relative indexing
'nested_bits': [1, 3]
}
# Nested objects could contain less indexed area, than block size,
# but mask will be calculated from outer level indexes only.
bf = MyBinField(0xFF)
0b00011111 == bf.nested
# Nested received (generated as all bits in range) mask from top
# and size from slice
1 == bf.nested.nested_bit # __getitem__ and properties is available
bf.nested.nested_bit = 0 # property has setters
0b11110111 == bf # Change on nested is returned to main object
Note: negative indexes is not supported by design!
Testing
The main test mechanism for the package binfield is using tox. Test environments available:
pep8 py27 py34 py35 py36 pypy pylint
CI systems
For code checking several CI systems is used in parallel:
Travis CI: is used for checking: PEP8, pylint, bandit, installation possibility and unit tests. Also it’s publishes coverage on coveralls.
coveralls: is used for coverage display.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file BinField-0.5.0.tar.gz
.
File metadata
- Download URL: BinField-0.5.0.tar.gz
- Upload date:
- Size: 18.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 98830818f6ebe31fb5355449c792f94326b0ffda08998b4c687b9d49c7defc4f |
|
MD5 | 09c646e3c26dd048bcee6e12bc8b6cca |
|
BLAKE2b-256 | c0c5ba177e4cfcbafa154b265a319962b2c772dc3ee8389f3cbec20380fe3af8 |
File details
Details for the file BinField-0.5.0-py2.py3-none-any.whl
.
File metadata
- Download URL: BinField-0.5.0-py2.py3-none-any.whl
- Upload date:
- Size: 13.0 kB
- Tags: Python 2, Python 3
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 99ba3ed9920ca9f81027c36f5657e2ffc0ee324b4937d0f77dc4e6cdb8a7148a |
|
MD5 | cd9da77fe87d840c0cef0ddca003c9e4 |
|
BLAKE2b-256 | e8b6ae8a343dcc2281a21d6d89a20f020f9935263f9c1aed70680264bc167d24 |