-
Notifications
You must be signed in to change notification settings - Fork 85
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
How to serialise whole std::list with custom structure type? #4
Comments
Hello, The idea behind Hope that helps :) |
Is this library suitable for maps and nested map? |
yep using NestedType = std::unordered_map<int, std::vector<float>>;
using MyType = std::map<std::string, NestedType>; There are two ways to do it. using verbose syntax (full serialization control), and flexible syntax. In verbose syntax you need to use StdMap extensions namespace bitsery {
template <typename S>
void serialize(S& ser, MyType& data) {
ser.ext(data, ext::StdMap{10}, [&ser](std::string& key, NestedType & value) {
ser.text1b(key, 10);
ser.ext(value, ext::StdMap{10}, [&ser](int& key, std::vector<float>& value) {
ser.value4b(key);
ser.container4b(value, 10);
});
});
}
} or create your own function anywhere you like, e.g. template <typename S>
void serializeAndDeserializeMyType(S& ser, MyType& data) {
ser.ext(data, ext::StdMap{10}, [&ser](std::string& key, NestedType & value) {
ser.text1b(key, 10);
ser.ext(value, ext::StdMap{10}, [&ser](int& key, std::vector<float>& value) {
ser.value4b(key);
ser.container4b(value, 10);
});
});
} In flexible syntax you don't need to define serialize function, just include other headers and you're done! #include <bitsery/flexible.h>
#include <bitsery/flexible/map.h>
#include <bitsery/flexible/unordered_map.h>
#include <bitsery/flexible/string.h>
#include <bitsery/flexible/vector.h> just instead of calling |
Hello,
You have made a very great and simple library but can you just help me with this?
The text was updated successfully, but these errors were encountered: