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
floats_ctrls.c File Reference
#include "floats_ctrls.h"
#include <math.h>
#include "assert.h"

Go to the source code of this file.

Functions

cbor_float_width cbor_float_get_width (const cbor_item_t *item)
 Get the float width.
 
uint8_t cbor_ctrl_value (const cbor_item_t *item)
 Reads the control value.
 
bool cbor_float_ctrl_is_ctrl (const cbor_item_t *item)
 Is this a ctrl value?
 
float cbor_float_get_float2 (const cbor_item_t *item)
 Get a half precision float.
 
float cbor_float_get_float4 (const cbor_item_t *item)
 Get a single precision float.
 
double cbor_float_get_float8 (const cbor_item_t *item)
 Get a double precision float.
 
double cbor_float_get_float (const cbor_item_t *item)
 Get the float value represented as double.
 
bool cbor_get_bool (const cbor_item_t *item)
 Get value from a boolean ctrl item.
 
void cbor_set_float2 (cbor_item_t *item, float value)
 Assigns a float value.
 
void cbor_set_float4 (cbor_item_t *item, float value)
 Assigns a float value.
 
void cbor_set_float8 (cbor_item_t *item, double value)
 Assigns a float value.
 
void cbor_set_ctrl (cbor_item_t *item, uint8_t value)
 Assign a control value.
 
void cbor_set_bool (cbor_item_t *item, bool value)
 Assign a boolean value to a boolean ctrl item.
 
cbor_item_tcbor_new_ctrl (void)
 Constructs a new ctrl item.
 
cbor_item_tcbor_new_float2 (void)
 Constructs a new float item.
 
cbor_item_tcbor_new_float4 (void)
 Constructs a new float item.
 
cbor_item_tcbor_new_float8 (void)
 Constructs a new float item.
 
cbor_item_tcbor_new_null (void)
 Constructs new null ctrl item.
 
cbor_item_tcbor_new_undef (void)
 Constructs new undef ctrl item.
 
cbor_item_tcbor_build_bool (bool value)
 Constructs new boolean ctrl item.
 
cbor_item_tcbor_build_float2 (float value)
 Constructs a new float.
 
cbor_item_tcbor_build_float4 (float value)
 Constructs a new float.
 
cbor_item_tcbor_build_float8 (double value)
 Constructs a new float.
 
cbor_item_tcbor_build_ctrl (uint8_t value)
 Constructs a ctrl item.
 

Function Documentation

◆ cbor_build_bool()

cbor_item_t * cbor_build_bool ( bool value)

Constructs new boolean ctrl item.

Parameters
valueThe value to use
Returns
Reference to the new boolean item. The item's reference count is initialized to one.
NULL if memory allocation fails

Definition at line 161 of file floats_ctrls.c.

◆ cbor_build_ctrl()

cbor_item_t * cbor_build_ctrl ( uint8_t value)

Constructs a ctrl item.

Parameters
valuethe value to use
Returns
Reference to the new ctrl item. The item's reference count is initialized to one.
NULL if memory allocation fails

Definition at line 186 of file floats_ctrls.c.

◆ cbor_build_float2()

cbor_item_t * cbor_build_float2 ( float value)

Constructs a new float.

Parameters
valuethe value to use
Returns
Reference to the new float item. The item's reference count is initialized to one.
NULL if memory allocation fails

Definition at line 165 of file floats_ctrls.c.

◆ cbor_build_float4()

cbor_item_t * cbor_build_float4 ( float value)

Constructs a new float.

Parameters
valuethe value to use
Returns
Reference to the new float item. The item's reference count is initialized to one.
NULL if memory allocation fails

Definition at line 172 of file floats_ctrls.c.

◆ cbor_build_float8()

cbor_item_t * cbor_build_float8 ( double value)

Constructs a new float.

Parameters
valuethe value to use
Returns
Reference to the new float item. The item's reference count is initialized to one.
NULL if memory allocation fails

Definition at line 179 of file floats_ctrls.c.

◆ cbor_ctrl_value()

uint8_t cbor_ctrl_value ( const cbor_item_t * item)

Reads the control value.

Parameters
itemA ctrl item
Returns
the simple value

Definition at line 17 of file floats_ctrls.c.

◆ cbor_float_ctrl_is_ctrl()

bool cbor_float_ctrl_is_ctrl ( const cbor_item_t * item)

Is this a ctrl value?

Parameters
itemA float or ctrl item
Returns
Is this a ctrl value?

Definition at line 23 of file floats_ctrls.c.

◆ cbor_float_get_float()

double cbor_float_get_float ( const cbor_item_t * item)

Get the float value represented as double.

Can be used regardless of the width.

Parameters
itemAny float
Returns
double precision value

Definition at line 46 of file floats_ctrls.c.

◆ cbor_float_get_float2()

float cbor_float_get_float2 ( const cbor_item_t * item)

Get a half precision float.

The item must have the corresponding width

Parameters
itemA half precision float
Returns
half precision value

Definition at line 28 of file floats_ctrls.c.

◆ cbor_float_get_float4()

float cbor_float_get_float4 ( const cbor_item_t * item)

Get a single precision float.

The item must have the corresponding width

Parameters
itemA single precision float
Returns
single precision value

Definition at line 34 of file floats_ctrls.c.

◆ cbor_float_get_float8()

double cbor_float_get_float8 ( const cbor_item_t * item)

Get a double precision float.

The item must have the corresponding width

Parameters
itemA double precision float
Returns
double precision value

Definition at line 40 of file floats_ctrls.c.

◆ cbor_float_get_width()

cbor_float_width cbor_float_get_width ( const cbor_item_t * item)

Get the float width.

Parameters
itemA float or ctrl item
Returns
The width.

Definition at line 12 of file floats_ctrls.c.

◆ cbor_get_bool()

bool cbor_get_bool ( const cbor_item_t * item)

Get value from a boolean ctrl item.

Parameters
itemA ctrl item
Returns
boolean value

Definition at line 63 of file floats_ctrls.c.

◆ cbor_new_ctrl()

cbor_item_t * cbor_new_ctrl ( void )

Constructs a new ctrl item.

The width cannot be changed once the item is created

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

Definition at line 98 of file floats_ctrls.c.

◆ cbor_new_float2()

cbor_item_t * cbor_new_float2 ( void )

Constructs a new float item.

The width cannot be changed once the item is created

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

Definition at line 111 of file floats_ctrls.c.

◆ cbor_new_float4()

cbor_item_t * cbor_new_float4 ( void )

Constructs a new float item.

The width cannot be changed once the item is created

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

Definition at line 123 of file floats_ctrls.c.

◆ cbor_new_float8()

cbor_item_t * cbor_new_float8 ( void )

Constructs a new float item.

The width cannot be changed once the item is created

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

Definition at line 135 of file floats_ctrls.c.

◆ cbor_new_null()

cbor_item_t * cbor_new_null ( void )

Constructs new null ctrl item.

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

Definition at line 147 of file floats_ctrls.c.

◆ cbor_new_undef()

cbor_item_t * cbor_new_undef ( void )

Constructs new undef ctrl item.

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

Definition at line 154 of file floats_ctrls.c.

◆ cbor_set_bool()

void cbor_set_bool ( cbor_item_t * item,
bool value )

Assign a boolean value to a boolean ctrl item.

Parameters
itemA ctrl item
valueThe simple value to assign.

Definition at line 92 of file floats_ctrls.c.

◆ cbor_set_ctrl()

void cbor_set_ctrl ( cbor_item_t * item,
uint8_t value )

Assign a control value.

embed:rst:leading-asterisk 
* .. warning:: It is possible to produce an invalid CBOR value by assigning a
*  invalid value using this mechanism. Please consult the standard before use.
* 
Parameters
itemA ctrl item
valueThe simple value to assign. Please consult the standard for allowed values

Definition at line 86 of file floats_ctrls.c.

◆ cbor_set_float2()

void cbor_set_float2 ( cbor_item_t * item,
float value )

Assigns a float value.

Parameters
itemA half precision float
valueThe value to assign

Definition at line 68 of file floats_ctrls.c.

◆ cbor_set_float4()

void cbor_set_float4 ( cbor_item_t * item,
float value )

Assigns a float value.

Parameters
itemA single precision float
valueThe value to assign

Definition at line 74 of file floats_ctrls.c.

◆ cbor_set_float8()

void cbor_set_float8 ( cbor_item_t * item,
double value )

Assigns a float value.

Parameters
itemA double precision float
valueThe value to assign

Definition at line 80 of file floats_ctrls.c.