1
0
mirror of https://github.com/RIOT-OS/RIOT.git synced 2024-12-29 04:50:03 +01:00

nanocoap: add coap_size2szx()

This commit is contained in:
Benjamin Valentin 2022-05-29 15:38:29 +02:00
parent 97a203a7ec
commit 3adda46cec

View File

@ -86,6 +86,7 @@
#include <unistd.h>
#ifdef RIOT_VERSION
#include "bitarithm.h"
#include "bitfield.h"
#include "byteorder.h"
#include "iolist.h"
@ -988,6 +989,19 @@ static inline unsigned coap_szx2size(unsigned szx)
{
return (1 << (szx + 4));
}
/**
* @brief Helper to encode byte size into next equal or smaller SZX value
*
* @param[in] len Size in bytes
*
* @returns closest SZX value that fits into a buffer of @p len
*/
static inline unsigned coap_size2szx(unsigned len)
{
assert(len >= 16);
return bitarithm_msb(len >> 4);
}
/**@}*/
/**