Range interface for std.serialization

Dicebot public at dicebot.lv
Wed Aug 21 13:21:48 PDT 2013


My 5 cents:

On Wednesday, 21 August 2013 at 18:45:48 UTC, Jacob Carlborg 
wrote:
> If this alternative is chosen how should the range for the 
> XmlArchive work like? Currently the archive returns a string, 
> should the range just wrap the string and step through 
> character by character? That doesn't sound very effective.

It should be range of strings - one call to popFront should 
serialize one object from input object range and provide matching 
string buffer.

> Alternative AO2:
>
> Another idea is the archive is an output range, having this 
> interface:
>
> auto archive = new XmlArchive!(char);
> archive.writeTo(outputRange);
>
> auto serializer = new Serializer(archive);
> serializer.serialize(new Object);
>
> Use the output range when the serialization is done.

I can't imagine a use case for this. Adding ranges just because 
you can is not very good :)

> A problem with this, actually I don't know if it's considered a 
> problem, is that the following won't be possible:
>
> auto archive = new XmlArchive!(InputRange);
> archive.data = archive.data;

What this snippet should do?

> Which one would usually expect from an OO API. The problem here 
> is that the archive is typed for the original input range but 
> the returned range from "data" is of a different type.

Range-based algorithms don't assign ranges. Transferring data 
from one range to another is done via copy(sourceRange, 
destRange) and similar tools.

> ... snip

It looks like difficulties come from your initial assumption that 
one call to serialize/deserialize implies one object - in that 
model ranges hardly are useful. I don't think it is a reasonable 
restriction. What is practically useful is (de)serialization of 
large list of objects lazily - and this is a natural job for 
ranges.


More information about the Digitalmars-d mailing list