xref: /freebsd/contrib/libcbor/src/cbor.h (revision 5d3e7166)
110ff414cSEd Maste /*
210ff414cSEd Maste  * Copyright (c) 2014-2020 Pavel Kalvoda <me@pavelkalvoda.com>
310ff414cSEd Maste  *
410ff414cSEd Maste  * libcbor is free software; you can redistribute it and/or modify
510ff414cSEd Maste  * it under the terms of the MIT license. See LICENSE for details.
610ff414cSEd Maste  */
710ff414cSEd Maste 
810ff414cSEd Maste #ifndef LIBCBOR_H_
910ff414cSEd Maste #define LIBCBOR_H_
1010ff414cSEd Maste 
1110ff414cSEd Maste #include "cbor/common.h"
1210ff414cSEd Maste #include "cbor/data.h"
1310ff414cSEd Maste 
1410ff414cSEd Maste #include "cbor/arrays.h"
1510ff414cSEd Maste #include "cbor/bytestrings.h"
1610ff414cSEd Maste #include "cbor/floats_ctrls.h"
1710ff414cSEd Maste #include "cbor/ints.h"
1810ff414cSEd Maste #include "cbor/maps.h"
1910ff414cSEd Maste #include "cbor/strings.h"
2010ff414cSEd Maste #include "cbor/tags.h"
2110ff414cSEd Maste 
2210ff414cSEd Maste #include "cbor/callbacks.h"
2310ff414cSEd Maste #include "cbor/cbor_export.h"
2410ff414cSEd Maste #include "cbor/encoding.h"
2510ff414cSEd Maste #include "cbor/serialization.h"
2610ff414cSEd Maste #include "cbor/streaming.h"
2710ff414cSEd Maste 
2810ff414cSEd Maste #ifdef __cplusplus
2910ff414cSEd Maste extern "C" {
3010ff414cSEd Maste #endif
3110ff414cSEd Maste 
3210ff414cSEd Maste /*
3310ff414cSEd Maste  * ============================================================================
3410ff414cSEd Maste  * High level decoding
3510ff414cSEd Maste  * ============================================================================
3610ff414cSEd Maste  */
3710ff414cSEd Maste 
3810ff414cSEd Maste /** Loads data item from a buffer
3910ff414cSEd Maste  *
4010ff414cSEd Maste  * @param source The buffer
4110ff414cSEd Maste  * @param source_size
42*5d3e7166SEd Maste  * @param[out] result Result indicator. #CBOR_ERR_NONE on success
43*5d3e7166SEd Maste  * @return Decoded CBOR item. The item's reference count is initialized to one.
44*5d3e7166SEd Maste  * @return `NULL` on failure. In that case, \p result contains the location and
45*5d3e7166SEd Maste  * description of the error.
4610ff414cSEd Maste  */
47*5d3e7166SEd Maste _CBOR_NODISCARD CBOR_EXPORT cbor_item_t* cbor_load(
48*5d3e7166SEd Maste     cbor_data source, size_t source_size, struct cbor_load_result* result);
4910ff414cSEd Maste 
50*5d3e7166SEd Maste /** Take a deep copy of an item
5110ff414cSEd Maste  *
52*5d3e7166SEd Maste  * All items this item points to (array and map members, string chunks, tagged
53*5d3e7166SEd Maste  * items) will be copied recursively using #cbor_copy. The new item doesn't
54*5d3e7166SEd Maste  * alias or point to any items from the original \p item. All the reference
55*5d3e7166SEd Maste  * counts in the new structure are set to one.
5610ff414cSEd Maste  *
57*5d3e7166SEd Maste  * @param item item to copy
58*5d3e7166SEd Maste  * @return Reference to the new item. The item's reference count is initialized
59*5d3e7166SEd Maste  * to one.
60*5d3e7166SEd Maste  * @return `NULL` if memory allocation fails
6110ff414cSEd Maste  */
62*5d3e7166SEd Maste _CBOR_NODISCARD CBOR_EXPORT cbor_item_t* cbor_copy(cbor_item_t* item);
6310ff414cSEd Maste 
6410ff414cSEd Maste #if CBOR_PRETTY_PRINTER
6510ff414cSEd Maste #include <stdio.h>
6610ff414cSEd Maste 
6710ff414cSEd Maste CBOR_EXPORT void cbor_describe(cbor_item_t* item, FILE* out);
6810ff414cSEd Maste #endif
6910ff414cSEd Maste 
7010ff414cSEd Maste #ifdef __cplusplus
7110ff414cSEd Maste }
7210ff414cSEd Maste #endif
7310ff414cSEd Maste 
7410ff414cSEd Maste #endif  // LIBCBOR_H_
75