17 Commits
0.1.0 ... 0.4.3

Author SHA1 Message Date
github-actions[bot]
5ef300ff93 chore(release): 0.4.3 2025-10-05 11:43:19 +00:00
1ab577ebd5 fix(message.py): provide id_ in ack() and hello() 2025-10-05 13:42:23 +02:00
github-actions[bot]
6ce742667a chore(release): 0.4.2 2025-10-05 11:35:11 +00:00
37eec56afe fix(message.py): allow providing ID via argument 2025-10-05 13:34:28 +02:00
github-actions[bot]
8c4b49f0d7 chore(release): 0.4.1 2025-10-05 11:23:28 +00:00
f307a7f457 chore(message.py): add target_id argument to Message.ack classmethod 2025-10-05 13:20:48 +02:00
github-actions[bot]
0e72c93d55 chore(release): 0.4.0 2025-10-05 10:58:42 +00:00
4cc3a5bb3a feat(message.py): add message uuid 2025-10-05 12:57:13 +02:00
github-actions[bot]
c25ee1ebdf chore(release): 0.3.0 2025-09-23 21:30:38 +00:00
ffc4ed1897 feat(message.py): add __str__ and __repr__ methods 2025-09-23 23:28:40 +02:00
bc1bf46388 feat(message.py): raise ValueError if invalid json in Message.from_bytes() 2025-09-21 21:59:12 +02:00
9b5b104061 style(message.py): organize imports 2025-09-21 21:58:43 +02:00
github-actions[bot]
cccda80784 chore(release): 0.2.0 2025-08-29 13:54:33 +00:00
fd070b1763 feat(message.py): add b"\n" at end of data from to_bytes() 2025-08-28 15:19:12 +02:00
df55e0c5cb feat(message.py): add Message.from_bytes() 2025-08-28 14:39:59 +02:00
762d09ea9b feat(message.py): add Message.to_bytes() 2025-08-28 13:24:21 +02:00
b90653b3fd feat(__init__.py): add public api 2025-08-28 13:16:58 +02:00
5 changed files with 105 additions and 8 deletions

View File

@@ -2,6 +2,50 @@
All notable changes to this project will be documented in this file.
## [0.4.3] - 2025-10-05
### Bug Fixes
- [`1ab577e`](https://gitea.pufereq.pl/judas/judas_protocol/commit/1ab577ebd583ed17f813d37745b5dc195855d9c3) **message.py**: provide `id_` in `ack()` and `hello()`
## [0.4.2] - 2025-10-05
### Bug Fixes
- [`37eec56`](https://gitea.pufereq.pl/judas/judas_protocol/commit/37eec56afeb2697955702aba04476ccdde7435e4) **message.py**: allow providing ID via argument
## [0.4.1] - 2025-10-05
### Miscellaneous Tasks
- [`f307a7f`](https://gitea.pufereq.pl/judas/judas_protocol/commit/f307a7f457924ff1717ed4c8ce195ce022dd5680) **message.py**: add `target_id` argument to `Message.ack` classmethod
## [0.4.0] - 2025-10-05
### Features
- [`4cc3a5b`](https://gitea.pufereq.pl/judas/judas_protocol/commit/4cc3a5bb3a0fce0c4d90958f26fa09a1d638a4b3) **message.py**: add message uuid
## [0.3.0] - 2025-09-23
### Features
- [`ffc4ed1`](https://gitea.pufereq.pl/judas/judas_protocol/commit/ffc4ed18974e89c6f1f5554d9e8832065432310a) **message.py**: add `__str__` and `__repr__` methods
- [`bc1bf46`](https://gitea.pufereq.pl/judas/judas_protocol/commit/bc1bf46388eb904738893a2f86b5050b4ce2489e) **message.py**: raise ValueError if invalid json in `Message.from_bytes()`
### Styling
- [`9b5b104`](https://gitea.pufereq.pl/judas/judas_protocol/commit/9b5b104061859b2dd4ab93258414edd8ce34b4a7) **message.py**: organize imports
## [0.2.0] - 2025-08-29
### 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

View File

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

View File

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

View File

@@ -1,9 +1,10 @@
# -*- coding: utf-8 -*-
from __future__ import annotations
from enum import Enum
import json
from typing import Any
import uuid
from enum import Enum
from typing import Any, override
from judas_protocol.types import Category, ControlAction
@@ -13,6 +14,7 @@ class Message:
def __init__(
self,
id_: str | None,
category: Category,
action: Enum,
payload: dict[str, Any] | None = None,
@@ -20,14 +22,24 @@ class Message:
"""Initialize a Message.
Args:
id_ (str | None): The ID of the message. If None, a new UUID will be generated.
category (Category): The category of the message.
action (Enum): The action of the message.
payload (dict[str, Any] | None): The payload of the message.
"""
self.id: str = id_ or str(uuid.uuid4())
self.category: Category = category
self.action: Enum = action
self.payload: dict[str, Any] = payload or {}
@override
def __str__(self) -> str:
return f"Message ({self.id}) [{self.category.name}] {self.action.name} - {self.payload}"
@override
def __repr__(self) -> str:
return f"Message(category={self.category}, action={self.action}, payload={self.payload})"
def to_dict(self) -> dict[str, Any]:
"""Convert the message to a dictionary.
@@ -35,6 +47,7 @@ class Message:
dict[str, Any]: The message as a dictionary.
"""
return {
"id": self.id,
"category": self.category,
"action": self.action,
"payload": self.payload,
@@ -48,6 +61,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.
@@ -58,6 +79,10 @@ class Message:
Returns:
Message: The created message.
"""
if "id" not in data:
data["id"] = None
id_: str | None = data["id"]
category = Category(data["category"])
action_str = data["action"]
@@ -68,7 +93,7 @@ class Message:
raise ValueError(f"Unknown category: {category}")
payload = data.get("payload", {})
return cls(category=category, action=action, payload=payload)
return cls(id_=id_, category=category, action=action, payload=payload)
@classmethod
def from_json(cls, data: str) -> Message:
@@ -79,17 +104,39 @@ class Message:
Returns:
Message: The created message.
"""
return cls.from_dict(json.loads(data))
try:
json_data = json.loads(data)
except json.JSONDecodeError as e:
raise ValueError("Invalid JSON data") from e
return cls.from_dict(json_data)
@classmethod
def ack(cls) -> Message:
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, target_id: str) -> Message:
"""Create an ACK message.
Args:
target_id (str): The ID of the message to acknowledge.
Returns:
Message: The created ACK message.
"""
return cls(
category=Category.CONTROL, action=ControlAction.ACK, payload={}
id_=None,
category=Category.CONTROL,
action=ControlAction.ACK,
payload={"target_id": target_id},
)
@classmethod
@@ -102,6 +149,7 @@ class Message:
Message: The created HELLO message.
"""
return cls(
id_=None,
category=Category.CONTROL,
action=ControlAction.HELLO,
payload={"mac": mac},

2
uv.lock generated
View File

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