generated from pufereq/python-template
Compare commits
5 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
cccda80784 | ||
|
fd070b1763
|
|||
|
df55e0c5cb
|
|||
|
762d09ea9b
|
|||
|
b90653b3fd
|
@@ -2,6 +2,15 @@
|
||||
|
||||
All notable changes to this project will be documented in this file.
|
||||
|
||||
## [0.2.0] - 2025-08-28
|
||||
|
||||
### Features
|
||||
|
||||
- [`fd070b1`](https://gitea.pufereq.pl/judas/judas_protocol/commit/fd070b176347a0f7b81f937b189d8f50736f3514) **message.py**: add `b"\n"` at end of data from `to_bytes()`
|
||||
- [`df55e0c`](https://gitea.pufereq.pl/judas/judas_protocol/commit/df55e0c5cba00c6d08b98cf09f265c130bc11f73) **message.py**: add `Message.from_bytes()`
|
||||
- [`762d09e`](https://gitea.pufereq.pl/judas/judas_protocol/commit/762d09ea9b3e28efdfdd2ac0674bb874154b41a9) **message.py**: add `Message.to_bytes()`
|
||||
- [`b90653b`](https://gitea.pufereq.pl/judas/judas_protocol/commit/b90653b3fd90957a0056dcd803da20a78a589314) **__init__.py**: add public api
|
||||
|
||||
## [0.1.0] - 2025-08-28
|
||||
|
||||
### Features
|
||||
|
||||
@@ -4,7 +4,7 @@ build-backend = "uv_build"
|
||||
|
||||
[project]
|
||||
name = "judas_protocol"
|
||||
version = "0.1.0"
|
||||
version = "0.2.0"
|
||||
description = "The judas protocol"
|
||||
readme = "README.md"
|
||||
authors = []
|
||||
|
||||
@@ -1 +1,6 @@
|
||||
__version__: str = "0.1.0"
|
||||
|
||||
from .message import Message
|
||||
from .types import Category, ControlAction
|
||||
|
||||
__all__ = ["__version__", "Message", "Category", "ControlAction"]
|
||||
|
||||
@@ -48,6 +48,14 @@ class Message:
|
||||
"""
|
||||
return json.dumps(self.to_dict())
|
||||
|
||||
def to_bytes(self) -> bytes:
|
||||
"""Convert the message to bytes.
|
||||
|
||||
Returns:
|
||||
bytes: The message as bytes.
|
||||
"""
|
||||
return self.to_json().encode("utf-8") + b"\n"
|
||||
|
||||
@classmethod
|
||||
def from_dict(cls, data: dict[str, Any]) -> Message:
|
||||
"""Create a Message from a dictionary.
|
||||
@@ -81,6 +89,17 @@ class Message:
|
||||
"""
|
||||
return cls.from_dict(json.loads(data))
|
||||
|
||||
@classmethod
|
||||
def from_bytes(cls, data: bytes) -> Message:
|
||||
"""Create a Message from bytes.
|
||||
|
||||
Args:
|
||||
data (bytes): The bytes to create the message from.
|
||||
Returns:
|
||||
Message: The created message.
|
||||
"""
|
||||
return cls.from_json(data.decode("utf-8"))
|
||||
|
||||
@classmethod
|
||||
def ack(cls) -> Message:
|
||||
"""Create an ACK message.
|
||||
|
||||
Reference in New Issue
Block a user