Creating binary data

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

Creating binary data

Holger Freyther
Hi All,

for the stuff I am planing to use GNU Smalltalk for I will need to
create binary structures. This means I need to write numbers and similar
as uint8,16,32,64, control the endian of these numbers and such. In
Pharo I have found the DataStream class is there something like this in
GNU Smalltalk? How would I solve my usecase in GNU Smalltalk?

My first approach would have been to port something like Python's struct
to Smalltalk.

regards
        holger

_______________________________________________
help-smalltalk mailing list
[hidden email]
http://lists.gnu.org/mailman/listinfo/help-smalltalk
Reply | Threaded
Open this post in threaded view
|

Re: Creating binary data

Paolo Bonzini-2
On Wed, Jun 2, 2010 at 07:17, Holger Hans Peter Freyther
<[hidden email]> wrote:
> Hi All,
>
> for the stuff I am planing to use GNU Smalltalk for I will need to
> create binary structures. This means I need to write numbers and similar
> as uint8,16,32,64, control the endian of these numbers and such. In
> Pharo I have found the DataStream class is there something like this in
> GNU Smalltalk? How would I solve my usecase in GNU Smalltalk?

For native endianness you can create a CStruct subclass and remember
to instantiate it with #gcNew instead of #new.

For specific endianness it is probably best to enhance the primitives
that access CObjects so that they take care of changing endianness.
This would be similar overall to how CArray/CPtr work (i.e. wrap the
original CObject) but of course the field type would still be scalar.

The simplest thing to do is of course to use CStruct and do the
endianness conversion yourself.

Paolo

_______________________________________________
help-smalltalk mailing list
[hidden email]
http://lists.gnu.org/mailman/listinfo/help-smalltalk
Reply | Threaded
Open this post in threaded view
|

Re: Creating binary data

Holger Freyther
On 06/02/2010 02:59 PM, Paolo Bonzini wrote:

> On Wed, Jun 2, 2010 at 07:17, Holger Hans Peter Freyther
> <[hidden email]> wrote:
>> Hi All,
>>
>> for the stuff I am planing to use GNU Smalltalk for I will need to
>> create binary structures. This means I need to write numbers and similar
>> as uint8,16,32,64, control the endian of these numbers and such. In
>> Pharo I have found the DataStream class is there something like this in
>> GNU Smalltalk? How would I solve my usecase in GNU Smalltalk?
>
> For native endianness you can create a CStruct subclass and remember
> to instantiate it with #gcNew instead of #new.

Thanks.

> The simplest thing to do is of course to use CStruct and do the
> endianness conversion yourself.

Is there a list of symbols I can use for my CStruct definition, honestly
I only looked at the CairoMatrix which is a fairly simple case...?

In my case I would like to read and create structure with bitfields like
the one below.

http://bb.osmocom.org/trac/browser/src/shared/libosmocore/include/osmocore/protocol/gsm_04_08.h


thanks
        holger



_______________________________________________
help-smalltalk mailing list
[hidden email]
http://lists.gnu.org/mailman/listinfo/help-smalltalk
Reply | Threaded
Open this post in threaded view
|

Re: Creating binary data

Paolo Bonzini-2
On 06/02/2010 10:33 AM, Holger Hans Peter Freyther wrote:
> In my case I would like to read and create structure with bitfields like
> the one below.
>
> http://bb.osmocom.org/trac/browser/src/shared/libosmocore/include/osmocore/protocol/gsm_04_08.h

Ouch, bitfields are not supported. :-(

The list is in the manual:

    #long                   CLong
    #uLong                  CULong
    #ulong                  CULong
    #byte                   CByte
    #char                   CChar
    #uChar                  CUChar
    #uchar                  CUChar
    #short                  CShort
    #uShort                 CUShort
    #ushort                 CUShort
    #int                    CInt
    #uInt                   CUInt
    #uint                   CUInt
    #float                  CFloat
    #double                 CDouble
    #longDouble             CLongDouble
    #string                 CString
    #smalltalk              CSmalltalk
    #{...}                  The given subclass of CObject

Paolo

_______________________________________________
help-smalltalk mailing list
[hidden email]
http://lists.gnu.org/mailman/listinfo/help-smalltalk