Boost logo

Boost Users :

Subject: Re: [Boost-users] serialization example
From: Marco Piacentini (marcopiacenta_at_[hidden])
Date: 2011-03-23 05:38:52


Maybe we refer to two distinct case...this is the example of boost::serialization // Serialize the data first so we know how large it is. std::ostringstream archive_stream; boost::archive::text_oarchive archive(archive_stream); archive << t; outbound_data_ = archive_stream.str(); // Format the header. std::ostringstream header_stream; header_stream << std::setw(header_length) << std::hex << outbound_data_.size(); if (!header_stream || header_stream.str().size() != header_length) { // Something went wrong, inform the caller. boost::system::error_code error(boost::asio::error::invalid_argument); socket_.io_service().post(boost::bind(handler, error)); return; } outbound_header_ = header_stream.str(); // Write the serialized data to the socket. We use "gather-write" to send // both the header and the data in a single write operation. std::vector<boost::asio::const_buffer> buffers; buffers.push_back(boost::asio::buffer(outbound_header_)); buffers.push_back(boost::asio::buffer(outbound_data_)); boost::asio::async_write(socket_, buffers, handler); } I don't understand if is mandatory to attach this header, or if I can delete it. ________________________________ Da: "Pfligersdorffer, Christian" <Christian.Pfligersdorffer_at_[hidden]> A: boost-users_at_[hidden] Inviato: Ven 18 marzo 2011, 16:57:09 Oggetto: Re: [Boost-users] serialization example Marco Piacentini wrote: > In the example of the serialization, before serialize, an header is linked to >the data. > It will be handle both in write and read operations. > Is this header essential for the serialization process, or it can be omitted >and I can serialize only the data? > thank you... Try the boost::archive::no_header flag when constructing your archive. Then you will serialize only data, if that is what you wanted. Good luck, -- Christian Pfligersdorffer Software Engineering www.eos.info _______________________________________________ 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