Read file/stream
Stewart Gordon
smjg_1998 at yahoo.com
Fri Mar 11 11:18:55 PST 2011
On 11/03/2011 18:46, Steven Schveighoffer wrote:
<snip>
> I am not sure what facilities Phobos provides for reading/writing integers in network
> order (i.e. Big Endian), but I'm sure there's something.
http://www.digitalmars.com/d/1.0/phobos/std_stream.html
EndianStream
I haven't experimented with it. And I don't expect it to handle structs well.
Alternatively, you could use some simple code like
--------
version (BigEndian) {
uint bigEndian(uint value) {
return value;
}
}
version (LittleEndian) {
uint bigEndian(uint value) {
return value << 24
| (value & 0x0000FF00) << 8
| (value & 0x00FF0000) >> 8
| value >> 24;
}
}
--------
though you would have to remember to call it for each file I/O operation that relies on
it. If you use a struct, you could put a method in it to call bigEndian on the members of
relevance.
Stewart.
More information about the Digitalmars-d-learn
mailing list