Optimize resource event schema

Very similar to how the base registry was optimized for binary size,
optimize the resource event registry, by making the getLogFromRegistry a
common method for both registries.

Tested: Only usage of these calls appears to be in management console.
The code and pattern we're using here is well unit tested, and seems
reasonable that we could rely on the compile time checks, but if not, I
could use some help testing this.

Signed-off-by: Ed Tanous <edtanous@google.com>
Change-Id: I9cc442966df2ed301b14547727a5eb727c0c3a29
diff --git a/redfish-core/include/registries.hpp b/redfish-core/include/registries.hpp
index 4247aa8..d3d6c5f 100644
--- a/redfish-core/include/registries.hpp
+++ b/redfish-core/include/registries.hpp
@@ -15,6 +15,8 @@
 */
 #pragma once
 
+#include <nlohmann/json.hpp>
+
 #include <array>
 #include <charconv>
 #include <cstddef>
@@ -89,4 +91,33 @@
     return ret;
 }
 
+inline nlohmann::json::object_t
+    getLogFromRegistry(const Header& header,
+                       std::span<const MessageEntry> registry, size_t index,
+                       std::span<const std::string_view> args)
+{
+    const redfish::registries::MessageEntry& entry = registry[index];
+    // Intentionally make a copy of the string, so we can append in the
+    // parameters.
+    std::string msg = entry.second.message;
+    redfish::registries::fillMessageArgs(args, msg);
+    nlohmann::json jArgs = nlohmann::json::array();
+    for (const std::string_view arg : args)
+    {
+        jArgs.push_back(arg);
+    }
+    std::string msgId = header.id;
+    msgId += ".";
+    msgId += entry.first;
+
+    nlohmann::json::object_t response;
+    response["@odata.type"] = "#Message.v1_1_1.Message";
+    response["MessageId"] = std::move(msgId);
+    response["Message"] = std::move(msg);
+    response["MessageArgs"] = std::move(jArgs);
+    response["MessageSeverity"] = entry.second.messageSeverity;
+    response["Resolution"] = entry.second.resolution;
+    return response;
+}
+
 } // namespace redfish::registries