On Tuesday, 20 August 2013 at 10:51:25 UTC, Johannes Pfau wrote:
Am Tue, 20 Aug 2013 10:40:57 +0200
schrieb "ilya-stromberg" <ilya-stromberg-2...@yandex.ru>:
We can use InputRange like this:
import std.file;
auto archive = new Archive()
Serializer(archive).serialize(object);
//Archive implements InputRange for ubyte[]
write("file", archive);
Yes, InputRange is more flexible, but it's also more difficult
to
implement and less efficient:
What happens between the 'serialize' and the 'write' call?
Archive
has to cache the data, either the original object or the final
produced data in an ubyte[] buffer.
No, Archive have to do NOTHING. 'serialize' call must only store
pointer to the object - without this requirement we can't have
lazy range. Serialization starts afrer 'write' call, and
ArchiveInputRange have to store current serialization state (like
Serializer in current implementation).