]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - contrib/libcbor/doc/source/api/type_5.rst
zfs: merge openzfs/zfs@6c3c5fcfb (zfs-2.1-release) into stable/13
[FreeBSD/FreeBSD.git] / contrib / libcbor / doc / source / api / type_5.rst
1 Type 5 – Maps
2 =============================
3
4 CBOR maps are the plain old associate hash maps known from JSON and many other formats and languages, with one exception: any CBOR data item can be a key, not just strings. This is somewhat unusual and you, as an application developer, should keep that in mind.
5
6 Maps can be either definite or indefinite, in much the same way as :doc:`type_4`.
7
8 ==================================  =====================================================================================
9 Corresponding :type:`cbor_type`     ``CBOR_TYPE_MAP``
10 Number of allocations (definite)    Two plus any manipulations with the data
11 Number of allocations (indefinite)  Two plus logarithmically many
12                                     reallocations relative to additions
13 Storage requirements (definite)     ``sizeof(cbor_pair) * size + sizeof(cbor_item_t)``
14 Storage requirements (indefinite)   ``<= sizeof(cbor_item_t) + sizeof(cbor_pair) * size * BUFFER_GROWTH``
15 ==================================  =====================================================================================
16
17 Streaming maps
18 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
19
20 Please refer to :doc:`/streaming`.
21
22 Getting metadata
23 ~~~~~~~~~~~~~~~~~
24 .. doxygenfunction:: cbor_map_size
25 .. doxygenfunction:: cbor_map_allocated
26 .. doxygenfunction:: cbor_map_is_definite
27 .. doxygenfunction:: cbor_map_is_indefinite
28
29 Reading data
30 ~~~~~~~~~~~~~
31
32 .. doxygenfunction:: cbor_map_handle
33
34 Creating new items
35 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
36
37 .. doxygenfunction:: cbor_new_definite_map
38 .. doxygenfunction:: cbor_new_indefinite_map
39
40
41 Modifying items
42 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
43
44 .. doxygenfunction:: cbor_map_add