Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Block Codec concept #250

Open
elshize opened this issue Sep 15, 2019 · 0 comments
Open

Block Codec concept #250

elshize opened this issue Sep 15, 2019 · 0 comments
Milestone

Comments

@elshize
Copy link
Member

elshize commented Sep 15, 2019

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?

@elshize elshize added this to the v1.0 milestone Sep 15, 2019
@elshize elshize mentioned this issue Sep 15, 2019
3 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant