generated from pufereq/python-template
Compare commits
4 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
8c4b49f0d7 | ||
|
f307a7f457
|
|||
|
|
0e72c93d55 | ||
|
4cc3a5bb3a
|
12
CHANGELOG.md
12
CHANGELOG.md
@@ -2,6 +2,18 @@
|
||||
|
||||
All notable changes to this project will be documented in this file.
|
||||
|
||||
## [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
|
||||
|
||||
@@ -4,7 +4,7 @@ build-backend = "uv_build"
|
||||
|
||||
[project]
|
||||
name = "judas_protocol"
|
||||
version = "0.3.0"
|
||||
version = "0.4.1"
|
||||
description = "The judas protocol"
|
||||
readme = "README.md"
|
||||
authors = []
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
from __future__ import annotations
|
||||
|
||||
import json
|
||||
import uuid
|
||||
from enum import Enum
|
||||
from typing import Any, override
|
||||
|
||||
@@ -24,13 +25,14 @@ class Message:
|
||||
action (Enum): The action of the message.
|
||||
payload (dict[str, Any] | None): The payload of the message.
|
||||
"""
|
||||
self.id: str = 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.category.name}] {self.action.name} - {self.payload}"
|
||||
return f"Message ({self.id}) [{self.category.name}] {self.action.name} - {self.payload}"
|
||||
|
||||
@override
|
||||
def __repr__(self) -> str:
|
||||
@@ -43,6 +45,7 @@ class Message:
|
||||
dict[str, Any]: The message as a dictionary.
|
||||
"""
|
||||
return {
|
||||
"id": self.id,
|
||||
"category": self.category,
|
||||
"action": self.action,
|
||||
"payload": self.payload,
|
||||
@@ -114,14 +117,19 @@ class Message:
|
||||
return cls.from_json(data.decode("utf-8"))
|
||||
|
||||
@classmethod
|
||||
def ack(cls) -> Message:
|
||||
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={}
|
||||
category=Category.CONTROL,
|
||||
action=ControlAction.ACK,
|
||||
payload={"target_id": target_id},
|
||||
)
|
||||
|
||||
@classmethod
|
||||
|
||||
Reference in New Issue
Block a user