remove QCOM-isms -- memscpy, memsmove; clean up documentation; at least one basic test; put into XCode project
diff --git a/.DS_Store b/.DS_Store
new file mode 100644
index 0000000..a05a102
--- /dev/null
+++ b/.DS_Store
Binary files differ
diff --git a/basic_test.c b/basic_test.c
new file mode 100644
index 0000000..b9baa88
--- /dev/null
+++ b/basic_test.c
@@ -0,0 +1,9 @@
+//
+// basic_test.c
+// QCBOR
+//
+// Created by Laurence Lundblade on 9/13/18.
+// Copyright © 2018 Laurence Lundblade. All rights reserved.
+//
+
+#include "basic_test.h"
diff --git a/basic_test.h b/basic_test.h
new file mode 100644
index 0000000..da9a3c6
--- /dev/null
+++ b/basic_test.h
@@ -0,0 +1,14 @@
+//
+// basic_test.h
+// QCBOR
+//
+// Created by Laurence Lundblade on 9/13/18.
+// Copyright © 2018 Laurence Lundblade. All rights reserved.
+//
+
+#ifndef basic_test_h
+#define basic_test_h
+
+#include <stdio.h>
+
+#endif /* basic_test_h */
diff --git a/cmd_line_main.c b/cmd_line_main.c
new file mode 100644
index 0000000..54adb50
--- /dev/null
+++ b/cmd_line_main.c
@@ -0,0 +1,19 @@
+//
+// main.c
+// QCBOR
+//
+// Created by Laurence Lundblade on 9/13/18.
+// Copyright © 2018 Laurence Lundblade. All rights reserved.
+//
+
+#include <stdio.h>
+
+#include "basic_test.h"
+
+int main(int argc, const char * argv[]) {
+ // insert code here...
+ printf("Hello, World! %d\n", basic_test_one());
+
+
+ return 0;
+}
diff --git a/inc/UsefulBuf.h b/inc/UsefulBuf.h
index aed6644..b78d0c7 100644
--- a/inc/UsefulBuf.h
+++ b/inc/UsefulBuf.h
@@ -55,8 +55,8 @@
#define _UsefulBuf_h
-#include <stdint.h>
-#include <string.h>
+#include <stdint.h> // for uint8_t, uint16_t....
+#include <string.h> // for strlen, memcpy, memmove, memset
#include <stddef.h> // for size_t
/**
@@ -130,13 +130,13 @@
*/
-typedef struct __UsefulBuf {
+typedef struct {
void *ptr;
size_t len;
} UsefulBuf;
-typedef struct __UsefulBufC {
+typedef struct {
const void *ptr;
size_t len;
} UsefulBufC;
@@ -157,12 +157,6 @@
return (UsefulBufC){UB.ptr, UB.len};
}
-// Old form. Should be deprecated.
-static inline UsefulBufC UsefulBufConst(const UsefulBuf UB)
-{
- return (UsefulBufC){UB.ptr, UB.len};
-}
-
/**
@brief Convert a const UsefulBufC to a non-const UsefulBuf
@@ -261,8 +255,9 @@
/**
@brief Copy a pointer into a UsefulBuf
- @param[in] pDest The destination buffer to copy into
- @param[out] Src The source to copy from
+ @param[in,out] pDest The destination buffer to copy into
+ @param[in] ptr The source to copy from
+ @param[in] len Length of the source; amoutn to copy
@return 0 on success, 1 on failure
@@ -418,7 +413,7 @@
can go on the stack or be a C99 function parameter.
*/
-typedef struct __UsefulOutBuf {
+typedef struct {
UsefulBuf UB;
size_t size; // size of the buffer (not the valid data in the buffer)
uint16_t magic; // Used to detect corruption and lack of initialization
@@ -429,11 +424,9 @@
/**
@brief Initialize and supply the actual output buffer
- @param[out] pOutBuf The UsefulOutBuf to initialize
+ @param[out] me The UsefulOutBuf to initialize
@param[in] pStorage Pointer to data buffer to use
- @param[in] nStorageSize Size of buffer pStorage
-
- @return None
+ @param[in] uStorageSize Size of buffer pStorage
Intializes the UsefulOutBuf with storage. Sets the current position
to the beginning of the buffer clears the error.
@@ -516,8 +509,6 @@
@param[in] NewData UsefulBuf with the bytes to insert
@param[in] uPos Index in output buffer at which to insert
- @return None
-
NewData is the pointer and length for the bytes to be added to the
output buffer. There must be room in the output buffer for all of
NewData or an error will occur.
@@ -552,8 +543,6 @@
@param[in] pBytes Pointer to the bytes to insert
@param[in] uLen Length of the bytes to insert
@param[in] uPos Index in output buffer at which to insert
-
- @return None
See UsefulOutBuf_InsertUsefulBuf() for details. This is the same with
the difference being a pointer and length is passed in rather than an
@@ -574,7 +563,6 @@
@param[in] me Pointer to the UsefulOutBuf
@param[in] szString string to append
- @return None
*/
static inline void UsefulOutBuf_InsertString(UsefulOutBuf *me, const char *szString, size_t uPos)
{
@@ -586,10 +574,8 @@
@brief Insert a byte into the UsefulOutBuf
@param[in] me Pointer to the UsefulOutBul
- @param[in] pByte Bytes to insert
- @param[in] nPos Index in output buffer at which to insert
-
- @return None
+ @param[in] byte Bytes to insert
+ @param[in] uPos Index in output buffer at which to insert
See UsefulOutBuf_InsertUsefulBuf() for details. This is the same with
the difference being a single byte is to be inserted.
@@ -605,9 +591,7 @@
@param[in] me Pointer to the UsefulOutBul
@param[in] uInteger16 Integer to insert
- @param[in] nPos Index in output buffer at which to insert
-
- @return None
+ @param[in] uPos Index in output buffer at which to insert
See UsefulOutBuf_InsertUsefulBuf() for details. This is the same with
the difference being a single byte is to be inserted.
@@ -629,9 +613,7 @@
@param[in] me Pointer to the UsefulOutBul
@param[in] uInteger32 Integer to insert
- @param[in] nPos Index in output buffer at which to insert
-
- @return None
+ @param[in] uPos Index in output buffer at which to insert
See UsefulOutBuf_InsertUsefulBuf() for details. This is the same with
the difference being a single byte is to be inserted.
@@ -655,9 +637,7 @@
@param[in] me Pointer to the UsefulOutBul
@param[in] uInteger64 Integer to insert
- @param[in] nPos Index in output buffer at which to insert
-
- @return None
+ @param[in] uPos Index in output buffer at which to insert
See UsefulOutBuf_InsertUsefulBuf() for details. This is the same with
the difference being a single byte is to be inserted.
@@ -685,9 +665,7 @@
@param[in] me Pointer to the UsefulOutBul
@param[in] f Integer to insert
- @param[in] nPos Index in output buffer at which to insert
-
- @return None
+ @param[in] uPos Index in output buffer at which to insert
See UsefulOutBuf_InsertUsefulBuf() for details. This is the same with
the difference being a single byte is to be inserted.
@@ -707,9 +685,7 @@
@param[in] me Pointer to the UsefulOutBul
@param[in] d Integer to insert
- @param[in] nPos Index in output buffer at which to insert
-
- @return None
+ @param[in] uPos Index in output buffer at which to insert
See UsefulOutBuf_InsertUsefulBuf() for details. This is the same with
the difference being a single byte is to be inserted.
@@ -730,8 +706,6 @@
@param[in] me Pointer to the UsefulOutBuf
@param[in] NewData UsefulBuf with the bytes to append
- @return None
-
See UsefulOutBuf_InsertUsefulBuf() for details. This does the same
with the insertion point at the end of the valid data.
@@ -748,9 +722,7 @@
@param[in] me Pointer to the UsefulOutBuf
@param[in] pBytes Pointer to bytes to append
- @param[in] nLen Index in output buffer at which to append
-
- @return None
+ @param[in] uLen Index in output buffer at which to append
See UsefulOutBuf_InsertUsefulBuf() for details. This does the same
with the insertion point at the end of the valid data.
@@ -769,7 +741,6 @@
@param[in] me Pointer to the UsefulOutBuf
@param[in] szString string to append
- @return None
*/
static inline void UsefulOutBuf_AppendString(UsefulOutBuf *me, const char *szString)
{
@@ -1001,7 +972,7 @@
#define UIB_MAGIC (0xB00F)
-typedef struct __UsefulInputBuf {
+typedef struct {
UsefulBufC UB;
size_t cursor;
uint16_t magic;
@@ -1044,9 +1015,7 @@
Sets current position in input buffer
@param[in] me Pointer to the UsefulInputBuf.
- @param[in] nPos Position to set to
-
- @return None.
+ @param[in] uPos Position to set to
If the position is off the end of the input buffer, the error state
is entered and all functions will do nothing.
diff --git a/inc/qcbor.h b/inc/qcbor.h
index 130d05a..cf34844 100644
--- a/inc/qcbor.h
+++ b/inc/qcbor.h
@@ -722,7 +722,7 @@
*/
static inline EncodedCBORC EncodedCBORConst(const EncodedCBOR ECBOR)
{
- return (EncodedCBORC){UsefulBufConst(ECBOR.Bytes), ECBOR.uItems};
+ return (EncodedCBORC){UsefulBuf_Const(ECBOR.Bytes), ECBOR.uItems};
}
@@ -744,9 +744,6 @@
@param[out] pBuf The buffer into which this encoded result will be placed.
@param[in] uBufLen The length of pBuf.
- @return
- None.
-
Call this once at the start of an encoding of a CBOR structure. Then
call the various QCBOREncode_AddXXX() functions to add the data
items. Then call QCBOREncode_Finish().
@@ -782,10 +779,7 @@
@param[in] szLabel The string map label for this integer value.
@param[in] nLabel The integer map label for this integer value.
@param[in] uTag A CBOR type 6 tag
- @param[in] uNum The integer to add.
-
- @return
- None.
+ @param[in] nNum The integer to add.
The functions and macros with a "U" add unsigned integers and those
without add signed. The main reason to use the unsigned versions is
@@ -854,10 +848,7 @@
@param[in] szLabel The string map label for this integer value.
@param[in] nLabel The integer map label for this integer value.
@param[in] uTag A CBOR type 6 tag
- @param[in] Num The float to add.
-
- @return
- None.
+ @param[in] fNum The float to add.
This works the same as QCBOREncode_AddInt64_3() except it is for floats and doubles.
@@ -894,9 +885,6 @@
@param[in] nLabel The integer map label for this integer value.
@param[in] date Number of seconds since 1970-01-01T00:00Z in UTC time.
- @return
- None.
-
As per RFC 7049 this is similar to UNIX/Linux/POSIX dates. This is
the most compact way to specify a date and time in CBOR. Note that this
is always UTC and does not include the time zone. Use
@@ -943,12 +931,9 @@
@param[in] pCtx The context to initialize.
@param[in] szLabel The string map label for this integer value.
@param[in] nLabel The integer map label for this integer value.
- @param[in[ uTag Optional CBOR data tag or CBOR_TAG_NONE.
+ @param[in] uTag Optional CBOR data tag or CBOR_TAG_NONE.
@param[in] Bytes Pointer and length of the input data.
- @return
- None.
-
Simply adds the bytes to the encoded output and CBOR major type 2.
If called with Bytes.len equal to 0, an empty string will be
@@ -1006,12 +991,9 @@
@param[in] pCtx The context to initialize.
@param[in] szLabel The string map label for this integer value.
@param[in] nLabel The integer map label for this integer value.
- @param[in[ uTag Optional CBOR data tag or CBOR_TAG_NONE.
+ @param[in] uTag Optional CBOR data tag or CBOR_TAG_NONE.
@param[in] Bytes Pointer and length of text to add.
- @return
- None
-
The text passed in must be unencoded UTF-8 according to RFC
3629. There is no NULL termination.
@@ -1143,9 +1125,6 @@
@param[in] nLabel The integer map label for this integer value.
@param[in] uTag Optional CBOR data tag or CBOR_TAG_NONE.
@param[in] uSimple One of CBOR_SIMPLEV_FALSE through _UNDEF
-
- @return
- None.
CBOR defines encoding for special values "true", "false", "null" and "undef". This
function can add these values.
@@ -1172,10 +1151,7 @@
@param[in] szLabel A string label for the bytes to add. NULL if no label.
@param[in] nLabel The integer map label for this integer value.
@param[in] uTag Optional CBOR data tag or CBOR_TAG_NONE.
- @param[in] bool true or false from stdbool. Anything will result in an error.
-
- @return
- None.
+ @param[in] b true or false from stdbool. Anything will result in an error.
Error handling is the same as QCBOREncode_AddInt64_3().
*/
@@ -1207,9 +1183,6 @@
@param[in] uTag A tag for the whole map or CBOR_TAG_NONE.
@param[in] bBstrWrap Indicates entire map should be wrapped as a binary string. Normally 0.
- @return
- None.
-
Arrays are the basic CBOR aggregate or structure type. Call this
function to start or open an array. The call the various AddXXX
functions to add the items that go into the array. Then call
@@ -1269,9 +1242,6 @@
@param[in] uTag A tag for the whole map or CBOR_TAG_NONE.
@param[in] bBstrWrap Indicates entire map should be wrapped as a binary string. Normally 0.
- @return
- None.
-
See QCBOREncode_OpenArray() for more information.
When adding items to maps, they must be added in pairs, the label and
@@ -1309,9 +1279,6 @@
@param[in] pCtx The context to add to.
- @return
- None.
-
This reduces the nesting level by one.
If more Close's have been called than Open's the error state is
@@ -1330,12 +1297,7 @@
Add some already-encoded CBOR bytes
@param[in] pCtx The context to add to.
- @param[in] pEncodedCBOR The already-encoded CBOR to add to the context.
- @param[in] nEncodedLength The length of pEncodedCBOR.
- @param[in] nItems The number of items in the encoded CBOR.
-
- @return
- None.
+ @param[in] Encoded The already-encoded CBOR to add to the context.
The CBOR added here must be self-consistent and not have any arrays
or maps open. Specifically, if an array or map with N encoded items is
@@ -1368,12 +1330,9 @@
@param[in] pCtx The encoding context to add the simple value to.
@param[in] szLabel A string label for the bytes to add. NULL if no label.
@param[in] nLabel The integer map tag / label for this integer value.
- @param[in[ uTag Optional CBOR data tag or CBOR_TAG_NONE.
+ @param[in] uTag Optional CBOR data tag or CBOR_TAG_NONE.
@param[in] uSimple One of CBOR_SIMPLEV_xxx.
- @return
- None.
-
There should be no need to use this function directly unless some
extensions to the CBOR standard are created and put to use. All the defined
simple types are available via the macros for false...null
@@ -1473,9 +1432,6 @@
@param[in] EncodedCBOR The buffer with CBOR encoded bytes to be decoded.
@param[in] nMode One of QCBOR_DECODE_MODE_xxx
- @return
- None.
-
Initialize context for a pre-order traveral of the encoded CBOR tree.
Three decoding modes are supported. In normal mode, maps are decoded
@@ -1606,8 +1562,8 @@
/**
Convert int64_t to smaller int's safely
- @param src[in] An int64_t
- @param dest[out] A smaller sized int to convert to
+ @param [in] src An int64_t
+ @param [out] dest A smaller sized int to convert to
@return 0 on success -1 if not
diff --git a/src/UsefulBuf.c b/src/UsefulBuf.c
index 7fc5e12..a0cc9b6 100644
--- a/src/UsefulBuf.c
+++ b/src/UsefulBuf.c
@@ -50,9 +50,7 @@
=====================================================================================*/
-#include <string.h>
#include "UsefulBuf.h"
-#include <stringl.h>
#define USEFUL_OUT_BUF_MAGIC (0x0B0F) // used to catch use of uninitialized or corrupted UOBs
@@ -64,7 +62,7 @@
if(Src.len > pDest->len)
return 1;
- memscpy(pDest->ptr, pDest->len, Src.ptr, Src.len);
+ memcpy(pDest->ptr, Src.ptr, Src.len);
pDest->len = Src.len;
@@ -228,14 +226,14 @@
size_t uRoomInDestination = me->size - (uInsertionPos + NewData.len); // PtrMath #4
if(uNumBytesToMove && me->UB.ptr) {
- memsmove(pDestinationOfMove, uRoomInDestination, pSourceOfMove, uNumBytesToMove);
+ memmove(pDestinationOfMove, pSourceOfMove, uNumBytesToMove);
}
/* 4. Put the new data in */
uint8_t *pInsertionPoint = ((uint8_t *)me->UB.ptr) + uInsertionPos; // PtrMath #5
uRoomInDestination = me->size - uInsertionPos; // PtrMath #6
if(me->UB.ptr) {
- memsmove(pInsertionPoint, uRoomInDestination, NewData.ptr, NewData.len);
+ memmove(pInsertionPoint, NewData.ptr, NewData.len);
}
me->UB.len += NewData.len ;
}
@@ -307,7 +305,7 @@
return 1; // buffer was too small
}
- memsmove(pBuf, uBufSize, B.ptr, B.len);
+ memmove(pBuf, B.ptr, B.len);
*puCopied = me->UB.len;
diff --git a/src/qcbor_decode.c b/src/qcbor_decode.c
index b412205..90d3bf3 100644
--- a/src/qcbor_decode.c
+++ b/src/qcbor_decode.c
@@ -50,11 +50,6 @@
#include "qcbor.h"
-#include <stdint.h>
-
-#ifdef QSEE
-#include "stringl.h"
-#endif
/*
diff --git a/src/qcbor_encode.c b/src/qcbor_encode.c
index 7b53ac1..14e13e8 100644
--- a/src/qcbor_encode.c
+++ b/src/qcbor_encode.c
@@ -50,11 +50,7 @@
=====================================================================================*/
#include "qcbor.h"
-#include <stdint.h>
-#ifdef QSEE
-#include "stringl.h"
-#endif
/*...... This is a ruler that is 80 characters long...........................*/