pisa
pisa copied to clipboard
Block Codec concept
In the spirit of #249, I want to start a discussion regarding our block (for now) codec interface.
Here's what it looks like now if represented by C++20 concepts TS:
template <typename T>
concept bool Encodable = requires(T codec,
std::uint32_t const *in,
std::uint32_t sum,
std::size_t n,
std::vector<std::uint8_t> &out)
{
{ T::encode(in, sum, n, out) } -> void;
};
template <typename T>
concept bool Decodable =
requires(T codec, std::uint8_t const *in, std::uint32_t *out, std::uint32_t sum, std::size_t n)
{
{ T::decode(in, out, sum, n) } -> uint8_t const *;
};
template <class T>
concept bool BlockCodecLike = Encodable<T> && Decodable<T>;
But I think we can make it better and more generic by changing several things:
template <typename C, typename V = std::uint32_t>
concept bool Encodable_ =
requires(C codec, V const *in, std::byte *out, std::size_t count, std::optional<V> max_value)
{
{ C::encode(in, out, count) } -> std::size_t;
{ C::max_encoded_bytes(count, max_value) } -> std::size_t;
};
template <typename C, typename V = std::uint32_t>
concept bool Decodable_ = requires(C codec, std::byte const *in, T *out, std::size_t count)
{
{ C::encode(in, out, count) } -> std::size_t;
};
Note that I removed the sum_of_values
. @amallia Is it used anywhere other than interpolative?
Any thoughts?