Handling endianness in Tango's FileConduit

Alexander Pánek alexander.panek at brainsware.org
Sat Oct 4 04:26:03 PDT 2008

Nick Sabalausky wrote:
> I've been looking at the Tango docs, but I'm unclear on how IProtocol works, 
> specifically in relation to endianness.
> I see stuff about protocols and endianness in the docs, so I assume Tango 
> provides a way to say "The file I'm reading/writing through this conduit 
> uses X type of endieanness, so Tango, make sure that any shorts, ints, etc, 
> that I read/write are adjusted to match the system's native endianness."  If 
> so, how would I adjust the following to tell Tango "This file uses 
> little-endian"?:
> auto file = new FileConduit(infilename);
> scope(exit) file.close();
> auto input = new Reader(file.input);
> // Load data through 'input'

tango.io.protocol.EndianProtocol should do that:

auto file = new FileConduit(infilename);
scope(exit) file.close;

auto protocol = new EndianProtocol(file);
auto input = new DerivedReader(protocol);

Note: it seems like this is always assuming the other endianess as your 
current system runs on.

> BTW, A small side question: Tango's conduits don't have anything like 
> "char[] readNullTerminatedString()", do they? It's trivial enough to 
> implement, but I thought if it was there, I may as well just use it. (I 
> don't think it is there though, right? No big deal, though, just wondering.) 

I don’t think so.

More information about the Digitalmars-d-learn mailing list