Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/tonyg/racket-bitsyntax

Erlang-style binaries/bitstrings for Racket
https://github.com/tonyg/racket-bitsyntax

binary-data parsing racket

Last synced: about 1 month ago
JSON representation

Erlang-style binaries/bitstrings for Racket

Awesome Lists containing this project

README

        

# racket-bitsyntax

Adds library support for slices and splices of byte-vectors to Racket,
and adds syntax for pattern-matching such bit-strings, inspired by
Erlang's binary pattern-matching:

-
-

## Documentation

A rendered version of the documentation for this library is available
via Github Pages:

-

## Example

Here's a Racket equivalent of the example given in the Erlang documentation:

(define IP-VERSION 4)
(define IP-MINIMUM-HEADER-LENGTH 5)
(bit-string-case datagram
([ (= IP-VERSION :: bits 4)
(header-length :: bits 4)
service-type
(total-length :: bits 16)
(id :: bits 16)
(flags :: bits 3)
(fragment-offset :: bits 13)
ttl
protocol
(header-checksum :: bits 16)
(source-ip :: bits 32)
(destination-ip :: bits 32)
(rest :: binary) ]
(when (and (>= header-length 5)
(>= (bit-string-length datagram) (* header-length 4))))
(let ((options-length (* 4 (- header-length IP-MINIMUM-HEADER-LENGTH))))
(bit-string-case rest
([ (opts :: binary bytes options-length)
(data :: binary) ]
'datagram-valid))))
[else
'datagram-not-valid])

## Licence

Copyright © 2011–2017 Tony Garnock-Jones

This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Lesser General Public License for more details.

You should have received a copy of the GNU Lesser General Public License
along with this program. If not, see .