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

feat: add support for std::variant #1075

Merged
merged 8 commits into from
Jul 6, 2023
Merged

Conversation

uyha
Copy link

@uyha uyha commented Jul 3, 2023

No description provided.

@uyha uyha changed the title feat: implement as and pack for std::variant feat: add support for std::variant Jul 3, 2023
@uyha
Copy link
Author

uyha commented Jul 3, 2023

@redboltz I'm having a bit of problem implementing object and object_with_zone, I'm not actually sure what they do and what operation is safe to do in the object case.

@codecov-commenter
Copy link

codecov-commenter commented Jul 3, 2023

Codecov Report

Merging #1075 (35638ea) into cpp_master (ac062e2) will increase coverage by 0.11%.
The diff coverage is 96.96%.

❗ Your organization is not using the GitHub App Integration. As a result you may experience degraded service beginning May 15th. Please install the Github App Integration for your organization. Read more.

Additional details and impacted files
@@              Coverage Diff               @@
##           cpp_master    #1075      +/-   ##
==============================================
+ Coverage       85.63%   85.74%   +0.11%     
==============================================
  Files              79       80       +1     
  Lines            5040     5073      +33     
==============================================
+ Hits             4316     4350      +34     
+ Misses            724      723       -1     

@uyha uyha marked this pull request as ready for review July 3, 2023 17:02
@redboltz
Copy link
Contributor

redboltz commented Jul 4, 2023

@redboltz I'm having a bit of problem implementing object and object_with_zone, I'm not actually sure what they do and what operation is safe to do in the object case.

object adaptor is only provided the packed type can be expressed by msgpack::object without zone allocation.

In the case of std::variant T is unpredictable. It is the same as std::optional.

template <typename T>
struct object<std::optional<T> > {
void operator()(msgpack::object& o, const std::optional<T>& v) const {
if (v) msgpack::adaptor::object<T>()(o, *v);
else o.type = msgpack::type::NIL;
}
};
template <typename T>
struct object_with_zone<std::optional<T> > {
void operator()(msgpack::object::with_zone& o, const std::optional<T>& v) const {
if (v) msgpack::adaptor::object_with_zone<T>()(o, *v);
else o.type = msgpack::type::NIL;
}
};

std::optional adaptor provides object adaptor. If T has object adator, then forward it, otherwise compile error.
At first, I thought that std::variant is the same case, but I noticed that this adaptor needs index. So MessagePack ARRAY is required. That means zone allocation is required.

Hence, this std::variant adaptor shouldn't provide object adaptor.

@redboltz
Copy link
Contributor

redboltz commented Jul 4, 2023

There are some of coding style fix request.
(Sorry for lack of documents)

I will add the comment inline later. Maybe we need to communicate several times.

Copy link
Contributor

@redboltz redboltz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please use 4 whitespaces indent.

I pointed out one case for each request. Please fix other same parts.

include/msgpack/v1/adaptor/cpp17/variant.hpp Outdated Show resolved Hide resolved
include/msgpack/v1/adaptor/cpp17/variant.hpp Outdated Show resolved Hide resolved
include/msgpack/v1/adaptor/cpp17/variant.hpp Outdated Show resolved Hide resolved
@uyha
Copy link
Author

uyha commented Jul 4, 2023

@redboltz could you please have a look again?

Copy link
Contributor

@redboltz redboltz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've checked updated one.

include/msgpack/v1/adaptor/cpp17/variant.hpp Outdated Show resolved Hide resolved
include/msgpack/v1/adaptor/cpp17/variant.hpp Show resolved Hide resolved
include/msgpack/v1/adaptor/cpp17/variant.hpp Show resolved Hide resolved
include/msgpack/v1/adaptor/cpp17/variant.hpp Outdated Show resolved Hide resolved
include/msgpack/v1/adaptor/cpp17/variant.hpp Outdated Show resolved Hide resolved
include/msgpack/v1/adaptor/cpp17/variant.hpp Show resolved Hide resolved
include/msgpack/v1/adaptor/cpp17/variant.hpp Outdated Show resolved Hide resolved
test/msgpack_cpp17.cpp Outdated Show resolved Hide resolved
test/msgpack_cpp17.cpp Outdated Show resolved Hide resolved
include/msgpack/v1/adaptor/cpp17/variant.hpp Outdated Show resolved Hide resolved
@uyha uyha requested a review from redboltz July 4, 2023 06:14
@uyha
Copy link
Author

uyha commented Jul 4, 2023

@redboltz are this PR and #1076 good enough for merge?

@redboltz redboltz merged commit 2d65f66 into msgpack:cpp_master Jul 6, 2023
24 checks passed
@redboltz
Copy link
Contributor

redboltz commented Jul 6, 2023

Merged. Thank you!

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.

3 participants