1Type 4 – Arrays
2=============================
3
4CBOR arrays, just like :doc:`byte strings <type_2>` and :doc:`strings <type_3>`, can be encoded either as definite, or as indefinite.
5
6==================================  =====================================================================================
7Corresponding :type:`cbor_type`     ``CBOR_TYPE_ARRAY``
8Number of allocations (definite)    Two plus any manipulations with the data
9Number of allocations (indefinite)  Two plus logarithmically many
10                                    reallocations relative to additions
11Storage requirements (definite)     ``(sizeof(cbor_item_t) + 1) * size``
12Storage requirements (indefinite)   ``<= sizeof(cbor_item_t) + sizeof(cbor_item_t) * size * BUFFER_GROWTH``
13==================================  =====================================================================================
14
15
16Examples
17~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
18
19::
20
21    0x9f        Start indefinite array
22        0x01        Unsigned integer 1
23        0xff        "Break" control token
24
25::
26
27    0x9f        Start array, 1B length follows
28    0x20        Unsigned integer 32
29        ...        32 items follow
30
31Streaming indefinite arrays
32~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
33
34Please refer to :doc:`/streaming`.
35
36Getting metadata
37~~~~~~~~~~~~~~~~~
38
39.. doxygenfunction:: cbor_array_size
40.. doxygenfunction:: cbor_array_allocated
41.. doxygenfunction:: cbor_array_is_definite
42.. doxygenfunction:: cbor_array_is_indefinite
43
44Reading data
45~~~~~~~~~~~~~
46
47.. doxygenfunction:: cbor_array_handle
48.. doxygenfunction:: cbor_array_get
49
50Creating new items
51~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
52
53.. doxygenfunction:: cbor_new_definite_array
54.. doxygenfunction:: cbor_new_indefinite_array
55
56
57Modifying items
58~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
59
60.. doxygenfunction:: cbor_array_push
61.. doxygenfunction:: cbor_array_replace
62.. doxygenfunction:: cbor_array_set
63