Endian conversion problems

David Beck davethebrv at mac.com
Tue Aug 5 21:59:01 EDT 2003


Hey,

I have been using rev for a couple years now and think its great! But I
recently ran into an issue which I am having trouble resolving and was
hoping somebody on this list could help out. My problem is as follows:

I have a stack that I am building for both Mac and Windows. It needs to be
able to create and read binary files. Much of the data I need to read/write
consists of 2-byte integers. The docs gave me the impression (although I
haven't confirmed this) that the read/write to file commands using the int2
keyword are endian dependant, meaning that on the Mac side network byte
order is used, but on the Windows side host byte order is used. Obviously I
want the files to be consistent so that the Mac Rev app can create file that
can be read with the Win Rev app and visa vera. I have decided to go with
network byte order for the files since my user base will be mostly Mac
people.

The question is: What is the best way to read/write a bunch of 2-byte
integers in network byte order on Windows??

I looked in to read/writing raw chars, and then using the
binaryEncode/binaryDecode functions to translate the raw binary data to
numbers, but those functions require a parameter for every value that gets
encoded/decoded. I need to be able to read/write sequences of up to 1120
2-byte integers in a reasonable amount of time, and I can neither supply
1120 arguments to those functions, nor can I read/write the ints one at a
time, since doing this is unacceptably slow.

Sombody must have run into this problem before. Did anybody figure out a
decent solution??

Thanks in advance,
Dave 

ps. As a side note, I noticed that there is no support for 4-byte integers
in network byte order from the binaryEncode/binaryDecode functions. This
isn't a problem for me, since almost all of the data I need to read/write is
2-byte integers, but I thought it was strange since there is support for
4-byte integers in host byte order from the same functions. Just thought I'd
mention that in case it was an oversight and there is Rev staff present.





More information about the use-livecode mailing list