summaryrefslogtreecommitdiff
path: root/src/ecbor.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/ecbor.c')
-rw-r--r--src/ecbor.c51
1 files changed, 51 insertions, 0 deletions
diff --git a/src/ecbor.c b/src/ecbor.c
index 9e8404f..dbbed96 100644
--- a/src/ecbor.c
+++ b/src/ecbor.c
@@ -6,6 +6,57 @@
*/
#include "ecbor.h"
+#include "ecbor_internal.h"
+
+uint16_t
+ecbor_uint16_from_big_endian (uint16_t value)
+{
+#if __BYTE_ORDER__ && (__BYTE_ORDER__ == __ORDER_BIG_ENDIAN__)
+ return value;
+#elif __BYTE_ORDER__ && (__BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__)
+ /* TODO: ARM optimization */
+ return ((value << 8) & 0xff00)
+ | ((value >> 8) & 0x00ff);
+#else
+ #error "Endianness not supported!"
+#endif
+}
+
+uint32_t
+ecbor_uint32_from_big_endian (uint32_t value)
+{
+#if __BYTE_ORDER__ && (__BYTE_ORDER__ == __ORDER_BIG_ENDIAN__)
+ return value;
+#elif __BYTE_ORDER__ && (__BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__)
+ /* TODO: ARM optimization */
+ return ((value << 8) & 0x00ff0000)
+ | ((value >> 8) & 0x0000ff00)
+ | ((value << 24) & 0xff000000)
+ | ((value >> 24) & 0x000000ff);
+#else
+ #error "Endianness not supported!"
+#endif
+}
+
+uint64_t
+ecbor_uint64_from_big_endian (uint64_t value)
+{
+#if __BYTE_ORDER__ && (__BYTE_ORDER__ == __ORDER_BIG_ENDIAN__)
+ return value;
+#elif __BYTE_ORDER__ && (__BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__)
+ /* TODO: ARM optimization */
+ return ((value << 8) & 0x000000ff00000000)
+ | ((value >> 8) & 0x00000000ff000000)
+ | ((value << 24) & 0x0000ff0000000000)
+ | ((value >> 24) & 0x0000000000ff0000)
+ | ((value << 40) & 0x00ff000000000000)
+ | ((value >> 40) & 0x000000000000ff00)
+ | ((value << 56) & 0xff00000000000000)
+ | ((value >> 56) & 0x00000000000000ff);
+#else
+ #error "Endianness not supported!"
+#endif
+}
extern ecbor_major_type_t
ecbor_get_type (ecbor_item_t *item)