Skip to content

Commit

Permalink
Update create_items example
Browse files Browse the repository at this point in the history
  • Loading branch information
PJK committed Dec 28, 2022
1 parent 1f6f0f8 commit e7c6d5d
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 26 deletions.
46 changes: 23 additions & 23 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,29 +63,29 @@ yum install libcbor-devel
#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: `buffer_size` bytes of data in the `buffer` */
unsigned char * buffer;
size_t buffer_size;
cbor_serialize_alloc(root, &buffer, &buffer_size);

fwrite(buffer, 1, buffer_size, stdout);
free(buffer);

fflush(stdout);
cbor_decref(&root);
int main(void) {
/* Preallocate the map structure */
cbor_item_t* root = cbor_new_definite_map(2);
/* Add the content */
bool success = cbor_map_add(
root, (struct cbor_pair){
.key = cbor_move(cbor_build_string("Is CBOR awesome?")),
.value = cbor_move(cbor_build_bool(true))});
success &= cbor_map_add(
root, (struct cbor_pair){
.key = cbor_move(cbor_build_uint8(42)),
.value = cbor_move(cbor_build_string("Is the answer"))});
if (!success) return 1;
/* Output: `length` bytes of data in the `buffer` */
unsigned char* buffer;
size_t buffer_size;
cbor_serialize_alloc(root, &buffer, &buffer_size);

fwrite(buffer, 1, buffer_size, stdout);
free(buffer);

fflush(stdout);
cbor_decref(&root);
}
```
Expand Down
6 changes: 3 additions & 3 deletions examples/create_items.c
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,10 @@ int main(void) {
if (!success) return 1;
/* Output: `length` bytes of data in the `buffer` */
unsigned char* buffer;
size_t buffer_size,
length = cbor_serialize_alloc(root, &buffer, &buffer_size);
size_t buffer_size;
cbor_serialize_alloc(root, &buffer, &buffer_size);

fwrite(buffer, 1, length, stdout);
fwrite(buffer, 1, buffer_size, stdout);
free(buffer);

fflush(stdout);
Expand Down

0 comments on commit e7c6d5d

Please sign in to comment.