Type 6 – Semantic tags

Tag are additional metadata that can be used to extend or specialize the meaning or interpretation of the other data items.

For example, one might tag an array of numbers to communicate that it should be interpreted as a vector.

Please consult the official IANA repository of CBOR tags for known registered values.

Please note that libcbor does not understand the semantics of tags and will process all well-formed tags regardless of whether they are valid with respect to the data they are applied to.

Corresponding cbor_type

CBOR_TYPE_TAG

Number of allocations

One plus any manipulations with the data reallocations relative to chunk count

Storage requirements

sizeof(cbor_item_t) + the tagged item

cbor_item_t *cbor_new_tag(uint64_t value)

Create a new tag.

param value:

The tag value (number).

return:

Reference to the new tag. Its reference count is initialized to one and it points to a NULL item.

return:

NULL if memory allocation fails.

cbor_item_t *cbor_tag_item(const cbor_item_t *tag)

Get the tagged item (what the tag points to).

Increases the reference count of the underlying item. The returned reference must be released using cbor_decref.

param tag:

A CBOR_TYPE_TAG tag.

return:

Reference to the tagged item.

uint64_t cbor_tag_value(const cbor_item_t *tag)

Get the tag value.

param tag:

A CBOR_TYPE_TAG tag.

return:

The tag value (number).

void cbor_tag_set_item(cbor_item_t *tag, cbor_item_t *tagged_item)

Assign a tag to an item.

If the tag already points to an item, the pointer will be replaced, without a reference count change on the previous item. TODO: Should we release the reference automatically?

param tag:

A CBOR_TYPE_TAG tag.

param tagged_item:

The item to tag. Its reference count will be increased by one.