Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
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
- Host: GitHub
- URL: https://github.com/tonyg/racket-bitsyntax
- Owner: tonyg
- License: other
- Created: 2011-06-28T04:42:09.000Z (over 13 years ago)
- Default Branch: master
- Last Pushed: 2021-05-12T14:38:22.000Z (over 3 years ago)
- Last Synced: 2024-10-15T03:02:20.759Z (about 1 month ago)
- Topics: binary-data, parsing, racket
- Language: Racket
- Homepage:
- Size: 1.02 MB
- Stars: 33
- Watchers: 4
- Forks: 3
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- License: COPYING_LESSER.txt
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 .