-
-
Notifications
You must be signed in to change notification settings - Fork 163
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
byte_string seems broken #208
Comments
I don't think that's a regression. jsoncons has never supported reading a string from a JSON text into a json value Two-way byte string support is only supported for binary formats, such as CBOR or MessagePack, that accomodate byte string formats. When encoding to JSON, jsoncons encodes byte strings to JSON strings as |
I was going to say I swear I had used it before but I was only reading it in cbor. I wonder if it would be possible to leverage the semantic tags like encoding. So if you do |
I suppose you want a strategy that will work for both CBOR (where you have a byte string) and for JSON (where you have a string in an encoding scheme that jsoncons doesn't know but you do.) One option would be to support |
I actually really like the idea of the |
I've added a new member function to template <class T>
T as(byte_string_arg_t, semantic_tag hint) const; which participates in overload resolution if So you can write std::vector<uint8_t> u = {'H','e','l','l','o'};
json j(byte_string_arg, u, semantic_tag::base64);
auto bytes = j.as<std::vector<uint8_t>>();
std::cout << "(1) ";
for (auto b : bytes)
{
std::cout << (char)b;
}
std::cout << "\n\n";
std::string s;
encode_json(j, s); // tag information is lost
std::cout << "(2) " << s << "\n\n";
auto sj = decode_json<json>(s);
// provide hint
auto v = sj.as<std::vector<uint8_t>>(byte_string_arg,
semantic_tag::base64);
assert(v == u); Output:
Currently on master. |
Greetings, I upgraded and moved my code to the new tags interface and I seem to have a regression. Here is my
json_type_traits
in case I am doing something wrong.I then do the following:
The output from
Buffer1 {}
is correct:The issue is when I try to parse it I get a
json cannot be converted to vector
. I also noticed the following on the printing the tags:to_json
:as
:I assume the string is correct on the read, but shouldn't the parser be able to try to convert the string to a
byte_string
/vector<uint8_t>
?The text was updated successfully, but these errors were encountered: