Skip to content

Commit 59a2c23

Browse files
author
Laurence Lundblade
committed
Improve documentation for tag decoding
1 parent 2530482 commit 59a2c23

File tree

3 files changed

+51
-41
lines changed

3 files changed

+51
-41
lines changed

doc/Tagging.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,7 @@ tag that QCBOR did not.
161161
Nesting of tags is certainly used in CBOR protocols, but deep nesting
162162
is less common so QCBOR has an implementation limit of 4 levels of tag
163163
encapsulation on some tag content. (This can be increased by changing
164-
QCBOR_MAX_TAGS_PER_ITEM, but it will increase stack memory use by
164+
@ref QCBOR_MAX_TAGS_PER_ITEM, but it will increase stack memory use by
165165
increasing the size of a QCBORItem).
166166

167167
QCBOR also saves memory by mapping the tag values larger than

inc/qcbor/qcbor_main_decode.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -289,7 +289,7 @@ typedef enum {
289289

290290
/**
291291
* The maximum number of tags that may occur on an individual nested
292-
* item. Typically 4.
292+
* item. Typically 4. This is a QCBOR implementation limit.
293293
*/
294294
#define QCBOR_MAX_TAGS_PER_ITEM QCBOR_MAX_TAGS_PER_ITEM1
295295

inc/qcbor/qcbor_tag_decode.h

Lines changed: 49 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ extern "C" {
2929
* @anchor TagDecoding
3030
* ## Tag Decoding
3131
*
32-
* See @ref CBORTags first if you are unfamiliar with the notion of
32+
* See @ref CBORTags first if you are unfamiliar with
3333
* tags in CBOR.
3434
*
3535
* QCBOR v2 offers several ways to decode tags.
@@ -188,12 +188,12 @@ enum QCBORDecodeTagReq {
188188

189189
#ifndef QCBOR_DISABLE_TAGS
190190
/**
191-
* @brief Returns the tag numbers for an item.
191+
* @brief Get the next tag number.
192192
*
193-
* @param[in] pCtx The decoder context.
193+
* @param[in] pCtx The decoder context.
194194
* @param[out] puTagNumber The returned tag number.
195195
*
196-
* In QCBOR v2, all tag numbers on an item MUST be fetched with this
196+
* In QCBOR v2, all tag numbers on an item must be fetched with this
197197
* method. If not, @ref QCBOR_ERR_UNPROCESSED_TAG_NUMBER will
198198
* occur. This is a major change from QCBORv1. The QCBOR v1 behavior
199199
* is too lax for proper CBOR decoding. When a tag number occurs it
@@ -202,7 +202,7 @@ enum QCBORDecodeTagReq {
202202
* incorrectly characterized as optional implying they could be
203203
* ignored.
204204
*
205-
* In typical item decoding, tag numbers are not used, not present and
205+
* In much item decoding, tag numbers are not used, not present and
206206
* not expected. There's no need to call this.
207207
*
208208
* When the protocol being decoded does use a tag number then this
@@ -216,8 +216,8 @@ enum QCBORDecodeTagReq {
216216
* number to switch the flow of decoding. If there's a possibility of
217217
* a tag number then this must be called.
218218
*
219-
* If this is called and there is no tag number, then this will return
220-
* @ref QCBOR_SUCCESS and the tag number returned will be
219+
* If this is called and there is no tag number, then this will succeed
220+
* (no error will be set) and the tag number returned will be
221221
* @ref CBOR_TAG_INVALID64.
222222
*
223223
* Usually there is only one tag number per item, but CBOR allows
@@ -236,9 +236,9 @@ QCBORDecode_VGetNextTagNumber(QCBORDecodeContext *pCtx, uint64_t *puTagNumber);
236236

237237

238238
/**
239-
* @brief Returns the tag numbers for an item.
239+
* @brief Get the next tag number.
240240
*
241-
* @param[in] pCtx The decoder context.
241+
* @param[in] pCtx The decoder context.
242242
* @param[out] puTagNumber The returned tag number.
243243
*
244244
* @return See error table of decoding errors set by QCBORDecode_VGetNext().
@@ -258,30 +258,31 @@ QCBORError
258258
QCBORDecode_GetNextTagNumberInMapSZ(QCBORDecodeContext *pCtx, const char *szLabel, uint64_t *puTagNumber);
259259

260260

261-
262261
/**
263262
* @brief Returns the tag numbers for a decoded item.
264263
*
265264
* @param[in] pCtx The decoder context.
266-
* @param[in] pItem The CBOR item to get the tag for.
267-
* @param[in] uIndex The index of the tag to get.
265+
* @param[in] pItem The decoded CBOR item to get the tag number from.
266+
* @param[in] uIndex The index of the tag to get.
268267
*
269268
* @returns The nth tag number or @ref CBOR_TAG_INVALID64.
270269
*
271-
* Typically, this is only used with @ref QCBOR_DECODE_ALLOW_UNPROCESSED_TAG_NUMBERS.
272-
* Normally, tag numbers are processed QCBORDecode_VGetNextTagNumber() or
273-
* QCBORTagContentCallBack.
270+
* Tag numbers are typically processed by consuming them with
271+
* QCBORDecode_VGetNextTagNumber() or a QCBORTagContentCallBack(),
272+
* rather than this function. Use of this function should not be mixed
273+
* with use of QCBORDecode_VGetNextTagNumber() or
274+
* QCBORDecode_GetNextTagNumber().
274275
*
275-
* TODO: rewrite this paragraph
276-
* TODO: are tag not fetched by QCBORDecode_VGetNextTagNumber put here?
277-
* When QCBOR decodes an item that is a tag, it will fully decode tags
278-
* it is able to. Tags that it is unable to process are put in a list
279-
* in the QCBORItem.
276+
* When QCBOR is initialized with
277+
* @ref QCBOR_DECODE_ALLOW_UNPROCESSED_TAG_NUMBERS, tag numbers preceding
278+
* an item are accumulated and associated with the QCBORItem (as was
279+
* always done in QCBOR v1). This function retrieves them from the
280+
* item. They cannot be accessed directly from @c pItem because they
281+
* are mapped to save space.
280282
*
281-
* Tags nest. Here the tag with index 0 is the outermost, the one
282-
* furthest form the data item that is the tag content. This is
283-
* the opposite order of QCBORDecode_GetNthTag(), but more
284-
* useful.
283+
* Tags nest. The tag at index 0 is the outermost, the furthest from
284+
* the tagged data item. This ordering is the reverse of
285+
* QCBORDecode_GetNthTag(), but is generally more useful.
285286
*
286287
* Deep tag nesting is rare so this implementation imposes a limit of
287288
* @ref QCBOR_MAX_TAGS_PER_ITEM on nesting and returns @ref
@@ -290,15 +291,16 @@ QCBORDecode_GetNextTagNumberInMapSZ(QCBORDecodeContext *pCtx, const char *szLabe
290291
* the constant can be increased and the library recompiled. It will
291292
* use more memory).
292293
*
293-
* See also @ref TagDecoding @ref CBORTags.
294+
* Deep tag nesting is rare, so this implementation limits nesting to
295+
* @ref QCBOR_MAX_TAGS_PER_ITEM. If this limit is exceeded,
296+
* @ref QCBOR_ERR_TOO_MANY_TAGS is returned. This constraint is
297+
* specific to this implementation, not CBOR itself .
294298
*
295-
* To reduce memory used by a @ref QCBORItem, tag numbers larger than
296-
* @c UINT16_MAX are mapped so the tag numbers in @c auTagNumbers must be
297-
* accessed with this function rather than directly.
299+
* See also @ref TagDecoding @ref CBORTags.
298300
*
299-
* This returns @ref CBOR_TAG_INVALID64 if any error occurred when
300-
* getting the item. This is also returned if there are no tags on the
301-
* item or no tag at @c uIndex.
301+
* If an error occurs when retrieving the item, or if the item has no
302+
* tags or no tag at @c uIndex, this function returns @ref
303+
* CBOR_TAG_INVALID64.
302304
*/
303305
uint64_t
304306
QCBORDecode_GetNthTagNumber(const QCBORDecodeContext *pCtx, const QCBORItem *pItem, uint8_t uIndex);
@@ -312,14 +314,22 @@ QCBORDecode_GetNthTagNumber(const QCBORDecodeContext *pCtx, const QCBORItem *pIt
312314
*
313315
* @returns The nth tag number or @ref CBOR_TAG_INVALID64.
314316
*
315-
* This returns tags of the most recently decoded item. See
316-
* QCBORDecode_GetNthTagNumber(). This is particularly of use for spiffy
317-
* decode functions that don't return a @ref QCBORItem.
318-
*
319-
* This does not work for QCBORDecode_GetNext(),
320-
* QCBORDecode_PeekNext(), QCBORDecode_VPeekNext() or
321-
* QCBORDecode_VGetNextConsume() but these all return a
322-
* @ref QCBORItem, so it is not necessary.
317+
* Like QCBORDecode_GetNthTagNumber(), this function is used when
318+
* QCBOR is initialized with
319+
* @ref QCBOR_DECODE_ALLOW_UNPROCESSED_TAG_NUMBERS. It returns the tag
320+
* numbers of the most recently decoded item. See
321+
* QCBORDecode_GetNthTagNumber().
322+
*
323+
* This is useful with spiffy decode functions that do not return a
324+
* @ref QCBORItem. Use of this function should not be mixed with use
325+
* of QCBORDecode_VGetNextTagNumber() or
326+
* QCBORDecode_GetNextTagNumber().
327+
*
328+
* It does not work with QCBORDecode_GetNext(),
329+
* QCBORDecode_PeekNext(), QCBORDecode_VPeekNext(), or
330+
* QCBORDecode_VGetNextConsume() as these return the tag numbers in a
331+
* @ref QCBORItem rather than save them as the last tags in the decode
332+
* context.
323333
*
324334
* If a decoding error is set, then this returns @ref CBOR_TAG_INVALID64.
325335
*/

0 commit comments

Comments
 (0)