types: Add constexpr endianness functions

Change-Id: I3ceff6cbd6d1991dc6131d266fa61dbf76595fdb
Signed-off-by: William A. Kennington III <wak@google.com>
diff --git a/test/test_types.cpp b/test/test_types.cpp
index 1f34144..8150555 100644
--- a/test/test_types.cpp
+++ b/test/test_types.cpp
@@ -4,6 +4,7 @@
 #include <fmt/chrono.h>
 #include <fmt/format.h>
 
+#include <array>
 #include <sstream>
 #include <string_view>
 
@@ -37,6 +38,19 @@
 namespace phosphor::network
 {
 
+TEST(Byteswap, Swap)
+{
+    EXPECT_EQ(38, bswap(uint8_t{38}));
+    EXPECT_EQ(38 << 8, bswap(uint16_t{38}));
+    EXPECT_EQ(0x240082fe, bswap(uint32_t{0xfe820024}));
+    EXPECT_EQ(0x240082fe00000000, bswap(uint64_t{0xfe820024}));
+    struct
+    {
+        std::array<char, 4> a = {1, 2, 3, 4};
+    } s;
+    EXPECT_EQ((std::array<char, 4>{4, 3, 2, 1}), bswap(s).a);
+}
+
 TEST(EqualOperator, InAddrAny)
 {
     EXPECT_EQ(InAddrAny(in6_addr{0xff, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,