Skip to content
Permalink
Browse files

Fix Readme example

  • Loading branch information...
PJK committed Feb 23, 2019
1 parent 57efe85 commit 87f977e732ca216682a8583a0e43803eb6b9c028
Showing with 29 additions and 1 deletion.
  1. +29 −1 README.md
@@ -50,7 +50,35 @@ yum install libcbor-devel

## Usage example

<script src="https://gist.github.com/PJK/962a468886d24195d1ee.js"></script>
```c
#include <cbor.h>
#include <stdio.h>
int main(int argc, char * argv[])
{
/* Preallocate the map structure */
cbor_item_t * root = cbor_new_definite_map(2);
/* Add the content */
cbor_map_add(root, (struct cbor_pair) {
.key = cbor_move(cbor_build_string("Is CBOR awesome?")),
.value = cbor_move(cbor_build_bool(true))
});
cbor_map_add(root, (struct cbor_pair) {
.key = cbor_move(cbor_build_uint8(42)),
.value = cbor_move(cbor_build_string("Is the answer"))
});
/* Output: `length` bytes of data in the `buffer` */
unsigned char * buffer;
size_t buffer_size,
length = cbor_serialize_alloc(root, &buffer, &buffer_size);
fwrite(buffer, 1, length, stdout);
free(buffer);
fflush(stdout);
cbor_decref(&root);
}
```
## Documentation
Get the latest documentation at [libcbor.readthedocs.org](http://libcbor.readthedocs.org/)

0 comments on commit 87f977e

Please sign in to comment.
You can’t perform that action at this time.
You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session.