diff options
| author | Stanislaw Halik <sthalik@misaki.pl> | 2024-01-15 07:24:08 +0100 |
|---|---|---|
| committer | Stanislaw Halik <sthalik@misaki.pl> | 2024-01-15 07:24:08 +0100 |
| commit | 152f9ef5feff7ea41c647e004f6e98082abf4b1c (patch) | |
| tree | 59c2cabb1291aa8d938d2768b8183f14e8b6d8ad /serialize/packbits-write.hpp | |
| parent | 8c7d8405b7c88d0553ee505061ade27127410431 (diff) | |
w
Diffstat (limited to 'serialize/packbits-write.hpp')
| -rw-r--r-- | serialize/packbits-write.hpp | 34 |
1 files changed, 17 insertions, 17 deletions
diff --git a/serialize/packbits-write.hpp b/serialize/packbits-write.hpp index 7b69069a..34fc140f 100644 --- a/serialize/packbits-write.hpp +++ b/serialize/packbits-write.hpp @@ -1,28 +1,28 @@ #pragma once -#include "packbits.hpp" +#include <concepts> -namespace floormat::detail_Pack { +namespace floormat::detail_Pack_output { -template<std::unsigned_integral T, size_t CAPACITY> +template<std::unsigned_integral T> struct output { - static_assert(CAPACITY <= sizeof(T)*8); - static constexpr size_t Capacity = CAPACITY; - T value; + T value = 0; + uint8_t capacity = sizeof(T)*8; - template<size_t N> - constexpr void set(T x) const + constexpr inline output next(T x, uint8_t bits) const { - static_assert(N > 0); - static_assert(N <= sizeof(T)*8); - static_assert(N <= Capacity); - if constexpr(CAPACITY < sizeof(T)*8) - value <<= CAPACITY; - T x_ = T(x & (1 << N)-1); + fm_assert(bits > 0 && bits <= capacity); + auto val = value; + val <<= bits; + T x_ = T(x & (T{1} << bits)- T{1}); fm_assert(x_ == x); - value |= x; + val |= x_; + return { val | x_, capacity - bits }; } - template<size_t N> using next = output<T, CAPACITY - N>; }; -} // namespace floormat::detail_Pack + + + + +} // namespace floormat::detail_Pack_output |
