lib: cpp: TProtocol: support zephyr byteorder
Zephyr's byteorder is defined in
`<zephyr/sys/byteorder.h>`. However, the `bswap_xx`
macros are also defined there. They need to be `#undef`d
first when building for big-endian architectures, since
the Thrift byteorder macros are no-ops for little-endian
architectures.
Signed-off-by: Chris Friedt <cfriedt@fb.com>
diff --git a/lib/cpp/src/thrift/protocol/TProtocol.h b/lib/cpp/src/thrift/protocol/TProtocol.h
index b691c41..c6ff360 100644
--- a/lib/cpp/src/thrift/protocol/TProtocol.h
+++ b/lib/cpp/src/thrift/protocol/TProtocol.h
@@ -86,6 +86,20 @@
#include <sys/param.h>
#endif
+#ifdef __ZEPHYR__
+# include <zephyr/sys/byteorder.h>
+
+# define __THRIFT_BYTE_ORDER __BYTE_ORDER__
+# define __THRIFT_LITTLE_ENDIAN __ORDER_LITTLE_ENDIAN__
+# define __THRIFT_BIG_ENDIAN __ORDER_BIG_ENDIAN__
+
+# if __THRIFT_BYTE_ORDER == __THRIFT_BIG_ENDIAN
+# undef bswap_64
+# undef bswap_32
+# undef bswap_16
+# endif
+#endif
+
#ifndef __THRIFT_BYTE_ORDER
# if defined(BYTE_ORDER) && defined(LITTLE_ENDIAN) && defined(BIG_ENDIAN)
# define __THRIFT_BYTE_ORDER BYTE_ORDER