libcbor 0.12.0
libcbor is a C library for parsing and generating CBOR, the general-purpose schema-less binary data format.
Loading...
Searching...
No Matches
bytestrings.h File Reference
#include "cbor/cbor_export.h"
#include "cbor/common.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.
 
bool cbor_bytestring_is_definite (const cbor_item_t *item)
 Is the byte string definite?
 
bool cbor_bytestring_is_indefinite (const cbor_item_t *item)
 Is the byte string indefinite?
 
cbor_mutable_data cbor_bytestring_handle (const cbor_item_t *item)
 Get the handle to the binary data.
 
void cbor_bytestring_set_handle (cbor_item_t *item, cbor_mutable_data data, size_t length)
 Set the handle to the binary data.
 
cbor_item_t ** cbor_bytestring_chunks_handle (const cbor_item_t *item)
 Get the handle to the array of chunks.
 
size_t cbor_bytestring_chunk_count (const cbor_item_t *item)
 Get the number of chunks this string consist of.
 
bool cbor_bytestring_add_chunk (cbor_item_t *item, cbor_item_t *chunk)
 Appends a chunk to the bytestring.
 
cbor_item_tcbor_new_definite_bytestring (void)
 Creates a new definite byte string.
 
cbor_item_tcbor_new_indefinite_bytestring (void)
 Creates a new indefinite byte string.
 
cbor_item_tcbor_build_bytestring (cbor_data handle, size_t length)
 Creates a new byte string and initializes it.
 

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
Reference to the new bytestring item. The item's reference count is initialized to one.
NULL if memory allocation fails

Definition at line 61 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
itemAn indefinite byte string
chunkA definite byte string. Its reference count will be be increased by one.
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 92 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
itemA indefinite bytestring
Returns
The chunk count. 0 for freshly created items.

Definition at line 86 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
itemA indefinite byte string
Returns
array of cbor_bytestring_chunk_count definite bytestrings

Definition at line 80 of file bytestrings.c.

◆ cbor_bytestring_handle()

cbor_mutable_data 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
itemA definite byte string
Returns
The address of the underlying binary data
NULL if no data have been assigned yet.

Definition at line 17 of file bytestrings.c.

◆ cbor_bytestring_is_definite()

bool cbor_bytestring_is_definite ( const cbor_item_t * item)

Is the byte string definite?

Parameters
itema byte string
Returns
Is the byte string definite?

Definition at line 22 of file bytestrings.c.

◆ cbor_bytestring_is_indefinite()

bool cbor_bytestring_is_indefinite ( const cbor_item_t * item)

Is the byte string indefinite?

Parameters
itema byte string
Returns
Is the byte string indefinite?

Definition at line 27 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
itema 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 data,
size_t length )

Set the handle to the binary data.

Parameters
itemA definite byte string
dataThe memory block. The caller gives up the ownership of the block. libcbor will deallocate it when appropriate using the free implementation configured using cbor_set_allocs
lengthLength of the data block

Definition at line 71 of file bytestrings.c.

◆ cbor_new_definite_bytestring()

cbor_item_t * cbor_new_definite_bytestring ( void )

Creates a new definite byte string.

The handle is initialized to NULL and length to 0

Returns
Reference to the new bytestring item. The item's reference count is initialized to one.
NULL if memory allocation fails

Definition at line 31 of file bytestrings.c.

◆ cbor_new_indefinite_bytestring()

cbor_item_t * cbor_new_indefinite_bytestring ( void )

Creates a new indefinite byte string.

The chunks array is initialized to NULL and chunk count to 0

Returns
Reference to the new bytestring item. The item's reference count is initialized to one.
NULL if memory allocation fails

Definition at line 42 of file bytestrings.c.