Remove nlohmann brace initialization
There's a few last places (outside of tests) where we still use
nlohmann brace initialization. Per the transforms we've been doing,
move these to constructing the objects explicitly, using operator[],
nlohmann::object_t and nlohmann::array_t. Theses were found by manual
inspection grepping for all uses of nlohmann::json.
This is done to reduce binary size and reduce the number of intermediate
objects being constructed. This commit saves a trivial amount of size
(~4KB, Half a percent of total) and in addition but makes our
construction consistent.
Tested:
Redfish service validator passes.
Signed-off-by: Ed Tanous <edtanous@google.com>
Change-Id: I7478479a9fdc41b254eef325002d413c1fb411a0
diff --git a/redfish-core/lib/managers.hpp b/redfish-core/lib/managers.hpp
index a52b7b5..1955de1 100644
--- a/redfish-core/lib/managers.hpp
+++ b/redfish-core/lib/managers.hpp
@@ -400,8 +400,8 @@
chassis = "#IllegalValue";
}
nlohmann::json& zone = zones[name];
- zone["Chassis"] = {
- {"@odata.id", "/redfish/v1/Chassis/" + chassis}};
+ zone["Chassis"]["@odata.id"] =
+ "/redfish/v1/Chassis/" + chassis;
zone["@odata.id"] =
"/redfish/v1/Managers/bmc#/Oem/OpenBmc/Fan/FanZones/" +
name;
@@ -2000,7 +2000,8 @@
asyncResp->res.jsonValue["Actions"]["#Manager.ResetToDefaults"];
resetToDefaults["target"] =
"/redfish/v1/Managers/bmc/Actions/Manager.ResetToDefaults";
- resetToDefaults["ResetType@Redfish.AllowableValues"] = {"ResetAll"};
+ resetToDefaults["ResetType@Redfish.AllowableValues"] =
+ nlohmann::json::array_t({"ResetAll"});
std::pair<std::string, std::string> redfishDateTimeOffset =
redfish::time_utils::getDateTimeOffsetNow();
@@ -2015,15 +2016,15 @@
// Fill in SerialConsole info
asyncResp->res.jsonValue["SerialConsole"]["ServiceEnabled"] = true;
asyncResp->res.jsonValue["SerialConsole"]["MaxConcurrentSessions"] = 15;
- asyncResp->res.jsonValue["SerialConsole"]["ConnectTypesSupported"] = {
- "IPMI", "SSH"};
+ asyncResp->res.jsonValue["SerialConsole"]["ConnectTypesSupported"] =
+ nlohmann::json::array_t({"IPMI", "SSH"});
#ifdef BMCWEB_ENABLE_KVM
// Fill in GraphicalConsole info
asyncResp->res.jsonValue["GraphicalConsole"]["ServiceEnabled"] = true;
asyncResp->res.jsonValue["GraphicalConsole"]["MaxConcurrentSessions"] =
4;
- asyncResp->res
- .jsonValue["GraphicalConsole"]["ConnectTypesSupported"] = {"KVMIP"};
+ asyncResp->res.jsonValue["GraphicalConsole"]["ConnectTypesSupported"] =
+ nlohmann::json::array_t({"KVMIP"});
#endif // BMCWEB_ENABLE_KVM
asyncResp->res.jsonValue["Links"]["ManagerForServers@odata.count"] = 1;