-
Notifications
You must be signed in to change notification settings - Fork 918
Added a visitor version of unpack API, #461
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
Conversation
The current unpacking APIs are constructed on the visitor mechanism. (Fixed msgpack#418) Updated test condition.
test/unpack_visitor.cpp
Outdated
|
|
||
| #if MSGPACK_DEFAULT_API_VERSION >= 2 | ||
|
|
||
| struct json_visitor : msgpack::v2::null_visitor { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since this test is also listed on the wiki documentation page, I'll point out two potential issues:
end_map_value()doesn't append a comma to separate map items likeend_array_item()does.visit_str()doesn't process strings as Unicode, therefore non-ASCII codepoints will result in invalid JSON (which encodes them as e.g."\u00f8").
Neither of these is required by the test case so that's okay for this particular piece of code, however you might want to point it out in the documentation.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for the comments.
end_map_value() doesn't append a comma to separate map items like end_array_item() does.
I will fix it.
visit_str() doesn't process strings as Unicode, therefore non-ASCII codepoints will result in invalid JSON (which encodes them as e.g. "\u00f8").
True. The point of the test and the document is not accurate JSON, I just demonstrate a visitor usage. However, I should use a precise term. I will fix the test and the document. I will use the term 'json like structure ( string is not espaced)'.
|
One more thing to consider: When I was having a look at https://github.com/msgpack/msgpack-c/wiki/v2_0_cpp_unpack_visit, I realized that this code isn't actually unpacking the msgpack buffer, at least not in the traditional sense of unpack as "parse buffer into msgpack::object". Since the function name ( |
|
Good point. |
|
I've fixed all problems that you pointed out. In addition, I found end_map_value() calling point was wrong, and fixed it. https://github.com/redboltz/msgpack-c/blob/add_unpack_visitor_api/include/msgpack/v2/unpack.hpp#L434 |
Renamed names that related to a visitor. Renamed test name from json to json_like because I omit escape. Added end_map_value() and end_map() implementation.
44d2dfc to
6593cba
Compare
|
@jpetso , could you review my fix? If my fix would be ok, I will merge it. |
|
I am going to merge the PR this weekend if no comments are post. |
|
Hi, sorry, and well done! I had a pretty tight few weeks and didn't manage to find the time for the review. Since the first version of the patch was already very good, I'm assuming it's quite alright :) Anyway, I'm glad it's in, and thank you for your hard work! |
|
@jpetso , thank you! |

The current unpacking APIs are constructed on the visitor mechanism.
(Fixed #418)