-
Notifications
You must be signed in to change notification settings - Fork 4
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
**WIP DO NOT MERGE IT**: Add automatic serialization support for boost::hana::Struct #55
base: develop
Are you sure you want to change the base?
Conversation
It is possible with the current API to (1) get a copy of the iarchive reader, (2) use this copy to skip over input, and (3) update the iarchive reader with this copy. Off the top of my head:
|
Okay, I've removed the usage of However I'm not convinced. What's the rationale for this forced copy here? And yes, I know that I could have created a single copy at the beginning of |
These function have not been well-considered. The That said, I would feel uncomfortable about giving users direct access to modify the underlying |
If you're worried about the user unintentionally modifying the internal reader, you can still keep separate getter/setter acessor methods. What do you think about changing template<class F>
void reader(F&& f)
{
f(member.reader);
} Sounds good enough? |
I have been thinking about this for a while, and would like to propose a more consistent solution. Currently the serialization input archive owns the reader, and the output archive owns the writer. Maybe we should start thinking about the archives as "algorithms". We are gravitating towards a composable solution where different algorithms (such as We could therefore make the reader a first-class citizen that represent the current state. The user owns this state and can apply different algorithms to it, including serialization. |
There is a rather easy solution for that. Change I have some experimental changes in 454bf9b on the featur/compose branch. With this you can either let the archive own the reader which works like normal:
or you can use an external reader:
The above-mentioned patch also removes the |
On the idea of two archives, I've believed in the same direction in the past. However the experience with template <typename CharT, typename T, typename Compare, typename MapAllocator>
struct save_overloader< json::basic_oarchive<CharT>,
typename std::map<std::string, T, Compare, MapAllocator> >
{
static void save(json::basic_oarchive<CharT>& archive,
const std::map<std::string, T, Compare, MapAllocator>& data,
const unsigned int protocol_version)
{
archive.template save<json::token::begin_object>();
for (typename std::map<std::string, T, Compare, MapAllocator>::const_iterator it = data.begin();
it != data.end();
++it)
{
archive.save_override(it->first, protocol_version);
archive.save_override(it->second, protocol_version);
}
archive.template save<json::token::end_object>();
}
}; I wrote similar code for Hana. I don't agree with this approach. Boost.Serialization only defines S-exprs mappings. The correct code would be: archive.save_override(it->first, protocol_version);
archive.template save<json::token::begin_array>();
archive.save_override(it->second, protocol_version);
archive.template save<json::token::end_array>(); We shouldn't really insert framing on structs having a load/save/serialize member function. We should insert framing by default (including construction/destruction of the archive) and skip them only if we know it's safe. I was thinking in the lines of... archive.save_override(it->first, protocol_version);
if (!has_native_json_representation<T>::value)
archive.template save<json::token::begin_array>();
archive.save_override(it->second, protocol_version);
if (!has_native_json_representation<T>::value)
archive.template save<json::token::end_array>(); This road would not only be safer and led to actual proper support for Boost.Serialization (we still having missing support for versioning, object id, etc), but would also allow to fix #7. However that alone doesn't help me with the To make matters worse mixing
and pushed it a little further? As in... introduce a lightweight "serialization" layer not dependent on Boost.Serialization that deals with protocol layer. We could move the The Boost.Serialization glue could fallback to this layer but not the other way around (this being the reason why it's safely avoiding the sandwich pattern). I could use the new layer (free from Boost.Serialization concerns) on the |
So... as I was saying in a previous email exchange of ours, I'll need
iarchive::reader()
to return a non-const reference so I can use algorithms such aspartial::skip()
to skip over unwanted extraneous members for instance.Users that specialize the types to have specific serialization for JSON might want just the same as well.
The code is fairly small and you could already take a look.