Embody Codec
Project description
EmBody protocol codec
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
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file embody_codec-1.0.36.tar.gz.
File metadata
- Download URL: embody_codec-1.0.36.tar.gz
- Upload date:
- Size: 17.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.12.8
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
938d48e1998f28c6850ab93c402703187f0c3a14f56d9b7ec6bf21bd16848522
|
|
| MD5 |
3d8c33b57f0099c3a00718e31b770aae
|
|
| BLAKE2b-256 |
b80ef8e36d3f20644b4fc78ddda668fd9205364bc9d9c8c7bbcdebdeab86c235
|
File details
Details for the file embody_codec-1.0.36-py3-none-any.whl.
File metadata
- Download URL: embody_codec-1.0.36-py3-none-any.whl
- Upload date:
- Size: 19.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.12.8
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
a44a2fea21525662cdf26adc780fd58d4103bdc7c1265254a4bec5aabf976b4e
|
|
| MD5 |
b68ecee493aba5c93a4a2e3e4db26ac3
|
|
| BLAKE2b-256 |
8c4c5fd13f68c027a10e7735ac8372dda56407e58f92dcba4f8739bd1a3cf369
|