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
maps.h File Reference
#include "cbor/cbor_export.h"
#include "cbor/common.h"

Go to the source code of this file.

Functions

size_t cbor_map_size (const cbor_item_t *item)
 Get the number of pairs.
 
size_t cbor_map_allocated (const cbor_item_t *item)
 Get the size of the allocated storage.
 
cbor_item_tcbor_new_definite_map (size_t size)
 Create a new definite map.
 
cbor_item_tcbor_new_indefinite_map (void)
 Create a new indefinite map.
 
bool cbor_map_add (cbor_item_t *item, struct cbor_pair pair)
 Add a pair to the map.
 
bool _cbor_map_add_key (cbor_item_t *item, cbor_item_t *key)
 Add a key to the map.
 
bool _cbor_map_add_value (cbor_item_t *item, cbor_item_t *value)
 Add a value to the map.
 
bool cbor_map_is_definite (const cbor_item_t *item)
 Is this map definite?
 
bool cbor_map_is_indefinite (const cbor_item_t *item)
 Is this map indefinite?
 
struct cbor_paircbor_map_handle (const cbor_item_t *item)
 Get the pairs storage.
 

Function Documentation

◆ _cbor_map_add_key()

bool _cbor_map_add_key ( cbor_item_t * item,
cbor_item_t * key )

Add a key to the map.

Sets the value to NULL. Internal API.

Parameters
itemA map
keyThe key, Its reference count will be be increased by one.
Returns
true on success, false if either reallocation failed or the preallocated storage is full

Definition at line 52 of file maps.c.

◆ _cbor_map_add_value()

bool _cbor_map_add_value ( cbor_item_t * item,
cbor_item_t * value )

Add a value to the map.

Assumes that _cbor_map_add_key has been called. Internal API.

Parameters
itemA map
valueThe value. Its reference count will be be increased by one.
Returns
true on success, false if either reallocation failed or the preallocated storage is full

Definition at line 95 of file maps.c.

◆ cbor_map_add()

bool cbor_map_add ( cbor_item_t * item,
struct cbor_pair pair )

Add a pair to the map.

For definite maps, items can only be added to the preallocated space. For indefinite maps, the storage will be expanded as needed

Parameters
itemA map
pairThe key-value pair to add. Reference count of the cbor_pair.key and cbor_pair.value will be increased by one.
Returns
true on success, false if memory allocation failed (indefinite maps) or the preallocated storage is full (definite maps)

Definition at line 107 of file maps.c.

◆ cbor_map_allocated()

size_t cbor_map_allocated ( const cbor_item_t * item)

Get the size of the allocated storage.

Parameters
itemA map
Returns
Allocated storage size (as the number of cbor_pair items)

Definition at line 16 of file maps.c.

◆ cbor_map_handle()

struct cbor_pair * cbor_map_handle ( const cbor_item_t * item)

Get the pairs storage.

Parameters
itemA map
Returns
Array of cbor_map_size pairs. Manipulation is possible as long as references remain valid.

Definition at line 122 of file maps.c.

◆ cbor_map_is_definite()

bool cbor_map_is_definite ( const cbor_item_t * item)

Is this map definite?

Parameters
itemA map
Returns
Is this map definite?

Definition at line 113 of file maps.c.

◆ cbor_map_is_indefinite()

bool cbor_map_is_indefinite ( const cbor_item_t * item)

Is this map indefinite?

Parameters
itemA map
Returns
Is this map indefinite?

Definition at line 118 of file maps.c.

◆ cbor_map_size()

size_t cbor_map_size ( const cbor_item_t * item)

Get the number of pairs.

Parameters
itemA map
Returns
The number of pairs

Definition at line 11 of file maps.c.

◆ cbor_new_definite_map()

cbor_item_t * cbor_new_definite_map ( size_t size)

Create a new definite map.

Parameters
sizeThe number of slots to preallocate
Returns
Reference to the new map item. The item's reference count is initialized to one.
NULL if memory allocation fails

Definition at line 21 of file maps.c.

◆ cbor_new_indefinite_map()

cbor_item_t * cbor_new_indefinite_map ( void )

Create a new indefinite map.

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

Definition at line 37 of file maps.c.