Boost logo

Boost Users :

From: sam p (sameersp21_at_[hidden])
Date: 2008-08-23 07:50:23


This is fine for most of the cases.
But suppose I want to pass serialized stream over a network and at the other
end I want to validate each datatype before deserializing it then how to do
it?
Can I use typeinfo somehow?

Thanks,
Sameer

On Fri, Aug 22, 2008 at 11:47 PM, Robert Ramey <ramey_at_[hidden]> wrote:

> The easy way is to use:
>
> template<class Archive>
> void serialize(Archive & ar, const unsigned int file_version)
> {
> ar & tmpMap;
> ar & a;
> ar & d;
> ar & stringList;
> }
>
> then input/output are always insync.
>
> Robert Ramey
>
> "sam p" <sameersp21_at_[hidden]> wrote in message
> news:c49aaa00808212055v39e5036habe307521a42d5b_at_mail.gmail.com...
> Hi,
>
> How to validate datatype before it gets deserialized?
> e.g.
> struct Abc
> {
>
> std::map<string,string> tmpMap;
> int a;
> float d;
> std::list<string> stringList;
>
> void serialize(boost::archive::polymorphic_oarchive & ar, const
> unsigned int file_version)
> {
> ar & tmpMap;
> ar & a;
> ar & d;
> ar & stringList;
> }
> void serialize(boost::archive::polymorphic_iarchive & ar, const
> unsigned int file_version)
> {
> /////////////////////////////////////////////////////////////////////
> /* Now the right thing to do over here is
> ar & tmpMap;
> ar & a;
> ar & d;
> ar & stringList;
> */
>
> ///////////////////////////////////////////////////////////////////////
> //But instead, if by mistake user writes something like
> ar & a;
> ar & d;
> ar & stringList;
> ar & tmpMap;
> /*
> So how to handle such problem?
> Can I validate data somehow before it gets deserialized?
> On some platforms like SuSE linux I have observed that such thing
> doesn't throw exception and we get SEGV.
> */
> }
>
> };
>
> Thanks,
> Sameer
>
> ------------------------------
>
> _______________________________________________
> Boost-users mailing list
> Boost-users_at_[hidden]
> http://lists.boost.org/mailman/listinfo.cgi/boost-users
>
>
> _______________________________________________
> Boost-users mailing list
> Boost-users_at_[hidden]
> http://lists.boost.org/mailman/listinfo.cgi/boost-users
>



Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net