Home | History | Annotate | Line # | Download | only in dist
      1 # [libcbor](https://github.com/PJK/libcbor)
      2 
      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 
      7 **libcbor** is a C library for parsing and generating [CBOR](http://tools.ietf.org/html/rfc7049), the general-purpose schema-less binary data format.
      8 
      9 ## Main features
     10  - Complete RFC conformance
     11  - Robust C99 implementation
     12  - Layered architecture offers both control and convenience
     13  - Flexible memory management
     14  - No shared global state - threading friendly
     15  - Proper handling of UTF-8
     16  - Full support for streams & incremental processing
     17  - Extensive documentation and test suite
     18  - No runtime dependencies, small footprint
     19  
     20 ## Getting started
     21 
     22 ### Compile from source
     23 
     24 ```bash
     25 git clone https://github.com/PJK/libcbor
     26 cmake -DCMAKE_BUILD_TYPE=Release -DCBOR_CUSTOM_ALLOC=ON libcbor
     27 make
     28 make install
     29 ```
     30 
     31 ### Homebrew
     32 
     33 ```bash
     34 brew tap pjk/libcbor
     35 brew install libcbor
     36 ```
     37 
     38 ### Ubuntu 18.04 and above
     39 
     40 ```bash
     41 sudo add-apt-repository universe
     42 sudo apt-get install libcbor-dev
     43 ```
     44 
     45 ### Fedora & RPM friends
     46 
     47 ```bash
     48 yum install libcbor-devel
     49 ```
     50 
     51 ## Usage example
     52 
     53 ```c
     54 #include <cbor.h>
     55 #include <stdio.h>
     56 
     57 int main(int argc, char * argv[])
     58 {
     59 	/* Preallocate the map structure */
     60 	cbor_item_t * root = cbor_new_definite_map(2);
     61 	/* Add the content */
     62 	cbor_map_add(root, (struct cbor_pair) {
     63 		.key = cbor_move(cbor_build_string("Is CBOR awesome?")),
     64 		.value = cbor_move(cbor_build_bool(true))
     65 	});
     66 	cbor_map_add(root, (struct cbor_pair) {
     67 		.key = cbor_move(cbor_build_uint8(42)),
     68 		.value = cbor_move(cbor_build_string("Is the answer"))
     69 	});
     70 	/* Output: `length` bytes of data in the `buffer` */
     71 	unsigned char * buffer;
     72 	size_t buffer_size,
     73 		length = cbor_serialize_alloc(root, &buffer, &buffer_size);
     74 
     75 	fwrite(buffer, 1, length, stdout);
     76 	free(buffer);
     77 
     78 	fflush(stdout);
     79 	cbor_decref(&root);
     80 }
     81 ```
     82 
     83 ## Documentation
     84 Get the latest documentation at [libcbor.readthedocs.org](http://libcbor.readthedocs.org/)
     85 
     86 ## Contributions
     87 
     88 All bug reports and contributions are welcome. Please see https://github.com/PJK/libcbor for more info.
     89 
     90 Kudos to all the [contributors](https://github.com/PJK/libcbor/graphs/contributors)!
     91 
     92 ## License
     93 The MIT License (MIT)
     94 
     95 Copyright (c) Pavel Kalvoda, 2014-2019
     96 
     97 Permission is hereby granted, free of charge, to any person obtaining a copy
     98 of this software and associated documentation files (the "Software"), to deal
     99 in the Software without restriction, including without limitation the rights
    100 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
    101 copies of the Software, and to permit persons to whom the Software is
    102 furnished to do so, subject to the following conditions:
    103 
    104 The above copyright notice and this permission notice shall be included in all
    105 copies or substantial portions of the Software.
    106 
    107 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
    108 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
    109 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
    110 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
    111 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
    112 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
    113 SOFTWARE.
    114