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/certificate_service.hpp b/redfish-core/lib/certificate_service.hpp
index ebd9436..d3aedd0 100644
--- a/redfish-core/lib/certificate_service.hpp
+++ b/redfish-core/lib/certificate_service.hpp
@@ -78,15 +78,16 @@
asyncResp->res.jsonValue["CertificateLocations"]["@odata.id"] =
"/redfish/v1/CertificateService/CertificateLocations";
}
- asyncResp->res
- .jsonValue["Actions"]["#CertificateService.ReplaceCertificate"] = {
- {"target",
- "/redfish/v1/CertificateService/Actions/CertificateService.ReplaceCertificate"},
- {"CertificateType@Redfish.AllowableValues", {"PEM"}}};
- asyncResp->res
- .jsonValue["Actions"]["#CertificateService.GenerateCSR"] = {
- {"target",
- "/redfish/v1/CertificateService/Actions/CertificateService.GenerateCSR"}};
+ nlohmann::json& actions = asyncResp->res.jsonValue["Actions"];
+ nlohmann::json& replace =
+ actions["#CertificateService.ReplaceCertificate"];
+ replace["target"] =
+ "/redfish/v1/CertificateService/Actions/CertificateService.ReplaceCertificate";
+ nlohmann::json::array_t allowed;
+ allowed.push_back("PEM");
+ replace["CertificateType@Redfish.AllowableValues"] = std::move(allowed);
+ actions["#CertificateService.GenerateCSR"]["target"] =
+ "/redfish/v1/CertificateService/Actions/CertificateService.GenerateCSR";
});
} // requestRoutesCertificateService