Byte order and ByteArray conversions

John.Maloney at disney.com John.Maloney at disney.com
Mon Nov 1 20:07:53 UTC 1999


Dave:

Re:
>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.

This is actually NOT a recommended, for several reasons. First,
these objects are meant to just be handles to an opaque data
abstraction; if you started to modify the bits you could either
break the abstraction, crash the VM, or become dependent on an
implementation detail that could change without warning in some
future release. Second, the representation is entirely platform
dependent. If you want your code to run everywhere, you'd have to
have variations for each platform, and you'd need to detect which
platform you were running on. That's just what the Squeak VM's
abstraction of the underlying OS facilities is supposed to save
you from having to do.

Re:
>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.

It seems to me that you would accomplish your goals most easily
simply by building wrapper object that holds either a FileStream and
Socket object. That is, you could build a class "UniversalStream"
that provides buffered stream I/O to either a file or a socket.
Instances of UniversalStream would have a private instance variable that
was a Squeak FileStream or Socket object. There would be no reason for
them to directly manipulate the data structures of the underlying VM
implementation of these objects (SQFile and SQSocket).

	-- John





More information about the Squeak-dev mailing list