BitSyntax for Squeak

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

BitSyntax for Squeak

Tony Garnock-Jones-5
Hi all,

As I've been working on getting a working cellphone with Squeak in
charge of the operating system, I've found myself needing to decode and
encode a number of complex telephony packet formats such as the
following, an incoming SMS delivery message containing an SMS-DELIVER
TPDU in GSM 03.40 format, containing seven-bit (!) GSM 03.38-encoded text:

  02 01 ffff
  01 28 07911356131313f3
  04 0b911316325476f8 000002909021044480 0ec67219644e83cc6f90b9de0e01

It turns out there are a *plethora* of such binary formats needed to get
a working cellphone.

I started off hand-rolling them, but it quickly became too much, so
borrowing from Erlang, I implemented BitSyntax for Smalltalk:

  https://squeaksource.com/BitSyntax.html

The BitSyntax package includes a `BitSyntaxCompiler` class which
interprets `BitSyntaxSpecification` objects, producing reasonably
efficient Smalltalk for decoding and encoding binary structures, mapping
from bytes to instance variables and back again.

Specs are written in an embedded DSL and look like this:

  (2 bytesLE >> #statusCode),
  (4 bytesLE
      storeTemp: #messageLength
      expr: 'statusMessage size'),
  (#messageLength bytes ascii >> #statusMessage)

I wrote a blog post containing a bit more detail and a bigger example
based on the SMS message above:

  https://eighty-twenty.org/2020/10/07/bit-syntax-for-smalltalk

There's also a wiki page, which includes examples of the generated code:

  https://wiki.squeak.org/squeak/6649

And if you install the code, there's a manual as part of Squeak's Help
system:

  (Installer squeaksource project: 'BitSyntax')
    install: 'BitSyntax-Core';      "the compiler and EDSL"
    install: 'BitSyntax-Examples';  "non-trivial examples"
    install: 'BitSyntax-Help'.      "user guide and reference"

Enjoy!

Cheers,
  Tony

Reply | Threaded
Open this post in threaded view
|

Re: BitSyntax for Squeak

Douglas Brebner-2
On 07/10/2020 09:30, Tony Garnock-Jones wrote:
> I started off hand-rolling them, but it quickly became too much, so
> borrowing from Erlang, I implemented BitSyntax for Smalltalk:
>
>    https://squeaksource.com/BitSyntax.html
>
> The BitSyntax package includes a `BitSyntaxCompiler` class which
> interprets `BitSyntaxSpecification` objects, producing reasonably
> efficient Smalltalk for decoding and encoding binary structures, mapping
> from bytes to instance variables and back again.


Weird, I was looking into binary parsing tools only yesterday.

Thanks for this :)


Reply | Threaded
Open this post in threaded view
|

Re: BitSyntax for Squeak

Tony Garnock-Jones-5
On 10/7/20 4:13 PM, Douglas Brebner wrote:
> Weird, I was looking into binary parsing tools only yesterday.
>
> Thanks for this :)

You're welcome! If you try it out and have any feedback I'd be keen to
hear it.

Cheers,
  Tony