Created
May 19, 2015 14:08
-
-
Save PJK/962a468886d24195d1ee to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment