Boost logo

Boost Users :

Subject: Re: [Boost-users] [serialization] EOF marker?
From: Lars Viklund (zao_at_[hidden])
Date: 2013-04-15 13:05:42


On Mon, Apr 15, 2013 at 04:34:47PM +0000, Ramey, Larry wrote:
> To my knowledge, S11n expects the code that reads the data to be aware of the exact order, count and types of things in the serialized stream.
>
> This means that if you want a sequence of variable length, you need to serialize and deserialize data from which you can derive the extents of the sequence.
>
> You might be able to piggyback on existing logic if you put all your objects in a standard library container like a list or vector and serialize _that_.
>
> Otherwise, count the objects and write a sized integer denoting the count, or write a sentinel object that you can use to find the end of the sequence.
>
> Depending on your actual use case and types involved, one may be easier than the other.
>
> --
> Lars Viklund | zao_at_[hidden]
> _______________________________________________
> Boost-users mailing list
> Boost-users_at_[hidden]
> http://lists.boost.org/mailman/listinfo.cgi/boost-users
>
>
> I can't count the object because I don't know how many I'm going to write. I am dumping debug elements as time passes... it it not know a priori how many will get dumped.
>
> You are saying, make my OWN EOF class. Yeah, I could do something like that. (why didn't I think of that myself?)

Another reasonably lightweight thing you could do would be that instead
of just writing the object, you write a single or few-byte identifier
indicating the category of the following object.

Or if the context is sufficiently narrow, write a bool indicating
whether you're out of objects, so your stream would be something like:

{ false, obj0, false, obj1, false, obj2, true }

-- 
Lars Viklund | zao_at_[hidden]

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