Skip to main content

A module for writing easy to understand byte packets and byte manipulations

Project description

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

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

ezpacket-0.0.6.tar.gz (5.7 kB view details)

Uploaded Source

File details

Details for the file ezpacket-0.0.6.tar.gz.

File metadata

  • Download URL: ezpacket-0.0.6.tar.gz
  • Upload date:
  • Size: 5.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.8.10

File hashes

Hashes for ezpacket-0.0.6.tar.gz
Algorithm Hash digest
SHA256 244892d84880e11c3811e5e383f98856223dca19fc5e747262857a86f9538847
MD5 6a31a2cfae4659c7ad823e08f84a0780
BLAKE2b-256 189f437256dc782c35830681e191a9538c3fe348259f4d638e7f80d6a20bed8c

See more details on using hashes here.

Supported by

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