Files
libcoap/include/coap/encode.h
T
Carsten Schoenert 0e59edc231 i/c/*.h: more public header cleanup
Resume the cleaning of the public header files, no functional changes.

Reformatting the infos in the head of the header files, restructure header
inclusion check to be more generic. Reorder some include directives in a
alphabetical order. Remove including instructions for C++ stuff, it's
already done in the coap.h header, and the user only has to include this
header file.

Dropping the prefixing of the include guarding of uthash.h because it would
cause trouble with the macro handling in TinyDLS.
Thanks Olaf for reminding this!
2016-01-10 17:49:07 +01:00

53 lines
1.7 KiB
C

/*
* encode.h -- encoding and decoding of CoAP data types
*
* Copyright (C) 2010-2012 Olaf Bergmann <bergmann@tzi.org>
*
* This file is part of the CoAP library libcoap. Please see README for terms
* of use.
*/
#ifndef _COAP_ENCODE_H_
#define _COAP_ENCODE_H_
#if (BSD >= 199103) || defined(WITH_CONTIKI)
# include <string.h>
#else
# include <strings.h>
#endif
#define Nn 8 /* duplicate definition of N if built on sky motes */
#define E 4
#define HIBIT (1 << (Nn - 1))
#define EMASK ((1 << E) - 1)
#define MMASK ((1 << Nn) - 1 - EMASK)
#define MAX_VALUE ( (1 << Nn) - (1 << E) ) * (1 << ((1 << E) - 1))
#define COAP_PSEUDOFP_DECODE_8_4(r) (r < HIBIT ? r : (r & MMASK) << (r & EMASK))
#ifndef HAVE_FLS
/* include this only if fls() is not available */
extern int coap_fls(unsigned int i);
#else
#define coap_fls(i) fls(i)
#endif
/* ls and s must be integer variables */
#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<<E<<ls)-1)) >> ls) & MMASK)), s == 0 ? HIBIT + ls + 1 : s + ls))
/**
* Decodes multiple-length byte sequences. buf points to an input byte sequence
* of length len. Returns the decoded value.
*/
unsigned int coap_decode_var_bytes(unsigned char *buf,unsigned int len);
/**
* Encodes multiple-length byte sequences. buf points to an output buffer of
* sufficient length to store the encoded bytes. val is the value to encode.
* Returns the number of bytes used to encode val or 0 on error.
*/
unsigned int coap_encode_var_bytes(unsigned char *buf, unsigned int val);
#endif /* _COAP_ENCODE_H_ */