Detemplateify intToHexString

The routine of intToHexString is mostly common between all the
various implementations, the only difference is in selecting a
reasonable default size for the type.  This commit moves to a common
method, so the templates don't get created for each and every
instantiation of intToHexString, and simplifies our code.

This saves a trivial amount (428 bytes) of compressed binary size.

Tested: Unit tests passing, and have good coverage of this.

Memory resources return the values as were there previously.

Signed-off-by: Ed Tanous <edtanous@google.com>
Change-Id: I6945a81a5e03c7a64d6a2a0629b24db941271930
diff --git a/redfish-core/include/utils/hex_utils.hpp b/redfish-core/include/utils/hex_utils.hpp
index 8ca3a81..c7c89a5 100644
--- a/redfish-core/include/utils/hex_utils.hpp
+++ b/redfish-core/include/utils/hex_utils.hpp
@@ -4,9 +4,7 @@
 #include <cstddef>
 #include <string>
 
-template <typename IntegerType>
-inline std::string intToHexString(IntegerType value,
-                                  size_t digits = sizeof(IntegerType) << 1)
+inline std::string intToHexString(uint64_t value, size_t digits)
 {
     static constexpr std::array<char, 16> digitsArray = {
         '0', '1', '2', '3', '4', '5', '6', '7',
diff --git a/redfish-core/lib/memory.hpp b/redfish-core/lib/memory.hpp
index f20681b..495b0a5 100644
--- a/redfish-core/lib/memory.hpp
+++ b/redfish-core/lib/memory.hpp
@@ -152,7 +152,7 @@
         return;
     }
 
-    aResp->res.jsonValue[key] = "0x" + intToHexString(*value);
+    aResp->res.jsonValue[key] = "0x" + intToHexString(*value, 4);
 }
 
 inline void getPersistentMemoryProperties(
diff --git a/redfish-core/lib/processor.hpp b/redfish-core/lib/processor.hpp
index 654a08b..b74b05c 100644
--- a/redfish-core/lib/processor.hpp
+++ b/redfish-core/lib/processor.hpp
@@ -153,7 +153,7 @@
                 if (value != nullptr)
                 {
                     aResp->res.jsonValue["ProcessorId"]["EffectiveFamily"] =
-                        "0x" + intToHexString(*value);
+                        "0x" + intToHexString(*value, 4);
                 }
             }
             else if (property.first == "EffectiveModel")
@@ -165,7 +165,7 @@
                     return;
                 }
                 aResp->res.jsonValue["ProcessorId"]["EffectiveModel"] =
-                    "0x" + intToHexString(*value);
+                    "0x" + intToHexString(*value, 4);
             }
             else if (property.first == "Id")
             {
@@ -174,7 +174,7 @@
                 {
                     aResp->res
                         .jsonValue["ProcessorId"]["IdentificationRegisters"] =
-                        "0x" + intToHexString(*value);
+                        "0x" + intToHexString(*value, 16);
                 }
             }
             else if (property.first == "Microcode")
@@ -186,7 +186,7 @@
                     return;
                 }
                 aResp->res.jsonValue["ProcessorId"]["MicrocodeInfo"] =
-                    "0x" + intToHexString(*value);
+                    "0x" + intToHexString(*value, 8);
             }
             else if (property.first == "Step")
             {
@@ -197,7 +197,7 @@
                     return;
                 }
                 aResp->res.jsonValue["ProcessorId"]["Step"] =
-                    "0x" + intToHexString(*value);
+                    "0x" + intToHexString(*value, 4);
             }
         }
     }
diff --git a/redfish-core/ut/hex_utils_test.cpp b/redfish-core/ut/hex_utils_test.cpp
index 708cb86..623c065 100644
--- a/redfish-core/ut/hex_utils_test.cpp
+++ b/redfish-core/ut/hex_utils_test.cpp
@@ -4,28 +4,22 @@
 
 TEST(ToHexString, uint64)
 {
-    EXPECT_EQ(intToHexString(0xFFFFFFFFFFFFFFFFULL), "FFFFFFFFFFFFFFFF");
+    EXPECT_EQ(intToHexString(0xFFFFFFFFFFFFFFFFULL, 16), "FFFFFFFFFFFFFFFF");
 
-    EXPECT_EQ(intToHexString<uint64_t>(0), "0000000000000000");
-    EXPECT_EQ(intToHexString<uint64_t>(0, 4), "0000");
-    EXPECT_EQ(intToHexString<uint64_t>(0, 8), "00000000");
-    EXPECT_EQ(intToHexString<uint64_t>(0, 12), "000000000000");
-    EXPECT_EQ(intToHexString<uint64_t>(0, 16), "0000000000000000");
+    EXPECT_EQ(intToHexString(0, 4), "0000");
+    EXPECT_EQ(intToHexString(0, 8), "00000000");
+    EXPECT_EQ(intToHexString(0, 12), "000000000000");
+    EXPECT_EQ(intToHexString(0, 16), "0000000000000000");
 
-    uint64_t deadbeef = 0xDEADBEEFBAD4F00DULL;
-    EXPECT_EQ(intToHexString<uint64_t>(deadbeef), "DEADBEEFBAD4F00D");
-    EXPECT_EQ(intToHexString<uint64_t>(deadbeef, 4), "F00D");
-    EXPECT_EQ(intToHexString<uint64_t>(deadbeef, 8), "BAD4F00D");
-    EXPECT_EQ(intToHexString<uint64_t>(deadbeef, 12), "BEEFBAD4F00D");
-    EXPECT_EQ(intToHexString<uint64_t>(deadbeef, 16), "DEADBEEFBAD4F00D");
+    // uint64_t sized ints
+    EXPECT_EQ(intToHexString(0xDEADBEEFBAD4F00DULL, 4), "F00D");
+    EXPECT_EQ(intToHexString(0xDEADBEEFBAD4F00DULL, 8), "BAD4F00D");
+    EXPECT_EQ(intToHexString(0xDEADBEEFBAD4F00DULL, 12), "BEEFBAD4F00D");
+    EXPECT_EQ(intToHexString(0xDEADBEEFBAD4F00DULL, 16), "DEADBEEFBAD4F00D");
+
+    // uint16_t sized ints
+    EXPECT_EQ(intToHexString(0xBEEF, 1), "F");
+    EXPECT_EQ(intToHexString(0xBEEF, 2), "EF");
+    EXPECT_EQ(intToHexString(0xBEEF, 3), "EEF");
+    EXPECT_EQ(intToHexString(0xBEEF, 4), "BEEF");
 }
-
-TEST(ToHexString, uint16)
-{
-    uint16_t beef = 0xBEEF;
-    EXPECT_EQ(intToHexString(beef), "BEEF");
-    EXPECT_EQ(intToHexString(beef, 1), "F");
-    EXPECT_EQ(intToHexString(beef, 2), "EF");
-    EXPECT_EQ(intToHexString(beef, 3), "EEF");
-    EXPECT_EQ(intToHexString(beef, 4), "BEEF");
-}
\ No newline at end of file