Jonathan M Davis:

> UTF-8 strings are easy because they're the same size as ubytes.
> Casting to char[] for the portion of the data that you want as a string 
> seems to work just fine.

D2 string are immutable(char)[] and not char[].
Strings are UTF-8, while the raw bytes you read from a file may contain 
everything, so in some situations you need to use the validate function.


> But what about other types? Is it the correct thing to 
> cast to T[] where T is whatever type the data represents and then index into 
> it 
> to get the values that you want of that type and then cast the next section 
> of 
> the data to U[] where U is the type for the next section of the data, etc.? 
> Or 
> is there a better way to handle this?

It's better to avoid casts when possible, and SafeD may even be restrict their 
usage.
Take a look at the rawWrite/rawRead methods of std.stdio.File.

Bye,
bearophile

Reply via email to