Skip to main content

A package to parse Photon Protocol packets in Python

Project description

photon-packet-parser

The photon-packet-parser is a Python library designed to parse and analyze packets transmitted using the Photon Protocol16 based on the C# library coded by 0blu. This library provides developers with a convenient way to decode and inspect Photon Protocol packets in their Python applications.

Warning

This library is incomplete as I merely needed some parts of it for my own project. I will add more features as I need them. It is not fully tested and far from being used in a production environment. If you need a feature that is not implemented yet, feel free to open an issue or submit a pull request.

Features

  • Parsing and decoding of Photon Protocol packets

  • Callbacks for handling different packet actions

  • Access to packet headers, payload, and metadata

Installation

You can install the photon-packet-parser library using pip:

pip install photon-packet-parser

Usage

To use the library, start by importing the PhotonPacketParser class:

from photon_packet_parser import PhotonPacketParser

Then, create an instance of the PhotonPacketParser class and provide the necessary callbacks:

def on_event(header, payload):

    # Callback for handling event packets

    pass



def on_request(header, payload):

    # Callback for handling request packets

    pass



def on_response(header, payload):

    # Callback for handling response packets

    pass



parser = PhotonPacketParser(on_event, on_request, on_response)

Once the parser object is created, you can use the handle_payload method to parse a payload:

payload_data = b'\x01\x02\x03\x04\x05\x06\x07\x08'

parser.handle_payload(payload_data)

The library will invoke the appropriate callback based on the packet type encountered during parsing.

For more advanced usage and customization options, please refer to the documentation.

Examples

Parsing a Photon Protocol packet

from photon_packet_parser import PhotonPacketParser



def on_event(header, payload):

    # Handle event packets

    print("Received event packet")



def on_request(header, payload):

    # Handle request packets

    print("Received request packet")



def on_response(header, payload):

    # Handle response packets

    print("Received response packet")



# Create a parser instance with callbacks

parser = PhotonPacketParser(on_event, on_request, on_response)



# Parse a payload

payload_data = b'\x01\x02\x03\x04\x05\x06\x07\x08'

parser.handle_payload(payload_data)

Contributing

Contributions to the photon-packet-parser library are welcome! If you find any bugs, have feature requests, or want to contribute improvements, please open an issue or submit a pull request on the GitHub repository.

When contributing, please follow the existing code style and ensure that all tests pass before submitting your changes.

License

The photon-packet-parser library is licensed under the MIT License. You are free to use, modify, and distribute this library in accordance with the terms of the license.

Acknowledgements

This library was inspired by 0blu implementation and the need for a Python parser.

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

photon-packet-parser-0.1.2.tar.gz (9.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

photon_packet_parser-0.1.2-py3-none-any.whl (10.2 kB view details)

Uploaded Python 3

File details

Details for the file photon-packet-parser-0.1.2.tar.gz.

File metadata

  • Download URL: photon-packet-parser-0.1.2.tar.gz
  • Upload date:
  • Size: 9.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.11.4

File hashes

Hashes for photon-packet-parser-0.1.2.tar.gz
Algorithm Hash digest
SHA256 6a3840c2b7adcb0e253e0de4cde44300e79993cd32ff96a3131fe57bb9e3db4f
MD5 09f081c8b8008d5719467055dfc1b6fb
BLAKE2b-256 9effd2c05a6131685f7b046109a60bcaed557c261d15fa457fde70162636596b

See more details on using hashes here.

File details

Details for the file photon_packet_parser-0.1.2-py3-none-any.whl.

File metadata

File hashes

Hashes for photon_packet_parser-0.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 b43c269b44da9947a070c0f3cba368346d8c3d380afc396ff96041f7ccb93ad1
MD5 c31dce42d519b5175ca7236f20962e3e
BLAKE2b-256 d1606ff035d4445d343f939815a012113d0df14ce558bfd55ad1bd3de82041d8

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