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 hashes)

Uploaded Source

Built Distribution

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

Uploaded Python 3

Supported by

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