Skip to content

Commit 7c57332

Browse files
committed
Add readme and setup
1 parent 4112c48 commit 7c57332

File tree

3 files changed

+70
-0
lines changed

3 files changed

+70
-0
lines changed

bits_coder/coder.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,3 +150,4 @@ def decode(self, pld):
150150
(2 ** field.nbits - 1)
151151
)
152152
field.decode(value)
153+
self._create_fields_map()

readme.md

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
# BitsCoder
2+
3+
Tool for encoding/decoding binary messages
4+
5+
## Installation
6+
7+
Clone repository:
8+
9+
$ git clone https://github.com/ladniac/bits_coder.git
10+
11+
Install package in your virtualenv:
12+
13+
$ pip setup.py install
14+
15+
16+
## Basic usage
17+
18+
### Encoding messages
19+
20+
Let's say we want to endode a following message:
21+
22+
data = {
23+
'temperature': 21,
24+
'is_nice': True,
25+
'lat': 78.234,
26+
'lon': -33.111
27+
}
28+
29+
And we want to use a following format:
30+
[5b temperature][1b is_nice][18b lat][18b lon][5b empty]
31+
32+
>>> from bits_coder.fields import Int, Bool, Float
33+
>>> from bits_coder.coder import BitsCoder
34+
>>> coder = BitsCoder(
35+
[
36+
Int(6, name='temperature', value=data['temperature']),
37+
Bool(1, name='is_nice', value=data['is_nice']),
38+
Float(18, frac=3, name='lat', value=data['lat']),
39+
Float(18, frac=3, name='lon', value=data['lon'])
40+
]
41+
)
42+
43+
44+
>>> encoded_msg = coder.encode()
45+
>>> print(encoded_msg.hex())
46+
5698cd6fd520
47+
48+
You can use the same BitsCoder instance to decode messages (fields without names will be named as ___n):
49+
50+
>>> coder.decode('FA123155A100')
51+
>>> print(coder.map)
52+
{'temperature': -2, 'is_nice': True, 'lat': 9.314, 'lon': -86.776, '___1': 0}
53+

setup.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
from setuptools import setup, find_packages
2+
3+
4+
setup(
5+
name="bits_coder",
6+
version="0.1.0",
7+
packages=find_packages(),
8+
install_requires=[],
9+
author="Szymon Ładniak",
10+
author_email="[email protected]",
11+
description="Tool for encoding/decoding binary messages",
12+
license="GPL",
13+
keywords=["binary decoder encoder"],
14+
url="https://github.com/ladniac/bits_coder",
15+
python_requires='>=3.6'
16+
)

0 commit comments

Comments
 (0)