static inline UMAX get_bytes(uint8_t* src, size_t byte, size_t bytes)
{
#ifdef UINT64_MAX
int32_t hi = 0;
#endif
int32_t lo = 0;
switch (bytes)
{
#ifdef UINT64_MAX
case 8: hi |= src[byte + 7] << 24;
case 7: hi |= src[byte + 6] << 16;
case 6: hi |= src[byte + 5] << 8;
case 5: hi |= src[byte + 4];
#endif
case 4: lo |= src[byte + 3] << 24;
case 3: lo |= src[byte + 2] << 16;
case 2: lo |= src[byte + 1] << 8;
case 1: lo |= src[byte];
}
return
#ifdef UINT64_MAX
(hi & 0xFFFFFFFFLL) << 32 |
#endif
(lo & 0xFFFFFFFFLL);
}
static inline int32_t set_bytes(const UMAX src, const size_t bytes, uint8_t* dst, const size_t byte)
{
#ifdef UINT64_MAX
const uint32_t hi = (uint32_t)(src >> 32);
#endif
const uint32_t lo = (uint32_t)(src & 0xFFFFFFFFL);
switch (bytes)
{
#ifdef UINT64_MAX
case 8: dst[byte + 7] = hi >> 24;
case 7: dst[byte + 6] = hi >> 16;
case 6: dst[byte + 5] = hi >> 8;
case 5: dst[byte + 4] = hi & 0xFF;
#endif
case 4: dst[byte + 3] = lo >> 24;
case 3: dst[byte + 2] = lo >> 16;
case 2: dst[byte + 1] = lo >> 8;
case 1: dst[byte] = lo & 0xFF;
}
return byte + bytes;
}