xref: /freebsd-src/contrib/libcbor/doc/source/api/encoding.rst (revision 5d3e7166f6a0187fa3f8831b16a06bd9955c21ff)
110ff414cSEd MasteEncoding
210ff414cSEd Maste=============================
310ff414cSEd Maste
410ff414cSEd MasteThe easiest way to encode data items is using the :func:`cbor_serialize` or :func:`cbor_serialize_alloc` functions:
510ff414cSEd Maste
610ff414cSEd Maste.. doxygenfunction:: cbor_serialize
710ff414cSEd Maste.. doxygenfunction:: cbor_serialize_alloc
810ff414cSEd Maste
9*5d3e7166SEd MasteTo determine the number of bytes needed to serialize an item, use :func:`cbor_serialized_size`:
10*5d3e7166SEd Maste
11*5d3e7166SEd Maste.. doxygenfunction:: cbor_serialized_size
12*5d3e7166SEd Maste
1310ff414cSEd MasteType-specific serializers
1410ff414cSEd Maste~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1510ff414cSEd MasteIn case you know the type of the item you want to serialize beforehand, you can use one
1610ff414cSEd Masteof the type-specific serializers.
1710ff414cSEd Maste
1810ff414cSEd Maste.. note:: Unless compiled in debug mode, these do not verify the type. Passing an incorrect item will result in an undefined behavior.
1910ff414cSEd Maste
2010ff414cSEd Maste.. doxygenfunction:: cbor_serialize_uint
2110ff414cSEd Maste.. doxygenfunction:: cbor_serialize_negint
2210ff414cSEd Maste.. doxygenfunction:: cbor_serialize_bytestring
2310ff414cSEd Maste.. doxygenfunction:: cbor_serialize_string
2410ff414cSEd Maste.. doxygenfunction:: cbor_serialize_array
2510ff414cSEd Maste.. doxygenfunction:: cbor_serialize_map
2610ff414cSEd Maste.. doxygenfunction:: cbor_serialize_tag
2710ff414cSEd Maste.. doxygenfunction:: cbor_serialize_float_ctrl
28