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 #ifndef LIBCBOR_TAGS_H 9 #define LIBCBOR_TAGS_H 10 11 #include "cbor/cbor_export.h" 12 #include "cbor/common.h" 13 14 #ifdef __cplusplus 15 extern "C" { 16 #endif 17 18 /* 19 * ============================================================================ 20 * Tag manipulation 21 * ============================================================================ 22 */ 23 24 /** Create a new tag 25 * 26 * @param value The tag value. Please consult the tag repository 27 * @return Reference to the new tag item. The item's reference count is 28 * initialized to one. 29 * @return `NULL` if memory allocation fails 30 */ 31 _CBOR_NODISCARD CBOR_EXPORT cbor_item_t *cbor_new_tag(uint64_t value); 32 33 /** Get the tagged item 34 * 35 * @param item A tag 36 * @return Reference to the tagged item 37 * 38 * Increases the reference count of the underlying item. The returned reference 39 * must be released using #cbor_decref. 40 */ 41 _CBOR_NODISCARD CBOR_EXPORT cbor_item_t *cbor_tag_item(const cbor_item_t *item); 42 43 /** Get tag value 44 * 45 * @param item A tag 46 * @return The tag value. Please consult the tag repository 47 */ 48 _CBOR_NODISCARD CBOR_EXPORT uint64_t cbor_tag_value(const cbor_item_t *item); 49 50 /** Set the tagged item 51 * 52 * @param item A tag 53 * @param tagged_item The item to tag. Its reference count will be increased 54 * by one. 55 */ 56 CBOR_EXPORT void cbor_tag_set_item(cbor_item_t *item, cbor_item_t *tagged_item); 57 58 /** Build a new tag 59 * 60 * @param item The item to tag. Its reference count will be increased by 61 * one. 62 * @param value Tag value 63 * @return Reference to the new tag item. The item's reference count is 64 * initialized to one. 65 * @return `NULL` if memory allocation fails 66 */ 67 _CBOR_NODISCARD CBOR_EXPORT cbor_item_t *cbor_build_tag(uint64_t value, 68 cbor_item_t *item); 69 70 #ifdef __cplusplus 71 } 72 #endif 73 74 #endif // LIBCBOR_TAGS_H 75