Handling endianness in Tango's FileConduit

Steven Schveighoffer schveiguy at yahoo.com
Sat Oct 4 10:57:00 PDT 2008

"Alexander Pánek" wrote
> 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.

Try PickleProtocol.  This always assumes the data being read/written is big 
endian.  I don't think there's an equivalent one if the file is in little 
endian form, but you could always just copy what PickleProtocol does (make 
an alias depending on native endianness).  In fact, PickleProtocol should 
probably be changed to allow you to specify the endianness you want.


More information about the Digitalmars-d-learn mailing list