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