mpp: introduce object encoding/decoding #63
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Now it became possible to pass an object of any class to
mpp::encode and mpp::decode if a co/dec rule is supplied.
There are two ways to specify a rule for a particular class:
mpp
member forecoding/decoding,
mpp_enc
for encoding only andmpp_dec
fodecoding only.
mpp_rule
for ecoding/decoding,mpp_enc_rule
for ecoding andmpp_dec_rule
for decoding. In any of these cases a staticmember
value
is expected in the specialization.In any case the value of the encoding rule must be a constexpr
expression that could contain any values, including standard
aggregates like std::tuple and pointers to members of the class
that must be encoded/decoded.
Note that one can specify one rule for encoding/decoding as well
as different rules for encoding and decoding.
Examples:
An object of such a class will be encoded/decoded as one integer
(MP_INT) value.
An object of this class will be encoded/decoded as array (MP_ARR)
of three values - a, b, c - with the corresponding types.
This error will be encoded/decoded as map (MP_MAP) with integer
keys (0, 1) and corresponding values (code, descr).