Skip to content

Commit

Permalink
Change a version number and put in mbed changes (#14)
Browse files Browse the repository at this point in the history
* Change a version number and put in mbed changes

* Needed to remove pointer as well
  • Loading branch information
jimsch authored Apr 8, 2020
1 parent 88deab0 commit 821797f
Show file tree
Hide file tree
Showing 6 changed files with 49 additions and 11 deletions.
2 changes: 2 additions & 0 deletions .mbedignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
test/*
cmake/*
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -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"
Expand Down
30 changes: 29 additions & 1 deletion include/cn-cbor/cn-cbor.h
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -33,7 +37,16 @@ extern "C" {
#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

/**
Expand Down Expand Up @@ -68,10 +81,12 @@ typedef enum cn_cbor_type {
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;
Expand Down Expand Up @@ -117,10 +132,12 @@ typedef struct cn_cbor {
#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;
Expand Down Expand Up @@ -283,7 +300,7 @@ cn_cbor* cn_cbor_mapget_int(const cn_cbor* cb, int key);
/**
* 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
*/
Expand Down Expand Up @@ -491,6 +508,17 @@ bool cn_cbor_array_append(cn_cbor* cb_array,

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
Expand Down
2 changes: 2 additions & 0 deletions src/cn-cbor.c
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@ extern "C" {
#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
Expand Down
12 changes: 8 additions & 4 deletions src/cn-encoder.c
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,16 @@ extern "C" {
#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>

Expand Down Expand Up @@ -118,7 +122,8 @@ static void _write_positive(cn_write_state *ws, cn_cbor_type typ, uint64_t val)
} 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;
Expand Down Expand Up @@ -297,13 +302,12 @@ void _encoder_visitor(const cn_cbor *cb, int depth, void *context)
CHECK(_write_positive(ws, CN_CBOR_INT, ~(cb->v.sint)));
break;

case CN_CBOR_DOUBLE:
#ifndef CBOR_NO_FLOAT
case CN_CBOR_DOUBLE:
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;
Expand Down
12 changes: 7 additions & 5 deletions src/cn-print.c
Original file line number Diff line number Diff line change
Expand Up @@ -165,15 +165,17 @@ void _print_encoder(const cn_cbor * cb, int depth, void * context)
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);
Expand Down

0 comments on commit 821797f

Please sign in to comment.