kasunath | 0aa36d8 | 2022-11-23 14:24:15 -0800 | [diff] [blame^] | 1 | #include "bej_common.h" |
kasunath | 7ffd30a | 2022-05-10 18:11:34 -0700 | [diff] [blame] | 2 | |
kasunath | 0aa36d8 | 2022-11-23 14:24:15 -0800 | [diff] [blame^] | 3 | uint64_t bejGetUnsignedInteger(const uint8_t* bytes, uint8_t numOfBytes) |
kasunath | 7ffd30a | 2022-05-10 18:11:34 -0700 | [diff] [blame] | 4 | { |
| 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 | |
kasunath | 0aa36d8 | 2022-11-23 14:24:15 -0800 | [diff] [blame^] | 13 | uint64_t bejGetNnint(const uint8_t* nnint) |
kasunath | 7ffd30a | 2022-05-10 18:11:34 -0700 | [diff] [blame] | 14 | { |
| 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; |
kasunath | 0aa36d8 | 2022-11-23 14:24:15 -0800 | [diff] [blame^] | 18 | return bejGetUnsignedInteger(nnint + sizeof(uint8_t), size); |
kasunath | 7ffd30a | 2022-05-10 18:11:34 -0700 | [diff] [blame] | 19 | } |
| 20 | |
kasunath | 0aa36d8 | 2022-11-23 14:24:15 -0800 | [diff] [blame^] | 21 | uint8_t bejGetNnintSize(const uint8_t* nnint) |
kasunath | 7ffd30a | 2022-05-10 18:11:34 -0700 | [diff] [blame] | 22 | { |
| 23 | // In nnint, first byte indicate how many bytes are there. |
| 24 | return *nnint + sizeof(uint8_t); |
| 25 | } |