Boost logo

Boost Users :

From: Diane (dbutton_at_[hidden])
Date: 2008-09-02 20:03:15


Robert Ramey <ramey <at> rrsd.com> writes:

>
> This example should probably be
>
> ar << binary_object(i + 1, p); // etc
>
> Robert Ramey
>
> Basilevs wrote:
> > On Sat, Aug 30, 2008 at 11:12 AM, Robert Ramey <ramey <at> rrsd.com> wrote:
> >> I'm suspecting that there is a confusion about how to seriailzation a
> >> pointer to
> >> a null terminated string. It's natural to want to do something like
> >>
> >> char *p;
> >> ...
> >> p = "jsdkfjads"
> >> ...
> >> ar & p;
> >>
> >> because the library syntax encourages one to think that way.
> >>
> >> But in this case, one would want
> >>
> >> save(...
> >> int i = strlen(p);
> >> ar << i;
> >> ar << binary_object(i, p);
> >> }
> >>
> >> load(...
> >> int i;
> >> ar >> i;
> >> ar >> binary_object(i,p);
> >> }
> >>
> >
> > How do we deal with the trailing null?
> > In this example trailing null is not saved, and it is a good thing,
> > but shouldn't we add it after loading?
>

Thank you for laying this out, it is exactly what I need.

Is there a way to do this in a free serialize function rather than requiring
save & load functions? I would like to write a serialize function for each of my
structures up through the hierarchy, and it looks to me like if I write
save/load functions for a structure in the middle then I will have to continue
with that all the way through to the top. So I would like to be able to handle
the null terminated string within the serialize function if that's possible.

Thanks,
Diane


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