generated from pufereq/python-template
feat(message.py): add Message.to_bytes()
This commit is contained in:
@@ -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")
|
||||||
|
|
||||||
@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.
|
||||||
|
|||||||
Reference in New Issue
Block a user