[Glass] How to properly write bytes objects into binary streams?

Mariano Martinez Peck via Glass glass at lists.gemtalksystems.com
Wed Sep 3 13:22:54 PDT 2014


On Wed, Sep 3, 2014 at 5:07 PM, Martin McClure <
martin.mcclure at gemtalksystems.com> wrote:

> On 09/03/2014 12:26 PM, Mariano Martinez Peck wrote:
>
>>
>>
>>
>> On Wed, Sep 3, 2014 at 4:10 PM, Dale Henrichs
>> <dale.henrichs at gemtalksystems.com
>> <mailto:dale.henrichs at gemtalksystems.com>> wrote:
>>
>>     My point is that LargeIntegers are not polymorphic byte-objects (no
>>     methods for accessing the bytes for a LargeInteger) ... in GemStone
>>
>>
>> OK. Thanks. Point taken. I could make a special serialization for them.
>> But I was hoping to find a general way for all the other guys. These are
>> the problematic ones:
>>
>>
> #_basicAt: and #_basicAt:put: do work to access the bytes of large
> integers (and I think all byte objects).
>
>
mmmmm I cannot access those in SmallDouble. I need to do a _asFloat. Maybe
because it is "special" (immediate object?).

Anyway, this doesn't work:

| byte1 byte2 |
byte1 := (1.1 _asFloat _basicAt: 1).
byte2 := (1.1 _asFloat _basicAt: 2 ).
(Float basicNew) _basicAt: 1 put: byte1; _basicAt: 2 put: byte2 ; yourself

_basicAt:  is answering strange numbers I think.


> The trick is to create an instance of these class classes. For
> LargeInteger, for instance, this is currently quite restricted. The best
> I've come up with so far is to create one the correct size like this:
>
> | size int1 int2|
> size := <size in bytes you want>
> int1 := (2 raisedToInteger: (size - 4 * 8)) - 1.
> "int1 is the right size, but immutable"
> int2 := int1 copy.
> "int2 is mutable, and can be modified via #_basicAt:put:"
>
>
OK, I see. THe way I found for Integers and LargeIntegers is to do a
#asByteArray when serializing and #asInteger when materializing and use a
regular #nextPutAll.

Thanks!



> Regards,
>
> -Martin
>



-- 
Mariano
http://marianopeck.wordpress.com
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.gemtalksystems.com/mailman/private/glass/attachments/20140903/30824e8c/attachment.html>


More information about the Glass mailing list