summaryrefslogtreecommitdiff
path: root/src/ecbor.c
diff options
context:
space:
mode:
authorrimio <vasi.vilvoiu@gmail.com>2018-03-01 23:10:42 +0200
committerrimio <vasi.vilvoiu@gmail.com>2018-03-01 23:10:42 +0200
commit3621d55cd101fa5b23e645287393deefacf43e02 (patch)
tree8dc934e5ed5f2cdcd3f0f2fbae95f87fbab7ea8e /src/ecbor.c
parent245bce0bd3b9af5ab026f4b8453424dbc4a1faea (diff)
Support for fp32 and fp64
Diffstat (limited to 'src/ecbor.c')
-rw-r--r--src/ecbor.c41
1 files changed, 39 insertions, 2 deletions
diff --git a/src/ecbor.c b/src/ecbor.c
index 2a9b5fb..0a5e3fb 100644
--- a/src/ecbor.c
+++ b/src/ecbor.c
@@ -58,14 +58,40 @@ ecbor_uint64_from_big_endian (uint64_t value)
#endif
}
+extern float
+ecbor_fp32_from_big_endian (float value)
+{
+#if __BYTE_ORDER__ && (__BYTE_ORDER__ == __ORDER_BIG_ENDIAN__)
+ return value;
+#elif __BYTE_ORDER__ && (__BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__)
+ uint32_t r = ecbor_uint32_from_big_endian(*((uint32_t *) &value));
+ return *((float *) &r);
+#else
+ #error "Endianness not supported!"
+#endif
+}
+
+extern double
+ecbor_fp64_from_big_endian (double value)
+{
+#if __BYTE_ORDER__ && (__BYTE_ORDER__ == __ORDER_BIG_ENDIAN__)
+ return value;
+#elif __BYTE_ORDER__ && (__BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__)
+ uint64_t r = ecbor_uint64_from_big_endian(*((uint64_t *) &value));
+ return *((double *) &r);
+#else
+ #error "Endianness not supported!"
+#endif
+}
+
extern ecbor_major_type_t
ecbor_get_type (ecbor_item_t *item)
{
if (!item) {
return ECBOR_MT_UNDEFINED;
}
- if (item->major_type < ECBOR_MT_UINT
- || item->major_type > ECBOR_MT_SPECIAL) {
+ if (item->major_type < ECBOR_MT_FIRST
+ || item->major_type > ECBOR_MT_LAST) {
return ECBOR_MT_UNDEFINED;
}
return item->major_type;
@@ -101,6 +127,17 @@ ecbor_get_value (ecbor_item_t *item, void *value)
case ECBOR_MT_TAG:
*((uint64_t *)value) = item->value.tag.tag_value;
break;
+
+ case ECBOR_MT_FP16:
+ return ECBOR_ERR_CURRENTLY_NOT_SUPPORTED;
+
+ case ECBOR_MT_FP32:
+ *((float *)value) = item->value.fp32;
+ break;
+
+ case ECBOR_MT_FP64:
+ *((double *)value) = item->value.fp64;
+ break;
default:
return ECBOR_ERR_INVALID_TYPE;