Change a version number and put in mbed changes (#14)
* Change a version number and put in mbed changes
* Needed to remove pointer as well
diff --git a/.mbedignore b/.mbedignore
new file mode 100644
index 0000000..b335ab6
--- /dev/null
+++ b/.mbedignore
@@ -0,0 +1,2 @@
+test/*
+cmake/*
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 96911b8..c354c7b 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -1,7 +1,7 @@
cmake_minimum_required(VERSION 3.0.0)
set(VERSION_MAJOR
- 0
+ 1
CACHE STRING "Project major version number")
set(VERSION_MINOR
"1"
diff --git a/include/cn-cbor/cn-cbor.h b/include/cn-cbor/cn-cbor.h
index 0416bd2..2dceae0 100644
--- a/include/cn-cbor/cn-cbor.h
+++ b/include/cn-cbor/cn-cbor.h
@@ -8,6 +8,10 @@
#ifndef CN_CBOR_H
#define CN_CBOR_H
+#ifdef __MBED__
+#include <stddef.h>
+#endif
+
#ifndef MYLIB_EXPORT
#if defined (_WIN32)
#if defined(CN_CBOR_IS_DLL)
@@ -33,7 +37,16 @@
#include <WinSock2.h>
typedef signed long ssize_t;
#else
+#ifndef __MBED__
#include <unistd.h>
+#else
+#ifndef RETARGET_H
+#ifndef _SSIZE_T_DECLARED
+typedef signed long ssize_t;
+#define _SSIZE_T_DECLARED
+#endif
+#endif
+#endif
#endif
/**
@@ -68,10 +81,12 @@
CN_CBOR_TAG,
/** Simple value, other than the defined ones */
CN_CBOR_SIMPLE,
+#ifndef CBOR_NO_FLOAT
/** Doubles, floats, and half-floats */
CN_CBOR_DOUBLE,
/** Floats, and half-floats */
CN_CBOR_FLOAT,
+#endif
/** An error has occurred */
CN_CBOR_INVALID
} cn_cbor_type;
@@ -117,10 +132,12 @@
#else
unsigned long uint;
#endif
+#ifndef CBOR_NO_FLOAT
/** CN_CBOR_DOUBLE */
double dbl;
/** CN_CBOR_FLOAT */
float f;
+#endif
/** for use during parsing */
#ifdef _MSC_VER
uint64_t count;
@@ -283,7 +300,7 @@
/**
* Get the item with the given index from a CBOR array.
*
- * @param[in] cb The CBOR map
+ * @param[in] cb The CBOR array
* @param[in] idx The array index
* @return The matching value, or NULL if the index is invalid
*/
@@ -491,6 +508,17 @@
extern ssize_t cn_cbor_printer_write(char * buffer, size_t bufferSize, const cn_cbor * cb, const char * indent, const char * crlf);
+#ifdef __MBED__
+#define ntohs(a) ((uint16_t) (((((uint16_t) (a)) & 0xff) << 8) | (((uint16_t) (a)) & 0xff00) >> 8))
+#define htons(a) ntohs(a)
+#define ntohl(a) ((uint32_t) ( \
+ ((((uint32_t)(a)) & 0x000000ff) << 24) | \
+ ((((uint32_t)(a)) & 0x0000ff00) << 8) | \
+ ((((uint32_t)(a)) & 0x00ff0000) >> 8) | \
+ ((((uint32_t)(a)) & 0xff000000) >> 24)))
+#define htonl(a) ntohl(a)
+#endif // __MBED__
+
#ifdef __cplusplus
}
#endif
diff --git a/src/cn-cbor.c b/src/cn-cbor.c
index 7da5f88..d837606 100644
--- a/src/cn-cbor.c
+++ b/src/cn-cbor.c
@@ -16,7 +16,9 @@
#ifdef _MSC_VER
#include <WinSock2.h> // needed for ntohl on Windows
#else
+#ifndef __MBED__
#include <arpa/inet.h> // needed for ntohl (e.g.) on Linux
+#endif
#include "dll-export.h"
#endif // _MSC_VER
diff --git a/src/cn-encoder.c b/src/cn-encoder.c
index 18de686..d5b5bf0 100644
--- a/src/cn-encoder.c
+++ b/src/cn-encoder.c
@@ -12,12 +12,16 @@
#include <WinSock2.h>
#define inline _inline
#else
+#ifndef __MBED__
#include <arpa/inet.h>
#endif
+#endif
#include <string.h>
#ifndef _MSC_VER
+#ifndef __MBED__
#include <strings.h>
#endif
+#endif
#include <stdbool.h>
#include <assert.h>
@@ -118,7 +122,8 @@
} else if (val < 0x100000000L) {
uint32_t be32 = (uint32_t)val;
ensure_writable(5);
- be32 = hton32p(&be32);
+ // be32 = hton32p(&be32);
+ be32 = htonl(be32);
write_byte_and_data(ib | 26, (const void*)&be32, 4);
} else {
uint64_t be64;
@@ -297,13 +302,12 @@
CHECK(_write_positive(ws, CN_CBOR_INT, ~(cb->v.sint)));
break;
+#ifndef CBOR_NO_FLOAT
case CN_CBOR_DOUBLE:
-#ifndef CBOR_NO_FLOAT
CHECK(_write_double(ws, cb->v.dbl));
-#endif /* CBOR_NO_FLOAT */
break;
+
case CN_CBOR_FLOAT:
-#ifndef CBOR_NO_FLOAT
CHECK(_write_double(ws, cb->v.f));
#endif /* CBOR_NO_FLOAT */
break;
diff --git a/src/cn-print.c b/src/cn-print.c
index 6799362..077b0a4 100644
--- a/src/cn-print.c
+++ b/src/cn-print.c
@@ -165,15 +165,17 @@
write_data(ws, rgchT, cch);
break;
- case CN_CBOR_FLOAT:
- cch = _snprintf(rgchT, sizeof(rgchT), "%f", cb->v.f);
- write_data(ws, rgchT, cch);
- break;
+#ifndef CBOR_NO_FLOAT
+ case CN_CBOR_FLOAT:
+ cch = _snprintf(rgchT, sizeof(rgchT), "%f", cb->v.f);
+ write_data(ws, rgchT, cch);
+ break;
- case CN_CBOR_DOUBLE:
+ case CN_CBOR_DOUBLE:
cch = _snprintf(rgchT, sizeof(rgchT), "%f", cb->v.dbl);
write_data(ws, rgchT, cch);
break;
+#endif
case CN_CBOR_INVALID:
write_data(ws, "invalid", 7);