libcbor 0.12.0
libcbor is a C library for parsing and generating CBOR, the general-purpose schema-less binary data format.
Loading...
Searching...
No Matches
tags.c
Go to the documentation of this file.
1/*
2 * Copyright (c) 2014-2020 Pavel Kalvoda <me@pavelkalvoda.com>
3 *
4 * libcbor is free software; you can redistribute it and/or modify
5 * it under the terms of the MIT license. See LICENSE for details.
6 */
7
8#include "tags.h"
9
10cbor_item_t* cbor_new_tag(uint64_t value) {
11 cbor_item_t* item = _cbor_malloc(sizeof(cbor_item_t));
12 _CBOR_NOTNULL(item);
13
14 *item = (cbor_item_t){
15 .refcount = 1,
16 .type = CBOR_TYPE_TAG,
17 .metadata = {.tag_metadata = {.value = value, .tagged_item = NULL}},
18 .data = NULL /* Never used */
19 };
20 return item;
21}
22
27
28uint64_t cbor_tag_value(const cbor_item_t* tag) {
30 return tag->metadata.tag_metadata.value;
31}
32
33void cbor_tag_set_item(cbor_item_t* tag, cbor_item_t* tagged_item) {
35 cbor_incref(tagged_item);
36 tag->metadata.tag_metadata.tagged_item = tagged_item;
37}
38
39cbor_item_t* cbor_build_tag(uint64_t value, cbor_item_t* item) {
40 cbor_item_t* res = cbor_new_tag(value);
41 if (res == NULL) {
42 return NULL;
43 }
44 cbor_tag_set_item(res, item);
45 return res;
46}
_cbor_malloc_t _cbor_malloc
Definition allocators.c:10
bool cbor_isa_tag(const cbor_item_t *item)
Does the item have the appropriate major type?
Definition common.c:46
cbor_item_t * cbor_incref(cbor_item_t *item)
Increases the item's reference count by one.
Definition common.c:78
#define _CBOR_NOTNULL(cbor_item)
Definition common.h:111
#define CBOR_ASSERT(e)
Definition common.h:73
@ CBOR_TYPE_TAG
6 - tags
Definition data.h:37
uint64_t value
Definition data.h:137
struct cbor_item_t * tagged_item
Definition data.h:136
The item handle.
Definition data.h:171
union cbor_item_metadata metadata
Discriminated by type.
Definition data.h:173
cbor_item_t * cbor_tag_item(const cbor_item_t *tag)
Get the tagged item (what the tag points to).
Definition tags.c:23
uint64_t cbor_tag_value(const cbor_item_t *tag)
Get the tag value.
Definition tags.c:28
cbor_item_t * cbor_build_tag(uint64_t value, cbor_item_t *item)
Build a new tag.
Definition tags.c:39
void cbor_tag_set_item(cbor_item_t *tag, cbor_item_t *tagged_item)
Assign a tag to an item.
Definition tags.c:33
cbor_item_t * cbor_new_tag(uint64_t value)
Create a new tag.
Definition tags.c:10
struct _cbor_tag_metadata tag_metadata
Definition data.h:166