Binary encoding/decoding package
Project description
JFW-Encoder-Decoder
A simple encoding/decoding scheme that freakin works
This sdk is inspired from googles protocol buffers This sdk is aimed to help embedded developer better integrate data exchange protocols with web/app developers. Data is encoded in binary format(Size and Speed advantage) and decoded into json format(Easy for web/app developer) User decides the data format by providing a header file. The user can insert data members within the fundamental data structures. Which are:
- veryHighPriorityData_t
- highPriorityData_t
- normalPriorityData_t
- lowPriorityData_t
- veryLowPriorityData_t
The structure names are to help user sort data members when using this sdk for data logging purpose.
- ✨Magic ✨
Packet Structure
Data is encoded according to the following scheme
SYNC_CHAR_1 | SYNC_CHAR_2 | LENGTH | MSG_ID | DATA[LENGTH] | CK_A | CK_B |
---|---|---|---|---|---|---|
0xB5 | 0x62 | Length | Packet Id | Data Length | Checksum | Checksum |
Features
- Data packetization for proper synchronization incase of garbage data.
- Checksum for data integrity
- Large range of fundamental c datatypes for code optimization
- Small code footprint and time complexity
- No dynamic allocation for C
Future Plans for development
Add option for encryption Add support for other languages Test and Build enviroment
Currently only C and Python are supported
Tech
- Currently the sdk does not uses any external dependency for C (except configuration file).
- The python dependencies are packed within the pypi package.
Installation
SDK requires Python 3.6+ to run.
Install the package.
pip3 install jfwEncoderDecoder
Generate the strcture class from conf header file
python3 -m jfwEncoderDecoder.jfw_generator $filepath
Now the class file has been generated and user can start using the sdk
Usage
Decoding
import json
import jfwEncoderDecoder.jfw_deserializer as jfw
binaryFilePath = "3014693-893931545-540029520-3732.bin"
with open(binaryFilePath, "rb") as f:
data = f.read()
ser = jfw.deserializer(data, len(data))
ser.search()
while(ser.decode_idx < len(ser.sync_char_off)):
final_json = ser.decode(False)
if(final_json != None):
temp = json.loads(final_json)
if 'async' in temp:
temp['async']['batteryId'] = "".join(chr(i) for i in temp['async']['batteryId'])
print("Data Lost: "+ser.loss())
Note: Strings have to be dealt with in post processing
Encoding/Decoding
with open('file.json', "rb+") as f:
lines = f.readlines()
idx = 0
for line in lines:
idx += 1
final_dictionary = json.loads(line)
encoder = jfwEncoderDecoder.jfw_serializer.serializer(final_dictionary, len(final_dictionary))
pkt_data = encoder.encode()
decoder = jfwEncoderDecoder.jfw_deserializer.deserializer(pkt_data, len(pkt_data))
decoder.search()
ret_json = decoder.decode()
if(json.dumps(final_dictionary) == str(ret_json)):
print("Line "+str(idx)+": Encoding/Decoding Successful!")
else:
print("ERROR!!!!!!")
Development
Want to contribute? Great! Contact at altamash.ar96@gmail.com
License
GNU General Public License v3 (GPLv3)
Free Software, Hell Yeah!
Project details
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
Hashes for jfwEncoderDecoder-0.2.6-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 78a5fe43eb9ea969d0b83a52e26fe7d1d3e3fc26a83b9621bbf3fb4ad111285e |
|
MD5 | df1810c7010b66e2b9340f18eba298a5 |
|
BLAKE2b-256 | 1c9c362e78a515874f77f1a8275f6a309e2cd171aa3277caf8eca7aae59dea07 |