summaryrefslogtreecommitdiff
path: root/src/ecbor.c
diff options
context:
space:
mode:
authorrimio <vasi.vilvoiu@gmail.com>2018-03-01 21:24:07 +0200
committerrimio <vasi.vilvoiu@gmail.com>2018-03-01 21:24:07 +0200
commitdd2de65b85cdc7a7744145214ecf8ea5ebe46c25 (patch)
tree1f6c4e1efae92285af903f59168571ec5ef98173 /src/ecbor.c
parentdf8d9c31e2191aeedd967560f222971d978a9a1c (diff)
Added endianness conversion; Added first 10 answer files; fixed test case; fixed small issue in describe tool
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)