Andrei:
http://tomerfiliba.com/blog/dlang/
struct PascalString { Field!ubyte length;
Also see if UDAs plus compile-time introspection is helpful.
auto stream = cast(ubyte[])"\x05helloXXXX".dup;
Perhaps this is enough, and avoids one allocation: immutable stream = "\x05helloXXXX".representation; Bye, bearophile