[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Christian Reiniger wrote:
> It's planned, but I'm not 100% sure about how it will look like. Most
> likely there will be a read/write function for each basic data type (char
> (?), int, double etc) and some config parameter to tell PFile "assume all
> values are little(big) endian".
A more elegant thing is to store a 'magic number' at the top of the
ALL Binary files should start with a 4 byte magic number anyway so that
you can check that you aren't being fed a file of the wrong kind - and
also so that the Linux/UNIX 'file' command can be set to recognise your
file type using /etc/magic.
Suppose we choose: 0x1234 (a short).
When you read a file, first read the magic number. If you see 0x1234
byte swap - if you see 0x3412, you need to swap.
The joy of this is that you don't have to byte swap when WRITING files,
so it halves the amount of work you have to do. Hence, since each
writes files in it's native format, but can read either swapped or not.
Steve Baker http://web2.airmail.net/sjbaker1
firstname.lastname@example.org (home) http://www.woodsoup.org/~sbaker