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

Possible improvement #34

Open
egorpugin opened this issue May 18, 2022 · 1 comment
Open

Possible improvement #34

egorpugin opened this issue May 18, 2022 · 1 comment
Labels
enhancement New feature or request

Comments

@egorpugin
Copy link

Hi,

Is it possible to improve as such?

using Student = message<
    field<uint32,"id", 1>, 
    field<std::string,"name", 3>
>;

Or another possible way with boost::pfr?

struct Student {
    field<uint32,"id", 1> id; 
    field<std::string,"name", 3> name;
};
@PragmaTwice
Copy link
Owner

PragmaTwice commented May 19, 2022

First of all, thanks for your suggestions!

Is it possible to improve as such?

In protopuf, uint32_field<name, key> is an alias for varint_field<name, key, uint32_t>, and varint_field<name, key, T> is an alias for field<name, key, varint_coder<T>>.

So actually, we divide the data type T and the encoding type *_coder<T>. While you want a uint32_t with varint encoding (refer to protobuf docs and wikipedia), you can use uint32_field (same as uint32 in protobuf), and while you want a uint32_t with fixed length encoding, you can use fixed32_field (alias to integer_field<name, key, uint32_t> and field<name, key, integer_coder<uint32_t>>, same as fixed32 in protobuf).

This design enables flexible combination of data types and encoding methods, and is an important abstraction in protopuf.

Or another possible way with boost::pfr?

This is a great suggestion, and I will go and study its feasibility further.
Let me know if you have any implementation suggestions, issues and PRs are very welcome!

@PragmaTwice PragmaTwice added the enhancement New feature or request label May 19, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants