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

Added the ability for custom Include and Exclude UDAs. If multiple UDAs are given the last applies (with exception). #3

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

JonathanILevi
Copy link
Contributor

I added some feature I need of a project of mine. I hope you will accept them up stream.

You can now give custom Include or Exclude UDAs:

Grouped!(Includer!CustomInclude, Excluder!CustomInclude, Includer!Another).serialize(data);
enum A;
enum B;
class Data {
	@A int a;
	@Exclude @B int b;
}
serialize(data); // `a` included;
Grouped!(Excluder!A).serialize(data); // returns [];
Grouped!(Includer!B).serialize(data); // `a` and `b` included.

The last of stacked UDAs is used (with exception to @DecodeOnly and @EncodeOnly):

class Data {
	int a; // included
@Exclude:
	int b; // excluded
	@Include int c; // included.
@Condition(cond):
	int d; // if condition
	@Include int e; // included
	@Exclude int f; // excluded
	@Condition(cond) int g; // if second condition (first is ignored)
@DecodeOnly:
	// Nothing will ever be encoded (only decoded).  `@DecodeOnly` and `@EncodeOnly` override.
	@Exclude int h; // alway excluded
	@Exclude @Include; // only decoded
}

@codecov-io
Copy link

codecov-io commented Nov 17, 2018

Codecov Report

Merging #3 into master will not change coverage.
The diff coverage is 100%.

Impacted file tree graph

@@          Coverage Diff          @@
##           master     #3   +/-   ##
=====================================
  Coverage     100%   100%           
=====================================
  Files           2      2           
  Lines         139    193   +54     
=====================================
+ Hits          139    193   +54
Impacted Files Coverage Δ
src/xserial/attribute.d 100% <ø> (ø) ⬆️
src/xserial/serial.d 100% <100%> (ø) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 39214ea...b62c480. Read the comment docs.

Because code coverage reports do not necessarily understand CTFE.
@Kripth
Copy link
Owner

Kripth commented Nov 24, 2018

Thank you again for the contribution. Just one thing, can you update the readme with the new functionalities?

@JonathanILevi
Copy link
Contributor Author

I refactored Grouped to Group I think I like it better.

@JonathanILevi
Copy link
Contributor Author

@Kripth I can do that, though, I realized that I think I should rework the current handling of stacked groups.

enum GroupA;
enum GroupB;
struct Test {
@Exclude: // Exlcude everything by default
    @GroupA @GroupB ubyte c; // included in both
}
assert(Group!(Includer!GroupA,Excluder!GroupB).serialize(Test(1,2,3))==[1]); // Group A without any B
assert(Group!(Includer!GroupB,Excluder!GroupA).serialize(Test(1,2,3))==[2,3]); // All of B even c because B is given after A for c;

Stacked groups should not look at the last group UDA given to the value but look at the order given in the Group template. The second assert should yield [2].

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants