Proper factoring for UsefulOutBuf Storage
diff --git a/inc/qcbor/UsefulBuf.h b/inc/qcbor/UsefulBuf.h
index 14188c5..0a0d31c 100644
--- a/inc/qcbor/UsefulBuf.h
+++ b/inc/qcbor/UsefulBuf.h
@@ -43,6 +43,7 @@
when who what, where, why
-------- ---- --------------------------------------------------
+ 08/14/2024 llundblade Add UsefulOutBuf_RetrieveOutputStorage().
08/13/2024 llundblade Add UsefulInputBuf_RetrieveUndecodedInput().
08/08/2024 llundblade Add UsefulOutBuf_SubString().
10/05/2024 llundblade Add Xxx_OffsetToPointer.
@@ -1400,6 +1401,21 @@
/**
+ * @brief Retrieve the storage buffer passed in to UsefulOutBuf_Init().
+ *
+ * @param[in] pUOutBuf The encoding context.
+ *
+ * @return The output storage buffer passed to UsefulOutBuf_Init().
+ *
+ * This doesn't give any information about how much has been encoded
+ * or the error state. It just returns the exact \ref UsefulOutBuf given
+ * to UsefulOutBuf_Init().
+ */
+static UsefulBuf UsefulOutBuf_RetrieveOutputStorage(UsefulOutBuf *pUOutBuf);
+
+
+
+/**
* @ref UsefulInputBuf is the counterpart to @ref UsefulOutBuf. It is
* for parsing data received. Initialize it with the data from the
* network. Then use the functions like UsefulInputBuf_GetBytes() to
@@ -2254,6 +2270,14 @@
}
+static inline UsefulBuf UsefulOutBuf_RetrieveOutputStorage(UsefulOutBuf *pMe)
+{
+ return pMe->UB;
+}
+
+
+
+
static inline void UsefulInputBuf_Init(UsefulInputBuf *pMe, UsefulBufC UB)
diff --git a/inc/qcbor/qcbor_encode.h b/inc/qcbor/qcbor_encode.h
index 169d338..d6757a8 100644
--- a/inc/qcbor/qcbor_encode.h
+++ b/inc/qcbor/qcbor_encode.h
@@ -2313,24 +2313,23 @@
* for other too.
*
* Call this to get the offset of the start of the encoded
- * to-be-hashed CBOR items, then call
- * QCBOREncode_SubString(). QCBOREncode_Tell() can also be called
- * twice, first to get the offset of the start and second for the
- * offset of the end. Those offsets can be applied to the output
- * storage buffer.
+ * to-be-hashed CBOR items, then call QCBOREncode_SubString().
+ * QCBOREncode_Tell() can also be called twice, first to get the
+ * offset of the start and second for the offset of the end. Those
+ * offsets can be applied to the output storage buffer.
*
* This will return successfully even if the encoder is in the error
* state.
*
* WARNING: All definite-length arrays and maps opened before the
- * first call QCBOREncode_Tell() must not be closed until the
+ * first call to QCBOREncode_Tell() must not be closed until the
* substring is obtained and processed. Simiarly, every
* definite-length array or map opened after the first call to
* QCBOREncode_Tell() must be closed before the substring is obtained
- * and processed. There is no detection of these errors. This is
- * because QCBOR goes back and inserts the lengths of definite-length
- * arrays and maps when they are closed. This insertion will make the
- * offsets incorrect.
+ * and processed. The same applies for opened bytte strings. There is
+ * no detection of these errors. This occurs because QCBOR goes back
+ * and inserts the lengths of definite-length arrays and maps when
+ * they are closed. This insertion will make the offsets incorrect.
*/
static size_t
QCBOREncode_Tell(QCBOREncodeContext *pCtx);
@@ -4104,7 +4103,7 @@
static inline UsefulBuf
QCBOREncode_RetrieveOutputStorage(QCBOREncodeContext *pMe)
{
- return pMe->OutBuf.UB;
+ return UsefulOutBuf_RetrieveOutputStorage(&(pMe->OutBuf));
}