From f7c0890bc84974c2770688378696bd8d74cfa7c2 Mon Sep 17 00:00:00 2001 From: aozhiwei Date: Tue, 3 Sep 2019 13:31:49 +0800 Subject: [PATCH] add IsValidNormalConfig --- cpp/utils.cc | 19 +++++++++++++++++++ cpp/utils.h | 2 ++ 2 files changed, 21 insertions(+) diff --git a/cpp/utils.cc b/cpp/utils.cc index 1ac7fa4..3990efc 100644 --- a/cpp/utils.cc +++ b/cpp/utils.cc @@ -337,4 +337,23 @@ namespace f8 return !getenv("SERVER_ENV"); } + bool IsValidNormalConfig(a8::XObject& conf, std::vector fields) + { + if (conf.GetType() != a8::XOT_ARRAY) { + abort(); + } + for (int i = 0; i < conf.Size(); ++i) { + std::shared_ptr node = conf.At(i); + if (node->At("instance_id")->AsXValue().GetInt() != i + 1) { + abort(); + } + for (std::string& field_name : fields) { + if (!node->HasKey(field_name)) { + abort(); + } + } + } + return true; + } + } diff --git a/cpp/utils.h b/cpp/utils.h index 4bf8205..a9631be 100644 --- a/cpp/utils.h +++ b/cpp/utils.h @@ -113,4 +113,6 @@ namespace f8 int ExtractChannelIdFromAccountId(const std::string& accountid); bool IsOnlineEnv(); + bool IsValidNormalConfig(a8::XObject& conf, std::vector fields); + }