Byte order and ByteArray conversions

David T. Lewis lewis at mail.msen.com
Mon Nov 1 00:30:06 UTC 1999


On Sun, Oct 31, 1999 at 12:38:43PM +0000, Lex Spoon wrote:
> 
> If you know the endian-ness you want, you can use nextNumber:put: and
> nextLittleEndianNumber:put: to write out integers in big endian or
> little endian.  So that would probably be the inverse of the methods you
> were looking for.  You can read them back with nextNumber: and
> nextLittleEndianNumber:.

Thanks, that's what I was looking for. I don't know why I missed it the
first time.

> But why would knowing the machine's ordering matter, unless you are
> doing primitives?  Maybe if you post a higher-level view of what you are
> trying to do, someone will have a more helpful response.  I tend to like
> the fact that I don't have to think about endianness :)
> 
> Lex

I'm trying to map a data structure (struct SQFile) in the VM to its
corresponding set of objects. The data structure is available as a
ByteArray on the Smalltalk side, and I was looking for a quick and
dirty way to convert to ByteArray into its corresponding Integers and
so forth. This would allow a convenient way to look at the SQFile data
structure with normal Smalltalk inspectors.

I suspect that the right way to do this is to rewrite the primitives
so they return arrays of objects, rather than raw ByteArrays. But that
involves a little more surgury than I wanted to get into.

Further background: It seems to me that there should be no real conceptual
difference between an IO channel to a file, and an IO channel to a socket,
or to any other external IO channel which can be opened, closed, read,
or written to. Presumably these should all look like streams, and presumably
we would want socket streams, file streams, and any other streams on
external IO channels to behave in similar ways. The specifics of making
connections to various types of external IO channels probably merit their
own classes, which would know about things like SQFile and SQSocket data
structures if needed. I wrote some classes to do this for files and sockets,
and it all seems to work very nicely, but I still need a machine independent
way to convert the file and socket data structures into Smalltalk objects,
hence the question about converting integers back and forth between
ByteArrays and Integers.

 - Dave





More information about the Squeak-dev mailing list