-
-
Notifications
You must be signed in to change notification settings - Fork 6.8k
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
Struct with array of struct and __attribute__((packed)) #1866
Comments
In order to asses your issue, we need the following information:
|
The cannot bind packed field errors occurs since One solution is to use
You also need to provide a |
Thanks for the hint. I've changed it but still getting errors:```
Error message: and: I guess there is something missing to tell the compiler that it is an array. |
For arrays, the library accepts auto mode_vec = j.at("mode").get<std::vector<mode_t>>();
for(size_t i=0; i<mode_vec.size(); i++)
{
p.mode[i] = mode_vec[i];
} Here is a minimal working code: https://wandbox.org/permlink/cj2Mn1k6dKnjrxch |
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions. |
What is the issue you have?
"cannot bind packed field".
Please describe the steps to reproduce the issue. Can you provide a small but working code example?
I've tried to cast a json dataset to a custom struct which is attribute packed and includes an array of type enum and an array of structs.
What is the expected behavior?
That it should cast the dataset with the given to_json and from_json functions.
And what is the actual behavior instead?
It does not compile with the following errors:
../src/main.cpp:37:23: error: cannot bind packed field ‘p.data_t::dur’ to ‘unsigned int&’
../src/main.cpp:38:23: error: cannot bind packed field ‘p.data_t::seq’ to ‘unsigned int&’
../src/main.cpp:39:24: error: cannot bind packed field ‘p.data_t::mode’ to ‘unsigned int (&)[5]’
../src/main.cpp:40:26: error: no matching function for call to ‘nlohmann::basic_json<>::get_to(internal_data_t [2]) const’
json.hpp:17270:25: error: no type named ‘type’ in ‘struct std::enable_if<false, int>’
json.hpp:17282:72: error: no type named ‘type’ in ‘struct std::enable_if<false, int>’
....
Which compiler and operating system are you using? Is it a supported compiler?
gcc (Ubuntu 7.4.0-1ubuntu1~18.04.1) 7.4.0
Did you use a released version of the library or the version from the develop branch?
released
If you experience a compilation error: can you compile and run the unit tests?
Yes the unit tests run fine.
Minimal example:
main.cpp:
test.json:
The text was updated successfully, but these errors were encountered: