Endianness and Tango

Mael mael.primet at gmail.com
Wed May 28 06:29:07 PDT 2008


Hello,

this is a noob question, but I'm learning Tango/D, and I'm a bit lost with all the possibilities I'm offered to read/write a file. The format of the file is a bit fuzzy, since it has, say, a BigEndian part followed by a LittleEndian part, so I must switch protocols in the middle of the reading and writing. What should be the
best approach ?

For now, I do :

read( char[] filename )
{
  auto file = new FileConduit( filename ) ;
  version( LittleEndian ) auto inp = new EndianInput!( short )( file );
  version( BigEndian ) auto inp = file ;
  read some stuf... ;

  version( LittleEndian ) auto inp2 = file ;
  version( BigEndian ) auto inp2 = new EndianInput!( float )( file );
  read some stuff... ;
}

and same for writing (with FileConduit.WriteCreate, and EndianOutput!( short ))

the reading seems to work fine, but the writing does not work (looks like when I do the second outpf = file ; it starts writing again from the beginning of the file rather than where I left it before. Plus the code looks ugly, to me, and I don't like having to specify the EndianInput!(short) thing, I'd prefer to tell at the point where I read something, what is the value I will be reading. Someone has a clue ?

I attached my FImage.d  library file


}
-------------- next part --------------
A non-text attachment was scrubbed...
Name: FImage.d
Type: text/x-dsrc
Size: 3067 bytes
Desc: not available
Url : http://lists.puremagic.com/pipermail/digitalmars-d-learn/attachments/20080528/f78f6a7e/attachment.d 


More information about the Digitalmars-d-learn mailing list