mirror of
https://github.com/obgm/libcoap.git
synced 2026-12-03 03:01:05 +03:00
moved some stuff from client implementation to libcoap
This commit is contained in:
1 parent
28a14dbb11
commit
96498de78e
3 files changed
+54
-2
No files matched your search
@@ -1,6 +1,6 @@
|
||||
/* encode.c -- encoding and decoding of CoAP data types
|
||||
*
|
||||
* (c) 2010 Carsten Bormann
|
||||
* (c) 2010 Olaf Bergmann <bergmann@tzi.org>, Carsten Bormann
|
||||
*/
|
||||
|
||||
#ifndef NDEBUG
|
||||
@@ -17,3 +17,26 @@ int coap_fls(unsigned int i) {
|
||||
return n;
|
||||
}
|
||||
|
||||
unsigned int
|
||||
coap_decode_var_bytes(unsigned char *buf,unsigned int len) {
|
||||
unsigned int i, n = 0;
|
||||
for (i = 0; i < len; ++i)
|
||||
n = (n << 8) + buf[i];
|
||||
|
||||
return n;
|
||||
}
|
||||
|
||||
unsigned int
|
||||
coap_encode_var_bytes(unsigned char *buf, unsigned int val) {
|
||||
int n, i = val >> 1;
|
||||
for (n = 0; i; n++) /* FIXME: coap_fls() */
|
||||
i >>= 1;
|
||||
|
||||
for (i = n / 8 + 1; i; --i) {
|
||||
buf[i-1] = val & 0xff;
|
||||
val >>= 8;
|
||||
}
|
||||
|
||||
return n / 8 + 1;
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user