On Saturday, 29 August 2015 at 20:15:53 UTC, Marc Schütz wrote:
Just cast to `Crumbs[]` directly:
import std.bitmanip;
import std.stdio;
import std.file;
struct Crumbs {
mixin(bitfields!(
ubyte, "one", 2,
ubyte, "two", 2,
ubyte, "three", 2,
ubyte, "four", 2
));
}
void main(string[] argv)
{
auto raw = read("binaryfile");
auto buffer = cast(Crumbs[]) raw;
foreach (cmb; buffer) {
writefln("Crumb one: %s", cmb.one);
writefln("Crumb two: %s", cmb.two);
writefln("Crumb three: %s", cmb.three);
writefln("Crumb four: %s", cmb.four);
}
}
I like that :-)