You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
25 lines
602 B
25 lines
602 B
import json
|
|
import typing
|
|
from dataclasses import dataclass
|
|
from dataclasses_json import dataclass_json
|
|
|
|
@dataclass_json
|
|
@dataclass
|
|
class Msg:
|
|
_from: str
|
|
cmd: str
|
|
values: typing.Any
|
|
|
|
def to_json_(self) -> str:
|
|
"""将数据类序列化为 JSON 字符串"""
|
|
# return json.dumps(self.__dict__, indent=4, default=lambda x: x.__dict__)
|
|
return self.to_json()
|
|
|
|
# @classmethod
|
|
# def from_json(cls, json_str: str) -> 'Msg':
|
|
# """从 JSON 字符串反序列化为数据类"""
|
|
# data_dict = json.loads(json_str)
|
|
# return cls(**data_dict)
|
|
|
|
|
|
|
|
|