Streams vs ranges

Piotr Szturmaj bncrbme at jadamspam.pl
Fri Jan 13 03:17:06 PST 2012


Is there a plan to replace streams with byte ranges? Or should I just 
use streams?

I need to do some binary parsing and I found using ranges is not very 
comfortable. For example to read an uint I need to:

version (LittleEndian)
     auto r = retro(takeExactly(range, 4));
else
     auto r = takeExactly(range, 4);

uint u;
auto ar = (cast(ubyte*)&u)[0 .. 4];
replaceInPlace(ar, 0, 4, r);

while with streams its easier:

uint u;
stream.read(u);
version (LittleEndian)
     u = swapEndian(u);


More information about the Digitalmars-d-learn mailing list