summaryrefslogtreecommitdiffhomepage
path: root/serialize
diff options
context:
space:
mode:
authorStanislaw Halik <sthalik@misaki.pl>2024-01-15 06:35:39 +0100
committerStanislaw Halik <sthalik@misaki.pl>2024-01-15 06:35:39 +0100
commit8c7d8405b7c88d0553ee505061ade27127410431 (patch)
treea78d75ebf176dc81009417b91b374820bcb74ed0 /serialize
parentb38c2ac1d97a2c0090ce7f63a40b98fcd174b356 (diff)
a
Diffstat (limited to 'serialize')
-rw-r--r--serialize/packbits-read.hpp14
-rw-r--r--serialize/packbits-write.hpp20
-rw-r--r--serialize/packbits.cpp2
-rw-r--r--serialize/packbits.hpp4
4 files changed, 32 insertions, 8 deletions
diff --git a/serialize/packbits-read.hpp b/serialize/packbits-read.hpp
index 32eca8df..362ec604 100644
--- a/serialize/packbits-read.hpp
+++ b/serialize/packbits-read.hpp
@@ -11,8 +11,6 @@ template<std::unsigned_integral T, size_t CAPACITY>
struct input
{
static_assert(CAPACITY <= sizeof(T)*8);
-
- using Type = T;
static constexpr size_t Capacity = CAPACITY;
T value;
@@ -36,7 +34,13 @@ struct input
constexpr bool operator==(const input&) const noexcept = default;
[[nodiscard]] constexpr inline bool check_zero() const { return value == T(0); }
- template<size_t N> using next = input<T, Capacity - N>;
+ template<size_t N>
+ struct next_
+ {
+ static_assert(N <= Capacity);
+ using type = input<T, Capacity - N>;
+ };
+ template<size_t N> using next = typename next_<N>::type;
};
template<std::unsigned_integral T>
@@ -85,8 +89,8 @@ template<std::unsigned_integral T, size_t... Ns> using make_pack = empty_pack_tu
} // namespace floormat::detail_Pack
-namespace floormat::Pack {
+namespace floormat::pack {
-} // namespace floormat::Pack
+} // namespace floormat::pack
diff --git a/serialize/packbits-write.hpp b/serialize/packbits-write.hpp
index 4741a462..7b69069a 100644
--- a/serialize/packbits-write.hpp
+++ b/serialize/packbits-write.hpp
@@ -3,6 +3,26 @@
namespace floormat::detail_Pack {
+template<std::unsigned_integral T, size_t CAPACITY>
+struct output
+{
+ static_assert(CAPACITY <= sizeof(T)*8);
+ static constexpr size_t Capacity = CAPACITY;
+ T value;
+ template<size_t N>
+ constexpr void set(T x) 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(x_ == x);
+ value |= x;
+ }
+ template<size_t N> using next = output<T, CAPACITY - N>;
+};
} // namespace floormat::detail_Pack
diff --git a/serialize/packbits.cpp b/serialize/packbits.cpp
index 84d91c28..1a7f5de8 100644
--- a/serialize/packbits.cpp
+++ b/serialize/packbits.cpp
@@ -1,4 +1,5 @@
#include "packbits-read.hpp"
+#include "packbits-write.hpp"
#include "compat/assert.hpp"
namespace floormat {
@@ -8,7 +9,6 @@ using namespace floormat::detail_Pack;
namespace {
template<std::unsigned_integral T, size_t N> constexpr inline T lowbits = (T{1} << N)-T{1};
-template<size_t Val> using us_bits = bits<uint16_t, Val>;
static_assert(!input<uint32_t, 3>{65535}.check_zero());
static_assert(input<uint32_t, 30>{65535}.advance<16>() == 0);
diff --git a/serialize/packbits.hpp b/serialize/packbits.hpp
index ee8aeaec..7d612942 100644
--- a/serialize/packbits.hpp
+++ b/serialize/packbits.hpp
@@ -32,8 +32,8 @@ template<typename... Ts> struct empty_pack_tuple {};
} // namespace floormat::detail_Pack
-namespace floormat::Pack {
+namespace floormat::pack {
-} // namespace floormat::Pack
+} // namespace floormat::pack