[squeak-dev] BitSyntax for Squeak

Tony Garnock-Jones tonyg at leastfixedpoint.com
Wed Oct 7 08:30:07 UTC 2020


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


More information about the Squeak-dev mailing list