mirror of
https://github.com/obgm/libcoap.git
synced 2026-12-03 03:01:05 +03:00
encode.c: Support encoding/decoding 8 byte options
Options such as COAP_OPTION_ETAG are up to 8 bytes in size. While being opaque, they can internally be represented as an 8 byte number. include/coap2/encode.h: libcoap-2.map: libcoap-2.sym: src/encode.c: Create 8 byte versions coap_decode_var_bytes8() and coap_encode_var_safe8().
This commit is contained in:
1 parent
1ccd3685ee
commit
851cb374e8
4 files changed
+65
-4
No files matched your search
@@ -58,3 +58,33 @@ coap_encode_var_safe(uint8_t *buf, size_t length, unsigned int val) {
|
||||
return n;
|
||||
}
|
||||
|
||||
uint64_t
|
||||
coap_decode_var_bytes8(const uint8_t *buf,unsigned int len) {
|
||||
unsigned int i;
|
||||
uint64_t n = 0;
|
||||
for (i = 0; i < len; ++i)
|
||||
n = (n << 8) + buf[i];
|
||||
|
||||
return n;
|
||||
}
|
||||
|
||||
unsigned int
|
||||
coap_encode_var_safe8(uint8_t *buf, size_t length, uint64_t val) {
|
||||
unsigned int n, i;
|
||||
uint64_t tval = val;
|
||||
|
||||
for (n = 0; tval && n < sizeof(val); ++n)
|
||||
tval >>= 8;
|
||||
|
||||
if (n > length) {
|
||||
assert (n <= length);
|
||||
return 0;
|
||||
}
|
||||
i = n;
|
||||
while (i--) {
|
||||
buf[i] = val & 0xff;
|
||||
val >>= 8;
|
||||
}
|
||||
|
||||
return n;
|
||||
}
|
||||
Reference in new issue
Block a user