Skip to main content

Binary encoding/decoding package

Project description

JFW-Encoder-Decoder

A simple encoding/decoding scheme that freakin works

Build Status

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

jfwEncoderDecoder-0.2.6.tar.gz (7.7 kB view details)

Uploaded Source

Built Distribution

jfwEncoderDecoder-0.2.6-py3-none-any.whl (9.4 kB view details)

Uploaded Python 3

File details

Details for the file jfwEncoderDecoder-0.2.6.tar.gz.

File metadata

  • Download URL: jfwEncoderDecoder-0.2.6.tar.gz
  • Upload date:
  • Size: 7.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.2 importlib_metadata/4.6.3 pkginfo/1.5.0.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.41.1 CPython/3.7.6

File hashes

Hashes for jfwEncoderDecoder-0.2.6.tar.gz
Algorithm Hash digest
SHA256 434df4d0eb5aedf572f857fa05cd29f3e89125a6368edfba9a816472145400d0
MD5 e5259c9d7b2ba535e10bd20bcf285d14
BLAKE2b-256 17e4fe17b8c36e6b46044b680b4b4975757a00c759c135d48251e8799ddd21fa

See more details on using hashes here.

File details

Details for the file jfwEncoderDecoder-0.2.6-py3-none-any.whl.

File metadata

  • Download URL: jfwEncoderDecoder-0.2.6-py3-none-any.whl
  • Upload date:
  • Size: 9.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.2 importlib_metadata/4.6.3 pkginfo/1.5.0.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.41.1 CPython/3.7.6

File hashes

Hashes for jfwEncoderDecoder-0.2.6-py3-none-any.whl
Algorithm Hash digest
SHA256 78a5fe43eb9ea969d0b83a52e26fe7d1d3e3fc26a83b9621bbf3fb4ad111285e
MD5 df1810c7010b66e2b9340f18eba298a5
BLAKE2b-256 1c9c362e78a515874f77f1a8275f6a309e2cd171aa3277caf8eca7aae59dea07

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page