MqttAccess/src/mqtt_acess/parser/factory.py

13 lines
471 B
Python
Raw Normal View History

2025-07-14 16:10:38 +08:00
from .json_parser import JsonParser
2025-07-14 16:24:02 +08:00
from .xml_parser import XmlParser
2025-07-14 16:10:38 +08:00
class ParserFactory:
def get_parser(self, protocol_type: str):
if protocol_type == "json":
return JsonParser()
2025-07-14 16:24:02 +08:00
elif protocol_type == "xml":
return XmlParser()
elif protocol_type == "custom":
from .custom_parser import CustomParser
return CustomParser()
2025-07-14 16:10:38 +08:00
raise ValueError(f"不支持的协议类型: {protocol_type}")