Git Product home page Git Product logo

ez-packet's Introduction

Ez-Packet

A byte manipulation tool for IoT and network communications.

This module aims to simplify writing protocols for I/O by allowing declarative byte parsing.

Usage

Since this module is not published yet it only works with relative import, so python console needs to run on the same level as this module's folder

from ezpacket import Packet, Section

packet = Packet([Section(0x1100),Section(value=0x11,byte_size=2)])
packet.to_bytes() # 0x11000011

response =  Packet([Section.Template(2),Section.Template(byte_size=3)])
raw_data = bytes([1,2,3,4,5])
response.decode(raw_data)
response[0] # 0x0102
response[-1] # 0x030405

Features

  • Simple and familiar API:
    • Each Section has two parameters: value and byte size.
    • Packet object is just a section array with to_bytes, to_int and decode functions added, which means its easier to read
    • Section.Template makes easier to read without adding extra complexity. This function just sets the byte_size and returns a regular Section for its value to be filled during parsing
  • Expandable
    • Sections can parse data as long as they desire, so they are not limited with their byte size. This allows expanded section implementations
  • Fast
    • Packet is making use of integer and byte shifting logic with some loops, so no string parsing and decoding going on speeding up the process
  • Supports trailing or leading zeros! Packet(trail_or_lead=Zeros.LEADING) or Section(trail_or_lead=Zeros.LEADING)

Sections

Section

Simple section with a value and byte size. Used for sections in byte array protocols with fixed length

Expanding Section

When this section is added to packet, it consumes all remaining bytes and sets its own length. Used for sections that require custom parsing with custom logic, returned value can be parsed manually after parsing

Dynamic Section

This section sets its own first byte as the length byte. Used for transmitting and decoding protocols with flexible lengths

ez-packet's People

Contributors

ynsgnr avatar

Stargazers

 avatar Oğuz Paksoy avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.