libcbor  0.5.0
libcbor is a C library for parsing and generating CBOR, the general-purpose schema-less binary data format.
Functions
encoding.h File Reference
#include "cbor/common.h"

Go to the source code of this file.

Functions

size_t cbor_encode_uint8 (uint8_t, unsigned char *, size_t)
 
size_t cbor_encode_uint16 (uint16_t, unsigned char *, size_t)
 
size_t cbor_encode_uint32 (uint32_t, unsigned char *, size_t)
 
size_t cbor_encode_uint64 (uint64_t, unsigned char *, size_t)
 
size_t cbor_encode_uint (uint64_t, unsigned char *, size_t)
 
size_t cbor_encode_negint8 (uint8_t, unsigned char *, size_t)
 
size_t cbor_encode_negint16 (uint16_t, unsigned char *, size_t)
 
size_t cbor_encode_negint32 (uint32_t, unsigned char *, size_t)
 
size_t cbor_encode_negint64 (uint64_t, unsigned char *, size_t)
 
size_t cbor_encode_negint (uint64_t, unsigned char *, size_t)
 
size_t cbor_encode_bytestring_start (size_t, unsigned char *, size_t)
 
size_t cbor_encode_indef_bytestring_start (unsigned char *, size_t)
 
size_t cbor_encode_string_start (size_t, unsigned char *, size_t)
 
size_t cbor_encode_indef_string_start (unsigned char *, size_t)
 
size_t cbor_encode_array_start (size_t, unsigned char *, size_t)
 
size_t cbor_encode_indef_array_start (unsigned char *, size_t)
 
size_t cbor_encode_map_start (size_t, unsigned char *, size_t)
 
size_t cbor_encode_indef_map_start (unsigned char *, size_t)
 
size_t cbor_encode_tag (uint64_t, unsigned char *, size_t)
 
size_t cbor_encode_bool (bool, unsigned char *, size_t)
 
size_t cbor_encode_null (unsigned char *, size_t)
 
size_t cbor_encode_undef (unsigned char *, size_t)
 
size_t cbor_encode_half (float, unsigned char *, size_t)
 Encodes a half-precision float. More...
 
size_t cbor_encode_single (float, unsigned char *, size_t)
 
size_t cbor_encode_double (double, unsigned char *, size_t)
 
size_t cbor_encode_break (unsigned char *, size_t)
 
size_t cbor_encode_ctrl (uint8_t, unsigned char *, size_t)
 

Function Documentation

§ cbor_encode_array_start()

size_t cbor_encode_array_start ( size_t  ,
unsigned char *  ,
size_t   
)

Definition at line 91 of file encoding.c.

§ cbor_encode_bool()

size_t cbor_encode_bool ( bool  ,
unsigned char *  ,
size_t   
)

Definition at line 116 of file encoding.c.

§ cbor_encode_break()

size_t cbor_encode_break ( unsigned char *  ,
size_t   
)

Definition at line 178 of file encoding.c.

§ cbor_encode_bytestring_start()

size_t cbor_encode_bytestring_start ( size_t  ,
unsigned char *  ,
size_t   
)

Definition at line 62 of file encoding.c.

§ cbor_encode_ctrl()

size_t cbor_encode_ctrl ( uint8_t  ,
unsigned char *  ,
size_t   
)

Definition at line 183 of file encoding.c.

§ cbor_encode_double()

size_t cbor_encode_double ( double  ,
unsigned char *  ,
size_t   
)

Definition at line 173 of file encoding.c.

§ cbor_encode_half()

size_t cbor_encode_half ( float  ,
unsigned char *  ,
size_t   
)

Encodes a half-precision float.

Since there is no native representation or semantics for half floats in the language, we use single-precision floats, as every value that can be expressed as a half-float can also be expressed as a float.

This however means that not all floats passed to this function can be unambiguously encoded. The behavior is as follows:

  • Infinity, NaN are preserved
  • Zero is preserved
  • Denormalized numbers keep their sign bit and 10 most significant bit of the significand
  • All other numbers
    • If the logical value of the exponent is < -24, the output is zero
    • If the logical value of the exponent is between -23 and -14, the output is cut off to represent the 'magnitude' of the input, by which we mean (-1)^{signbit} x 1.0e{exponent}. The value in the significand is lost.
    • In all other cases, the sign bit, the exponent, and 10 most significant bits of the significand are kept
Parameters
value
bufferTarget buffer
buffer_sizeAvailable space in the buffer
Returns
number of bytes written

Definition at line 131 of file encoding.c.

§ cbor_encode_indef_array_start()

size_t cbor_encode_indef_array_start ( unsigned char *  ,
size_t   
)

Definition at line 96 of file encoding.c.

§ cbor_encode_indef_bytestring_start()

size_t cbor_encode_indef_bytestring_start ( unsigned char *  ,
size_t   
)

Definition at line 76 of file encoding.c.

§ cbor_encode_indef_map_start()

size_t cbor_encode_indef_map_start ( unsigned char *  ,
size_t   
)

Definition at line 106 of file encoding.c.

§ cbor_encode_indef_string_start()

size_t cbor_encode_indef_string_start ( unsigned char *  ,
size_t   
)

Definition at line 86 of file encoding.c.

§ cbor_encode_map_start()

size_t cbor_encode_map_start ( size_t  ,
unsigned char *  ,
size_t   
)

Definition at line 101 of file encoding.c.

§ cbor_encode_negint()

size_t cbor_encode_negint ( uint64_t  ,
unsigned char *  ,
size_t   
)

Definition at line 57 of file encoding.c.

§ cbor_encode_negint16()

size_t cbor_encode_negint16 ( uint16_t  ,
unsigned char *  ,
size_t   
)

Definition at line 42 of file encoding.c.

§ cbor_encode_negint32()

size_t cbor_encode_negint32 ( uint32_t  ,
unsigned char *  ,
size_t   
)

Definition at line 47 of file encoding.c.

§ cbor_encode_negint64()

size_t cbor_encode_negint64 ( uint64_t  ,
unsigned char *  ,
size_t   
)

Definition at line 52 of file encoding.c.

§ cbor_encode_negint8()

size_t cbor_encode_negint8 ( uint8_t  ,
unsigned char *  ,
size_t   
)

Definition at line 37 of file encoding.c.

§ cbor_encode_null()

size_t cbor_encode_null ( unsigned char *  ,
size_t   
)

Definition at line 121 of file encoding.c.

§ cbor_encode_single()

size_t cbor_encode_single ( float  ,
unsigned char *  ,
size_t   
)

Definition at line 167 of file encoding.c.

§ cbor_encode_string_start()

size_t cbor_encode_string_start ( size_t  ,
unsigned char *  ,
size_t   
)

Definition at line 81 of file encoding.c.

§ cbor_encode_tag()

size_t cbor_encode_tag ( uint64_t  ,
unsigned char *  ,
size_t   
)

Definition at line 111 of file encoding.c.

§ cbor_encode_uint()

size_t cbor_encode_uint ( uint64_t  ,
unsigned char *  ,
size_t   
)

Definition at line 31 of file encoding.c.

§ cbor_encode_uint16()

size_t cbor_encode_uint16 ( uint16_t  ,
unsigned char *  ,
size_t   
)

Definition at line 16 of file encoding.c.

§ cbor_encode_uint32()

size_t cbor_encode_uint32 ( uint32_t  ,
unsigned char *  ,
size_t   
)

Definition at line 21 of file encoding.c.

§ cbor_encode_uint64()

size_t cbor_encode_uint64 ( uint64_t  ,
unsigned char *  ,
size_t   
)

Definition at line 26 of file encoding.c.

§ cbor_encode_uint8()

size_t cbor_encode_uint8 ( uint8_t  ,
unsigned char *  ,
size_t   
)

Definition at line 11 of file encoding.c.

§ cbor_encode_undef()

size_t cbor_encode_undef ( unsigned char *  ,
size_t   
)

Definition at line 126 of file encoding.c.