5 Commits
0.1.0 ... 0.2.0

5 changed files with 35 additions and 2 deletions

View File

@@ -2,6 +2,15 @@
All notable changes to this project will be documented in this file. 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 ## [0.1.0] - 2025-08-28
### Features ### Features

View File

@@ -4,7 +4,7 @@ build-backend = "uv_build"
[project] [project]
name = "judas_protocol" name = "judas_protocol"
version = "0.1.0" version = "0.2.0"
description = "The judas protocol" description = "The judas protocol"
readme = "README.md" readme = "README.md"
authors = [] authors = []

View File

@@ -1 +1,6 @@
__version__: str = "0.1.0" __version__: str = "0.1.0"
from .message import Message
from .types import Category, ControlAction
__all__ = ["__version__", "Message", "Category", "ControlAction"]

View File

@@ -48,6 +48,14 @@ class Message:
""" """
return json.dumps(self.to_dict()) 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 @classmethod
def from_dict(cls, data: dict[str, Any]) -> Message: def from_dict(cls, data: dict[str, Any]) -> Message:
"""Create a Message from a dictionary. """Create a Message from a dictionary.
@@ -81,6 +89,17 @@ class Message:
""" """
return cls.from_dict(json.loads(data)) 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 @classmethod
def ack(cls) -> Message: def ack(cls) -> Message:
"""Create an ACK message. """Create an ACK message.

2
uv.lock generated
View File

@@ -240,7 +240,7 @@ wheels = [
[[package]] [[package]]
name = "judas-protocol" name = "judas-protocol"
version = "0.1.0" version = "0.2.0"
source = { editable = "." } source = { editable = "." }
[package.dev-dependencies] [package.dev-dependencies]