Anant Narayanan wrote:
> I need to to be able to send arbitrary amounts of binary data from and 
> to the socket, even strings used in the protocol are encoded as UTF-8 
> unicode characters. While going through the XPCOM documentation at 
> xulplanet.com, I came across the nsIBinaryInputStream and 
> nsIBinaryOutputStream interfaces, but they seem to provide methods only 
> to read 8, 16, 32 or 64 bytes of data at a time, that too in a fixed 
> big-endian format.

My experience is that this is probably the simplest way to do it, using 
readByteArray and writeByteArray on the binary streams after doing the byte 
swap yourself (ugh, but it's Mozilla's network orientation).  This will let you 
read or write a reasonable amount of data at a time, assuming you can be 
guaranteed that data will be available (or you're willing to handle 
non-blocking stream exceptions).

The streams API isn't really that great for working with binary data without 
doing it in C++, unfortunately; it's something that will be rectified in 
Mozilla 2 (the next iteration of the platform after Firefox 3, most probably, 
and one where we will be breaking API compatibility and probably replacing some 
number of frozen APIs).

Jeff
_______________________________________________
dev-tech-xpcom mailing list
[email protected]
https://lists.mozilla.org/listinfo/dev-tech-xpcom

Reply via email to