配置生成逻辑优化

This commit is contained in:
2026-08-21 17:59:48 +08:00
parent 4909392c5e
commit ff487be64e
19 changed files with 536 additions and 1769 deletions
+23 -19
View File
@@ -55,11 +55,11 @@ public:
ret.append(Psc::JSON("output_format", output_format.read([](const auto& value) { return value.to_base_json(); })));
return ret;
}
virtual void from_json(const Psc::JSON* that_json, bool not_exist_use_default_value) {
With_Loop_Coro::from_base_json(that_json, not_exist_use_default_value);
source_key = that_json->get("source_key") == nullptr ? std::string{} : that_json->get_string("source_key");
virtual void from_json(const Psc::JSON* that_json) {
With_Loop_Coro::from_base_json(that_json);
source_key = that_json->get_string("source_key");
output_format.write([&](auto& value) {
value.from_base_json(that_json->get("output_format"), not_exist_use_default_value);
value.from_base_json(that_json->get("output_format"));
});
}
virtual Psc::JSON get_custom_state_json() {
@@ -148,10 +148,10 @@ public:
co_await svr.write_to_all_clients_coro(data);
co_return;
}
void from_json(const Psc::JSON* that_json, bool not_exist_use_default_value) override {
Data_Feed::from_json(that_json, not_exist_use_default_value);
void from_json(const Psc::JSON* that_json) override {
Data_Feed::from_json(that_json);
specific.write([&](auto& value) {
value.from_base_json(that_json, not_exist_use_default_value);
value.from_base_json(that_json);
});
}
Psc::JSON to_json() override {
@@ -236,10 +236,10 @@ public:
co_await cli.connect_coro();
co_return;
}
void from_json(const Psc::JSON* that_json, bool not_exist_use_default_value) override {
Data_Feed::from_json(that_json, not_exist_use_default_value);
void from_json(const Psc::JSON* that_json) override {
Data_Feed::from_json(that_json);
specific.write([&](auto& value) {
value.from_base_json(that_json, not_exist_use_default_value);
value.from_base_json(that_json);
});
}
Psc::JSON to_json() override {
@@ -295,10 +295,10 @@ public:
}
return ret;
}
void from_json(const Psc::JSON* that_json, bool not_exist_use_default_value) override {
Data_Feed::from_json(that_json, not_exist_use_default_value);
void from_json(const Psc::JSON* that_json) override {
Data_Feed::from_json(that_json);
specific.write([&](auto& value) {
value.from_base_json(that_json, not_exist_use_default_value);
value.from_base_json(that_json);
});
}
Psc::JSON to_json() override {
@@ -346,10 +346,10 @@ public:
co_return;
}
Psc::asio_socket::UDP_Client_Coro cli;
void from_json(const Psc::JSON* that_json, bool not_exist_use_default_value) override {
Data_Feed::from_json(that_json, not_exist_use_default_value);
void from_json(const Psc::JSON* that_json) override {
Data_Feed::from_json(that_json);
specific.write([&](auto& value) {
value.from_base_json(that_json, not_exist_use_default_value);
value.from_base_json(that_json);
});
}
Psc::JSON to_json() override {
@@ -408,16 +408,20 @@ public:
Psc::String_Pool pool_ = Psc::String_Pool(1600, 8 * 1024); // 8192 * 1600 12.5 MB
Ordered_Map<std::string, std::shared_ptr<Data_Feed>> map;
Data_feed_Config() = default;
void init(const Psc::JSON* that_json, bool not_exist_use_default_value) {
void init(const Psc::JSON* that_json) {
if (that_json == nullptr || that_json->valueType != Psc::Object)
throw Psc::json_assign_error(std::make_error_code(std::errc::invalid_argument), "data_feed");
auto connect = that_json->get("list");
if (connect == nullptr || connect->valueType != Psc::Array)
throw Psc::json_assign_error(std::make_error_code(std::errc::invalid_argument), "data_feed.list");
for (auto& it : connect->children) {
auto type = it.get_string("type");
std::shared_ptr<Data_Feed> t = create_data_feed_from_type(type);
t->from_json(&it, not_exist_use_default_value);
t->from_json(&it);
map.push_back(t);
}
settings.write([&](auto& value) {
value.from_base_json(that_json, not_exist_use_default_value);
value.from_base_json(that_json);
});
}
Psc::JSON list() const {