libcbor  0.5.0
libcbor is a C library for parsing and generating CBOR, the general-purpose schema-less binary data format.
Functions
bytestrings.c File Reference
#include <string.h>
#include "bytestrings.h"
#include "internal/memory_utils.h"

Go to the source code of this file.

Functions

size_t cbor_bytestring_length (const cbor_item_t *item)
 Returns the length of the binary data. More...
 
unsigned char * cbor_bytestring_handle (const cbor_item_t *item)
 Get the handle to the binary data. More...
 
bool cbor_bytestring_is_definite (const cbor_item_t *item)
 Is the byte string definite? More...
 
bool cbor_bytestring_is_indefinite (const cbor_item_t *item)
 Is the byte string indefinite? More...
 
cbor_item_tcbor_new_definite_bytestring ()
 Creates a new definite byte string. More...
 
cbor_item_tcbor_new_indefinite_bytestring ()
 Creates a new indefinite byte string. More...
 
cbor_item_tcbor_build_bytestring (cbor_data handle, size_t length)
 Creates a new byte string and initializes it. More...
 
void cbor_bytestring_set_handle (cbor_item_t *item, cbor_mutable_data CBOR_RESTRICT_POINTER data, size_t length)
 Set the handle to the binary data. More...
 
cbor_item_t ** cbor_bytestring_chunks_handle (const cbor_item_t *item)
 Get the handle to the array of chunks. More...
 
size_t cbor_bytestring_chunk_count (const cbor_item_t *item)
 Get the number of chunks this string consist of. More...
 
bool cbor_bytestring_add_chunk (cbor_item_t *item, cbor_item_t *chunk)
 Appends a chunk to the bytestring. More...
 

Function Documentation

§ cbor_build_bytestring()

cbor_item_t* cbor_build_bytestring ( cbor_data  handle,
size_t  length 
)

Creates a new byte string and initializes it.

The handle will be copied to a newly allocated block

Parameters
handleBlock of binary data
lengthLength of data
Returns
A new byte string with content handle. NULL on malloc failure.

Definition at line 63 of file bytestrings.c.

§ cbor_bytestring_add_chunk()

bool cbor_bytestring_add_chunk ( cbor_item_t item,
cbor_item_t chunk 
)

Appends a chunk to the bytestring.

Indefinite byte strings only.

May realloc the chunk storage.

Parameters
item[borrow]An indefinite byte string
item[incref]A definite byte string
Returns
true on success, false on realloc failure. In that case, the refcount of chunk is not increased and the item is left intact.

Definition at line 95 of file bytestrings.c.

§ cbor_bytestring_chunk_count()

size_t cbor_bytestring_chunk_count ( const cbor_item_t item)

Get the number of chunks this string consist of.

Parameters
item[borrow]A indefinite bytestring
Returns
The chunk count. 0 for freshly created items.

Definition at line 87 of file bytestrings.c.

§ cbor_bytestring_chunks_handle()

cbor_item_t** cbor_bytestring_chunks_handle ( const cbor_item_t item)

Get the handle to the array of chunks.

Manipulations with the memory block (e.g. sorting it) are allowed, but the validity and the number of chunks must be retained.

Parameters
item[borrow]A indefinite byte string
Returns
array of cbor_bytestring_chunk_count definite bytestrings

Definition at line 80 of file bytestrings.c.

§ cbor_bytestring_handle()

unsigned char* cbor_bytestring_handle ( const cbor_item_t item)

Get the handle to the binary data.

Definite items only. Modifying the data is allowed. In that case, the caller takes responsibility for the effect on items this item might be a part of

Parameters
item[borrow]A definite byte string
Returns
The address of the binary data. NULL if no data have been assigned yet.

Definition at line 18 of file bytestrings.c.

§ cbor_bytestring_is_definite()

bool cbor_bytestring_is_definite ( const cbor_item_t item)

Is the byte string definite?

Parameters
item[borrow]a byte string
Returns
Is the byte string definite?

Definition at line 24 of file bytestrings.c.

§ cbor_bytestring_is_indefinite()

bool cbor_bytestring_is_indefinite ( const cbor_item_t item)

Is the byte string indefinite?

Parameters
item[borrow]a byte string
Returns
Is the byte string indefinite?

Definition at line 30 of file bytestrings.c.

§ cbor_bytestring_length()

size_t cbor_bytestring_length ( const cbor_item_t item)

Returns the length of the binary data.

For definite byte strings only

Parameters
item[borrow]a definite bytestring
Returns
length of the binary data. Zero if no chunk has been attached yet

Definition at line 12 of file bytestrings.c.

§ cbor_bytestring_set_handle()

void cbor_bytestring_set_handle ( cbor_item_t item,
cbor_mutable_data CBOR_RESTRICT_POINTER  data,
size_t  length 
)

Set the handle to the binary data.

Parameters
item[borrow]A definite byte string
dataThe memory block. The caller gives up the ownership of the block. libcbor will deallocate it when appropriate using its free function
lengthLength of the data block

Definition at line 72 of file bytestrings.c.

§ cbor_new_definite_bytestring()

cbor_item_t* cbor_new_definite_bytestring ( )

Creates a new definite byte string.

The handle is initialized to NULL and length to 0

Returns
new definite bytestring. NULL on malloc failure.

Definition at line 35 of file bytestrings.c.

§ cbor_new_indefinite_bytestring()

cbor_item_t* cbor_new_indefinite_bytestring ( )

Creates a new indefinite byte string.

The chunks array is initialized to NULL and chunkcount to 0

Returns
new indefinite bytestring. NULL on malloc failure.

Definition at line 46 of file bytestrings.c.