blob: 1d3be07a8d991e1a6798f1763bfdc4c9ae8ce775 [file] [log] [blame]
kasunath0aa36d82022-11-23 14:24:15 -08001#include "bej_common.h"
kasunath7ffd30a2022-05-10 18:11:34 -07002
kasunath0aa36d82022-11-23 14:24:15 -08003uint64_t bejGetUnsignedInteger(const uint8_t* bytes, uint8_t numOfBytes)
kasunath7ffd30a2022-05-10 18:11:34 -07004{
5 uint64_t num = 0;
6 for (uint8_t i = 0; i < numOfBytes; ++i)
7 {
8 num |= (uint64_t)(*(bytes + i)) << (i * 8);
9 }
10 return num;
11}
12
kasunath0aa36d82022-11-23 14:24:15 -080013uint64_t bejGetNnint(const uint8_t* nnint)
kasunath7ffd30a2022-05-10 18:11:34 -070014{
15 // In nnint, first byte indicate how many bytes are there. Remaining bytes
16 // represent the value in little-endian format.
17 const uint8_t size = *nnint;
kasunath0aa36d82022-11-23 14:24:15 -080018 return bejGetUnsignedInteger(nnint + sizeof(uint8_t), size);
kasunath7ffd30a2022-05-10 18:11:34 -070019}
20
kasunath0aa36d82022-11-23 14:24:15 -080021uint8_t bejGetNnintSize(const uint8_t* nnint)
kasunath7ffd30a2022-05-10 18:11:34 -070022{
23 // In nnint, first byte indicate how many bytes are there.
24 return *nnint + sizeof(uint8_t);
25}