writing uint16's to a binary file
Bijan Parsia
bparsia at email.unc.edu
Tue Mar 12 00:42:40 UTC 2002
On Mon, 11 Mar 2002, Ken G. Brown wrote:
> Thx for the quick responses. See inline comments...
No prob.
[snip]
> > WHy the ReadStream?
>
> Confusing code because I'm confused. I admit it! :)
> ReadStream appeared to have the uint16 possibility from PositionableStream.
> I had tried going directly on the FileStream from collection but iut seemed
> to want to output 32 bits for each element and I have to have 16 bits.
Maybe #nextWordPut:? Its comment reads:
"Append to the receiver an Integer as the next two bytes."
Also, at this point, I'd *strongly* consider a Bitmap, or, likely better,
a ByteArray, as the collection. There's a bunch of nice at and put methods
there.
[snip]
> > > outfile nextPutAll: (rStr do: [ :ii | rStr uint16]).
> >
> > This is definitely broken in a couple of places, most notable in the
> > block. Surely you want ii uint16? Second, if uint16 *returns*
> > something,
> > rather than modifying the receiver (which I suspect will be
> > the case) then
> > you won't have "done" anything that outfile will see. (I'm a bit
> > suspicious about nextPutAll:ing a stream anyway).
>
> My intent was to retrieve the next element of the collection as a uint16,
> via the ReadStream on the collection.
Ah. But then you still want the nextPutting inside the block, because the
#do: returns its *receiver*, which, in this case, will be the
stream. (#do: is really for side effects). So you'd want something like:
rStr do: [ :ii | outfile nextPut: rStr uint16]).
But #collect: and friends seem better.
> I'll be trying out these suggested
> variations.
But, now that I poke a bit, ByteArray seems *much*
better. #shortAt:put:bigEndian: seems *exactly* what you want.
Cheers,
Bijan Parsia.
More information about the Squeak-dev
mailing list
|