Merge some feature adds from QCBOR 1.x into dev
diff --git a/inc/qcbor/UsefulBuf.h b/inc/qcbor/UsefulBuf.h
index 1a4a3bf..95f0571 100644
--- a/inc/qcbor/UsefulBuf.h
+++ b/inc/qcbor/UsefulBuf.h
@@ -43,7 +43,8 @@
when who what, where, why
-------- ---- --------------------------------------------------
- 28/02/2022 llundblade Rearrange UsefulOutBuf_Compare().
+ 10/05/2024 llundblade Add Xxx_OffsetToPointer.
+ 28/02/2024 llundblade Rearrange UsefulOutBuf_Compare().
19/11/2023 llundblade Add UsefulOutBuf_GetOutput().
19/11/2023 llundblade Add UsefulOutBuf_Swap().
19/11/2023 llundblade Add UsefulOutBuf_Compare().
@@ -651,16 +652,27 @@
/**
- @brief Convert a pointer to an offset with bounds checking.
-
- @param[in] UB Pointer to the UsefulInputBuf.
- @param[in] p Pointer to convert to offset.
-
- @return SIZE_MAX if @c p is out of range, the byte offset if not.
+ * @brief Convert a pointer to an offset with bounds checking.
+ *
+ * @param[in] UB A UsefulBuf.
+ * @param[in] p Pointer to convert to offset.
+ *
+ * @return SIZE_MAX if @c p is out of range, the byte offset if not.
*/
static inline size_t UsefulBuf_PointerToOffset(UsefulBufC UB, const void *p);
+/**
+ * @brief Convert an offset to a pointer with bounds checking.
+ *
+ * @param[in] UB A UsefulBuf.
+ * @param[in] uOffset Offset in @c pUInBuf.
+ *
+ * @return @c NULL if @c uOffset is out of range, a pointer into the buffer if not.
+ */
+static inline const void *UsefulBuf_OffsetToPointer(UsefulBufC UB, size_t uOffset);
+
+
#ifndef USEFULBUF_DISABLE_DEPRECATED
/** Deprecated macro; use @ref UsefulBuf_FROM_SZ_LITERAL instead */
#define SZLiteralToUsefulBufC(szString) UsefulBuf_FROM_SZ_LITERAL(szString)
@@ -1589,7 +1601,18 @@
*
* @return SIZE_MAX if @c p is out of range, the byte offset if not.
*/
-static inline size_t UsefulInputBuf_PointerToOffset(UsefulInputBuf *pUInBuf, const void *p);
+static size_t UsefulInputBuf_PointerToOffset(UsefulInputBuf *pUInBuf, const void *p);
+
+
+/**
+ * @brief Convert an offset to a pointer with bounds checking.
+ *
+ * @param[in] pUInBuf Pointer to the @ref UsefulInputBuf.
+ * @param[in] uOffset Offset in @c pUInBuf.
+ *
+ * @return @c NULL if @c uOffset is out of range, a pointer into the buffer if not.
+ */
+static const void *UsefulInputBuf_OffsetToPointer(UsefulInputBuf *pUInBuf, size_t uOffset);
/**
@@ -1955,6 +1978,18 @@
}
+static inline const void *UsefulBuf_OffsetToPointer(UsefulBufC UB, size_t uOffset)
+{
+ if(UsefulBuf_IsNULLC(UB) || uOffset >= UB.len) {
+ return NULL;
+ }
+
+ return (const uint8_t *)UB.ptr + uOffset;
+}
+
+
+
+
#ifndef USEFULBUF_DISABLE_ALL_FLOAT
static inline uint32_t UsefulBufUtil_CopyFloatToUint32(float f)
{
@@ -2361,6 +2396,12 @@
}
+static inline const void *UsefulInputBuf_OffsetToPointer(UsefulInputBuf *pUInBuf, size_t uOffset)
+ {
+ return UsefulBuf_OffsetToPointer(pUInBuf->UB, uOffset);
+ }
+
+
static inline UsefulBufC UsefulInputBuf_GetUsefulBuf(UsefulInputBuf *pMe, size_t uNum)
{
const void *pResult = UsefulInputBuf_GetBytes(pMe, uNum);