libcoap  4.1.1
 All Data Structures Files Functions Variables Typedefs Macros Groups Pages
encode.h
Go to the documentation of this file.
1 /* encode.h -- encoding and decoding of CoAP data types
2  *
3  * Copyright (C) 2010--2012 Olaf Bergmann <bergmann@tzi.org>
4  *
5  * This file is part of the CoAP library libcoap. Please see
6  * README for terms of use.
7  */
8 
9 #ifndef _COAP_ENCODE_H_
10 #define _COAP_ENCODE_H_
11 
12 #if (BSD >= 199103) || defined(WITH_CONTIKI)
13 # include <string.h>
14 #else
15 # include <strings.h>
16 #endif
17 
18 #define Nn 8 /* duplicate definition of N if built on sky motes */
19 #define E 4
20 #define HIBIT (1 << (Nn - 1))
21 #define EMASK ((1 << E) - 1)
22 #define MMASK ((1 << Nn) - 1 - EMASK)
23 #define MAX_VALUE ( (1 << Nn) - (1 << E) ) * (1 << ((1 << E) - 1))
24 
25 #define COAP_PSEUDOFP_DECODE_8_4(r) (r < HIBIT ? r : (r & MMASK) << (r & EMASK))
26 
27 #ifndef HAVE_FLS
28 /* include this only if fls() is not available */
29 extern int coap_fls(unsigned int i);
30 #else
31 #define coap_fls(i) fls(i)
32 #endif
33 
34 /* ls and s must be integer variables */
35 #define COAP_PSEUDOFP_ENCODE_8_4_DOWN(v,ls) (v < HIBIT ? v : (ls = coap_fls(v) - Nn, (v >> ls) & MMASK) + ls)
36 #define COAP_PSEUDOFP_ENCODE_8_4_UP(v,ls,s) (v < HIBIT ? v : (ls = coap_fls(v) - Nn, (s = (((v + ((1<<E<<ls)-1)) >> ls) & MMASK)), s == 0 ? HIBIT + ls + 1 : s + ls))
37 
42 unsigned int coap_decode_var_bytes(unsigned char *buf,unsigned int len);
43 
50 unsigned int coap_encode_var_bytes(unsigned char *buf, unsigned int val);
51 
52 #endif /* _COAP_ENCODE_H_ */
int coap_fls(unsigned int i)
Definition: encode.c:17
unsigned int coap_encode_var_bytes(unsigned char *buf, unsigned int val)
Encodes multiple-length byte sequences.
Definition: encode.c:34
unsigned int coap_decode_var_bytes(unsigned char *buf, unsigned int len)
Decodes multiple-length byte sequences.
Definition: encode.c:25