1Type 5 – Maps 2============================= 3 4CBOR maps are the plain old associative maps similar JSON objects or Python dictionaries. 5 6Definite maps have a fixed size which is stored in the header, whereas indefinite maps do not and are terminated by a special "break" byte instead. 7 8Map are explicitly created or decoded as definite or indefinite and will be encoded using the corresponding wire representation, regardless of whether the actual size is known at the time of encoding. 9 10.. note:: 11 12 Indefinite maps can be conveniently used with streaming :doc:`decoding <streaming_decoding>` and :doc:`encoding <streaming_encoding>`. 13 Keys and values can simply be output one by one, alternating keys and values. 14 15.. warning:: Any CBOR data item is a legal map key (not just strings). 16 17================================== ===================================================================================== 18Corresponding :type:`cbor_type` ``CBOR_TYPE_MAP`` 19Number of allocations (definite) Two plus any manipulations with the data 20Number of allocations (indefinite) Two plus logarithmically many 21 reallocations relative to additions 22Storage requirements (definite) ``sizeof(cbor_pair) * size + sizeof(cbor_item_t)`` 23Storage requirements (indefinite) ``<= sizeof(cbor_item_t) + sizeof(cbor_pair) * size * BUFFER_GROWTH`` 24================================== ===================================================================================== 25 26Examples 27~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 28 29:: 30 31 0xbf Start indefinite map (represents {1: 2}) 32 0x01 Unsigned integer 1 (key) 33 0x02 Unsigned integer 2 (value) 34 0xff "Break" control token 35 36:: 37 38 0xa0 Map of size 0 39 40Getting metadata 41~~~~~~~~~~~~~~~~~ 42.. doxygenfunction:: cbor_map_size 43.. doxygenfunction:: cbor_map_allocated 44.. doxygenfunction:: cbor_map_is_definite 45.. doxygenfunction:: cbor_map_is_indefinite 46 47Reading data 48~~~~~~~~~~~~~ 49 50.. doxygenfunction:: cbor_map_handle 51 52Creating new items 53~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 54 55.. doxygenfunction:: cbor_new_definite_map 56.. doxygenfunction:: cbor_new_indefinite_map 57 58 59Modifying items 60~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 61 62.. doxygenfunction:: cbor_map_add 63