attribute length missing in std.array: Appender

Andre via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Thu Nov 27 08:08:12 PST 2014


Hi,

I implement a network protocol and use an Appender!(ubyte[])().
I have following issue. The first three bytes I have to fill,
the following bytes are reserved and must be 0. In this example
the overall header length must be 8.

import std.array: appender;
const HEADER_LENGTH = 8;
	
auto app = appender!(ubyte[])();
app.put(cast(ubyte)40);
app.put(cast(ubyte)5);
app.put(cast(ubyte)234);
// ... add 5 times 0
// variable length body will follow

In case of dynamic array I can simple set the length to 8.
Appender doesn't have a length attribute.

Is there some other nice D functionaliy I can use?
Maybe some functionality in std.array is missing: app.fill(0, 
HEADER_LENGTH)?
Currently I do a work around with a for loop.

Kind regards
André


More information about the Digitalmars-d-learn mailing list