Updated Makefiles and CMakeLists.txt to point to resource, not oic-resource
[platform/upstream/iotivity.git] / csdk / libcoap-4.1.1 / encode.h
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 #ifdef __cplusplus
13 extern "C" {
14 #endif
15
16 #if (BSD >= 199103) || defined(WITH_CONTIKI)
17 # include <string.h>
18 #else
19 #ifndef WITH_ARDUINO
20 # include <strings.h>
21 #endif
22 #endif
23
24 #define Nn 8  /* duplicate definition of N if built on sky motes */
25 #define E 4
26 #define HIBIT (1 << (Nn - 1))
27 #define EMASK ((1 << E) - 1)
28 #define MMASK ((1 << Nn) - 1 - EMASK)
29 #define MAX_VALUE ( (1 << Nn) - (1 << E) ) * (1 << ((1 << E) - 1))
30
31 #define COAP_PSEUDOFP_DECODE_8_4(r) (r < HIBIT ? r : (r & MMASK) << (r & EMASK))
32
33 #ifndef HAVE_FLS
34 /* include this only if fls() is not available */
35 extern int coap_fls(unsigned int i);
36 #else
37 #define coap_fls(i) fls(i)
38 #endif
39
40 /* ls and s must be integer variables */
41 #define COAP_PSEUDOFP_ENCODE_8_4_DOWN(v,ls) (v < HIBIT ? v : (ls = coap_fls(v) - Nn, (v >> ls) & MMASK) + ls)
42 #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))
43
44 /**
45  * Decodes multiple-length byte sequences. buf points to an input byte
46  * sequence of length len. Returns the decoded value.
47  */
48 unsigned int coap_decode_var_bytes(unsigned char *buf,unsigned int len);
49
50 /**
51  * Encodes multiple-length byte sequences. buf points to an output
52  * buffer of sufficient length to store the encoded bytes. val is
53  * the value to encode. Returns the number of bytes used to encode
54  * val or 0 on error.
55  */
56 unsigned int coap_encode_var_bytes(unsigned char *buf, unsigned int val);
57
58 #ifdef __cplusplus
59 }
60 #endif
61
62 #endif /* _COAP_ENCODE_H_ */