Boost logo

Boost Users :

Subject: Re: [Boost-users] Seeking in a serialized file
From: Robert Ramey (ramey_at_[hidden])
Date: 2012-02-20 11:47:09


gnu indian wrote:
> hi,
> I am fairly new to boost and using it for serialization. Though I
> went through the archives, couldn't get a clear answer to the
> following:
>
> How do I fseek in a file and load from an offset. I don't want to
> read the whole data in the file; which works ( as given in some
> tutorial); but normal fseekg and then loading apparently doesn't
> work. Here is the sample code:
>
> const char* fileName = "xyz.txt";
>
> // Create some objects
> const Obj o1(1, false);
> const Obj o2;
> const Obj o3(2, true);
> const Obj* const p1 = &o1;
> int p = 0;
> int q = 0;
>
> // Save data
> {
> // Create an output archive
> std::fstream ofs(fileName);
>
> boost::archive::binary_oarchive ar(ofs,boost::archive::no_header);
> // Write data
> ar & o1 & o2 & o3 & p1;
> p = ofs.tellp();
> ar & o1 & o2 & o3 & p1;
> }
>
>
> // Restore data
> Obj restored_o1;
> Obj restored_o2;
> Obj restored_o3;
> Obj* restored_p1;
> {
> // Create and input archive
> std::ifstream ifs(fileName);
> boost::archive::binary_iarchive ar(ifs, boost::archive::no_header
> ifs.seekg(p);
> ar & restored_o1 & restored_o2 & restored_o3 & restored_p1;
> }
>
> Mridul

This is not supported by any current archives.

It has likely been implemented by someone who concatonates separate
serializations into files,
and this might be an interesting case to add to the examples, but so far no
one has done this.

Robert Ramey


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