[serialization] load-only or save-only types?

Hi, I want to send out instances of one type and receive the same data format but build instances of a different type. Obviously I can just define serialize() for each of them, but can I define only save for the outgoing type and load for the incoming one, causing serialization in the other direction to be a compile-time error? Not a big deal, but it would be more expressive that way. TIA, -- Dave Abrahams BoostPro Computing http://www.boostpro.com

I want to send out instances of one type and receive the same data format but build instances of a different type. Obviously I can just define serialize() for each of them, but can I define only save for the outgoing type and load for the incoming one, causing serialization in the other direction to be a compile-time error? Not a big deal, but it would be more expressive that way.
I'd use a wrapper type to have control over what types get instantiated on the receiving end. This way you don't have to trick the serialization library into handling the same data format differently on the save and load ends. Regards Hartmut

on Mon Nov 03 2008, "Hartmut Kaiser" <hartmut.kaiser-AT-gmail.com> wrote:
I want to send out instances of one type and receive the same data format but build instances of a different type. Obviously I can just define serialize() for each of them, but can I define only save for the outgoing type and load for the incoming one, causing serialization in the other direction to be a compile-time error? Not a big deal, but it would be more expressive that way.
I'd use a wrapper type to have control over what types get instantiated on the receiving end.
I can't picture what you mean, but it doesn't seem to address my question.
This way you don't have to trick the serialization library into handling the same data format differently on the save and load ends.
I don't think there's any trickery involved. I'll just ar << transmit_type; ar >> receive_type; What am I missing? -- Dave Abrahams BoostPro Computing http://www.boostpro.com

David Abrahams wrote:
I don't think there's any trickery involved. I'll just
ar << transmit_type;
ar >> receive_type;
What am I missing?
BOOST_SERIALIZATION_SPLIT_FREE(transmit_type) BOOST_SERIALIZATION_SPLIT_FREE(recieve_type) template<class Archive> save<transmit_type>(Archive ar, ...){...} load<recieve_type>(...){..}. leave undefined the following: save<recieve_type>(...){..}. load<transmit_type>(Archive ar, ...){...} So that your get a compile time error if you try to ar >> transmit_type Robert Ramey

on Tue Nov 04 2008, "Robert Ramey" <ramey-AT-rrsd.com> wrote:
David Abrahams wrote:
I don't think there's any trickery involved. I'll just
ar << transmit_type;
ar >> receive_type;
What am I missing?
BOOST_SERIALIZATION_SPLIT_FREE(transmit_type)
BOOST_SERIALIZATION_SPLIT_FREE(recieve_type)
template<class Archive> save<transmit_type>(Archive ar, ...){...} load<recieve_type>(...){..}.
leave undefined the following:
save<recieve_type>(...){..}. load<transmit_type>(Archive ar, ...){...}
So that your get a compile time error if you try to
ar >> transmit_type
Thanks, I think that works! -- Dave Abrahams BoostPro Computing http://www.boostpro.com

I'm not exactly sure what you're trying to do. But it looks to me that perhaps defining your own variation of boost/serialization/split_member.hpp or boost/serialization/split_free.hpp might do the trick. The templates are designed to instantiate only the code actually called so I believe that they might provide the basis to build what you're looking for. Robert Ramey David Abrahams wrote:
Hi,
I want to send out instances of one type and receive the same data format but build instances of a different type. Obviously I can just define serialize() for each of them, but can I define only save for the outgoing type and load for the incoming one, causing serialization in the other direction to be a compile-time error? Not a big deal, but it would be more expressive that way.
TIA,
participants (3)
-
David Abrahams
-
Hartmut Kaiser
-
Robert Ramey