libcoap  4.3.0beta
encode.h File Reference
#include <strings.h>
#include <stdint.h>
+ Include dependency graph for encode.h:
+ This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Macros

#define Nn   8 /* duplicate definition of N if built on sky motes */
 
#define ENCODE_HEADER_SIZE   4
 
#define HIBIT   (1 << (Nn - 1))
 
#define EMASK   ((1 << ENCODE_HEADER_SIZE) - 1)
 
#define MMASK   ((1 << Nn) - 1 - EMASK)
 
#define MAX_VALUE   ( (1 << Nn) - (1 << ENCODE_HEADER_SIZE) ) * (1 << ((1 << ENCODE_HEADER_SIZE) - 1))
 
#define COAP_PSEUDOFP_DECODE_8_4(r)   (r < HIBIT ? r : (r & MMASK) << (r & EMASK))
 
#define COAP_PSEUDOFP_ENCODE_8_4_DOWN(v, ls)   (v < HIBIT ? v : (ls = coap_fls(v) - Nn, (v >> ls) & MMASK) + ls)
 
#define COAP_PSEUDOFP_ENCODE_8_4_UP(v, ls, s)   (v < HIBIT ? v : (ls = coap_fls(v) - Nn, (s = (((v + ((1<<ENCODE_HEADER_SIZE<<ls)-1)) >> ls) & MMASK)), s == 0 ? HIBIT + ls + 1 : s + ls))
 

Functions

int coap_fls (unsigned int i)
 
int coap_flsll (long long i)
 
unsigned int coap_decode_var_bytes (const uint8_t *buf, unsigned int length)
 Decodes multiple-length byte sequences. More...
 
uint64_t coap_decode_var_bytes8 (const uint8_t *buf, unsigned int length)
 Decodes multiple-length byte sequences. More...
 
unsigned int coap_encode_var_safe (uint8_t *buf, size_t length, unsigned int value)
 Encodes multiple-length byte sequences. More...
 
unsigned int coap_encode_var_safe8 (uint8_t *buf, size_t length, uint64_t value)
 Encodes multiple-length byte sequences. More...
 
COAP_STATIC_INLINE COAP_DEPRECATED int coap_encode_var_bytes (uint8_t *buf, unsigned int value)
 

Macro Definition Documentation

◆ COAP_PSEUDOFP_DECODE_8_4

#define COAP_PSEUDOFP_DECODE_8_4 (   r)    (r < HIBIT ? r : (r & MMASK) << (r & EMASK))

Definition at line 28 of file encode.h.

◆ COAP_PSEUDOFP_ENCODE_8_4_DOWN

#define COAP_PSEUDOFP_ENCODE_8_4_DOWN (   v,
  ls 
)    (v < HIBIT ? v : (ls = coap_fls(v) - Nn, (v >> ls) & MMASK) + ls)

Definition at line 45 of file encode.h.

◆ COAP_PSEUDOFP_ENCODE_8_4_UP

#define COAP_PSEUDOFP_ENCODE_8_4_UP (   v,
  ls,
 
)    (v < HIBIT ? v : (ls = coap_fls(v) - Nn, (s = (((v + ((1<<ENCODE_HEADER_SIZE<<ls)-1)) >> ls) & MMASK)), s == 0 ? HIBIT + ls + 1 : s + ls))

Definition at line 46 of file encode.h.

◆ EMASK

#define EMASK   ((1 << ENCODE_HEADER_SIZE) - 1)

Definition at line 24 of file encode.h.

◆ ENCODE_HEADER_SIZE

#define ENCODE_HEADER_SIZE   4

Definition at line 22 of file encode.h.

◆ HIBIT

#define HIBIT   (1 << (Nn - 1))

Definition at line 23 of file encode.h.

◆ MAX_VALUE

#define MAX_VALUE   ( (1 << Nn) - (1 << ENCODE_HEADER_SIZE) ) * (1 << ((1 << ENCODE_HEADER_SIZE) - 1))

Definition at line 26 of file encode.h.

◆ MMASK

#define MMASK   ((1 << Nn) - 1 - EMASK)

Definition at line 25 of file encode.h.

◆ Nn

#define Nn   8 /* duplicate definition of N if built on sky motes */

Definition at line 21 of file encode.h.

Function Documentation

◆ coap_encode_var_bytes()

COAP_STATIC_INLINE COAP_DEPRECATED int coap_encode_var_bytes ( uint8_t buf,
unsigned int  value 
)
Deprecated:
Use coap_encode_var_safe() instead.

Provided for backward compatibility. As value has a maximum value of 0xffffffff, and buf is usually defined as an array, it is unsafe to continue to use this variant if buf[] is less than buf[4].

For example char buf[1],oops; .. coap_encode_var_bytes(buf, 0xfff); would cause oops to get overwritten. This error can only be found by code inspection. coap_encode_var_safe(buf, sizeof(buf), 0xfff); would catch this error at run-time and should be used instead.

Definition at line 126 of file encode.h.

+ Here is the call graph for this function:

◆ coap_fls()

int coap_fls ( unsigned int  i)

Definition at line 13 of file encode.c.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ coap_flsll()

int coap_flsll ( long long  i)

Definition at line 19 of file encode.c.

+ Here is the caller graph for this function: