Tim, is this something that could be handled in the Grease package for Seaside? I am not up to speed on Seaside things, but I'm guessing that the notion of LPI>>asByteArray might have been one of those Pharo "enhancements".

I like your idea of having a method to directly convert a hash value into net-transportable base64 format, that seems much better than trying to do a generic asByteArray for integers.

Dave


On 2023-11-13 18:24, Tim Rowledge wrote:



On 2023-11-13, at 4:53 AM, Taeumel, Marcel via Squeak-dev <squeak-dev@lists.squeakfoundation.org> wrote:

1152921504606846976 asByteArray

That example is hilariously confusing at first glance. 16! How can it be 16! Oh no it's all screwed up!
And then you remember that the 16 is the *highest* byte...

I'd suggest that this is one of those cases where a too-general name got chosen, then used in some places where 'other code' needed a ByteArray (consider the conversion of bitmaps to bytearrays to allow using the compression code), and then mis-used in other places where it isn't really appropriate.

The case that triggered this thread is in Seaside where a hash of a string is used as a key into some javascript thing. -
entityTagFor: aStringOrByteArray
    | hash base64 |
    hash := GRPlatform current secureHashFor: aStringOrByteArray.
    "etags have to be delimited by double quotes"
    base64 := GRPlatform current base64Encode: hash asByteArray.
    ^ String new: base64 size + 2 streamContents:  [ :stream |
        stream
            nextPut: $";
            nextPutAll: base64;
            nextPut: $"]

I can't help thinking it might be more helpful to have a method to directly convert a hash value into net-transportable base64 format.

And then there are methods like CanvasEncoder>>#drawString:from:to:in:font:color: where an argument is converted to a String, copied from (so we know the result is a String), then if it is a WideString converted to a byte array and then to a String again. I suspect it is because StringSocket doesn't have a way to handle WideStrings in #addToOutBuf: and so on. So any user has to do the converse dance just in case.

tim
--
tim Rowledge; tim@rowledge.org; http://www.rowledge.org/tim
Do you like me for my brain or my baud?