1 # [libcbor](https://github.com/PJK/libcbor)
3 [![Build Status](https://travis-ci.org/PJK/libcbor.svg?branch=master)](https://travis-ci.org/PJK/libcbor)
4 [![Build status](https://ci.appveyor.com/api/projects/status/8kkmvmefelsxp5u2?svg=true)](https://ci.appveyor.com/project/PJK/libcbor)
5 [![Documentation Status](https://readthedocs.org/projects/libcbor/badge/?version=latest)](https://readthedocs.org/projects/libcbor/?badge=latest)
6 [![latest packaged version(s)](https://repology.org/badge/latest-versions/libcbor.svg)](https://repology.org/project/libcbor/versions)
7 [![codecov](https://codecov.io/gh/PJK/libcbor/branch/master/graph/badge.svg)](https://codecov.io/gh/PJK/libcbor)
9 **libcbor** is a C library for parsing and generating [CBOR](http://tools.ietf.org/html/rfc7049), the general-purpose schema-less binary data format.
12 - Complete RFC conformance
13 - Robust C99 implementation
14 - Layered architecture offers both control and convenience
15 - Flexible memory management
16 - No shared global state - threading friendly
17 - Proper handling of UTF-8
18 - Full support for streams & incremental processing
19 - Extensive documentation and test suite
20 - No runtime dependencies, small footprint
24 ### Compile from source
27 git clone https://github.com/PJK/libcbor
28 cmake -DCMAKE_BUILD_TYPE=Release -DCBOR_CUSTOM_ALLOC=ON libcbor
39 ### Ubuntu 18.04 and above
42 sudo add-apt-repository universe
43 sudo apt-get install libcbor-dev
46 ### Fedora & RPM friends
49 yum install libcbor-devel
55 <summary>Packaged libcbor is available from 15+ major repositories. Click here for more detail</summary>
57 [![Packaging status](https://repology.org/badge/vertical-allrepos/libcbor.svg)](https://repology.org/project/libcbor/versions)
66 int main(int argc, char * argv[])
68 /* Preallocate the map structure */
69 cbor_item_t * root = cbor_new_definite_map(2);
71 cbor_map_add(root, (struct cbor_pair) {
72 .key = cbor_move(cbor_build_string("Is CBOR awesome?")),
73 .value = cbor_move(cbor_build_bool(true))
75 cbor_map_add(root, (struct cbor_pair) {
76 .key = cbor_move(cbor_build_uint8(42)),
77 .value = cbor_move(cbor_build_string("Is the answer"))
79 /* Output: `length` bytes of data in the `buffer` */
80 unsigned char * buffer;
82 length = cbor_serialize_alloc(root, &buffer, &buffer_size);
84 fwrite(buffer, 1, length, stdout);
93 Get the latest documentation at [libcbor.readthedocs.org](http://libcbor.readthedocs.org/)
97 All bug reports and contributions are welcome. Please see https://github.com/PJK/libcbor for more info.
99 Kudos to all the [contributors](https://github.com/PJK/libcbor/graphs/contributors)!
102 The MIT License (MIT)
104 Copyright (c) Pavel Kalvoda, 2014-2020
106 Permission is hereby granted, free of charge, to any person obtaining a copy
107 of this software and associated documentation files (the "Software"), to deal
108 in the Software without restriction, including without limitation the rights
109 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
110 copies of the Software, and to permit persons to whom the Software is
111 furnished to do so, subject to the following conditions:
113 The above copyright notice and this permission notice shall be included in all
114 copies or substantial portions of the Software.
116 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
117 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
118 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
119 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
120 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
121 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE