Skip to main content

Embody Codec

Project description

EmBody protocol codec

PyPI Status Python Version License

Tests

pre-commit Black

This is a Python based implementation library for the Aidee EmBody communication protocol.

Features

  • High-performance message decoding with O(1) lookup using optimized message registries
  • Comprehensive protocol support for all EmBody message types
  • Robust error handling with detailed error messages and optional CRC validation bypass
  • Type-safe implementations with full type annotations for better IDE support
  • Zero dependencies for the core library
  • Extensive test coverage ensuring protocol compliance

Requirements

  • This library does not require any external libraries
  • Requires Python 3.11+

Installation

You can install embody codec via pip from PyPI:

pip install embody-codec

Usage Examples

Basic Message Encoding/Decoding

from embodycodec import codec

# Create and encode a heartbeat message
heartbeat = codec.Heartbeat()
encoded_data = heartbeat.encode()

# Decode received data
decoded_msg = codec.decode(encoded_data)
print(f"Received: {type(decoded_msg).__name__}")

Working with Attributes

from embodycodec import codec, attributes

# Create a set attribute message
attr = attributes.BatteryLevelAttribute(value=85)
msg = codec.SetAttribute(attribute=attr)
encoded = msg.encode()

# Decode and access attribute value
decoded = codec.decode(encoded)
print(f"Battery level: {decoded.attribute.value}%")

Error Handling

from embodycodec import codec
from embodycodec.exceptions import CrcError, DecodeError

try:
    # Decode with CRC validation
    msg = codec.decode(data)
except CrcError:
    # Handle CRC error - optionally decode anyway
    msg = codec.decode(data, accept_crc_error=True)
except DecodeError as e:
    print(f"Decode failed: {e}")

Recent Improvements

Performance Enhancements

  • O(1) Message Lookups: Replaced linear if/elif chains with dictionary-based registries for 40x faster worst-case message type resolution
  • Optimized Memory Usage: More efficient payload extraction in ExecuteCommand and ExecuteCommandResponse

Bug Fixes

  • Fixed ExecuteCommand/Response to correctly extract only payload bytes instead of entire buffer
  • Corrected CRC16 handling when existing_crc is 0
  • Fixed typos in error messages ("too short/long" instead of "to short/long")
  • Enhanced validation in AFE_WRITE_REGISTER command handling
  • Fixed off-by-one error in hex dump generation

Code Quality

  • Added comprehensive type annotations to all registries
  • Extracted magic numbers to named constants (e.g., TEMPERATURE_SCALE_FACTOR)
  • Improved error handling with proper validation and meaningful error messages
  • Added extensive test coverage for edge cases

Contributing

Contributions are very welcome. To learn more, see the Contributor Guide.

License

Distributed under the terms of the MIT license.

Issues

If you encounter any problems, please file an issue along with a detailed description.

Credits

Inspiration collected from Cookiecutter UV template.

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

embody_codec-1.0.39.tar.gz (18.5 kB view details)

Uploaded Source

Built Distribution

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

embody_codec-1.0.39-py3-none-any.whl (20.3 kB view details)

Uploaded Python 3

File details

Details for the file embody_codec-1.0.39.tar.gz.

File metadata

  • Download URL: embody_codec-1.0.39.tar.gz
  • Upload date:
  • Size: 18.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for embody_codec-1.0.39.tar.gz
Algorithm Hash digest
SHA256 c9990f7c84b44adc35fde549ad49e0c0069d10eb6cec682db3ad5d4752a4a557
MD5 989b1eda586cdfb255cf25f142928e6d
BLAKE2b-256 33a9ba7ed6811628bd423e8341d1d52470badb41596184df18f72d1f5c5e619c

See more details on using hashes here.

File details

Details for the file embody_codec-1.0.39-py3-none-any.whl.

File metadata

  • Download URL: embody_codec-1.0.39-py3-none-any.whl
  • Upload date:
  • Size: 20.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for embody_codec-1.0.39-py3-none-any.whl
Algorithm Hash digest
SHA256 413d00e8a8aaf2636066259ac0debf45c04a54436d5f26bebbacf0f480411f28
MD5 6fa06ae417f815c25a05bc0c8890370b
BLAKE2b-256 ae4faa70a5a1274a84a57d86edc04c4c213a1ca43f2d13a6fda832daec5dcec1

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