[racket] Low level manipulation on numbers
Or the packed-binary package on PLaneT (
http://planet.racket-lang.org/display.ss?package=packed-binary.plt&owner=williams)
that is useful for reading binary formatted files. From the package
description:
Performs conversions between Racket values and C structs represented as byte
strings. It also provides read and write routines to perform these
conversions directly to/from binary files. It uses format strings as compact
descriptions of the layout of the C structs and the intended conversion
to/from Racket values. This can be used in handling binary data stored in
files or from network connections, among other sources.
Doug
On Tue, Oct 11, 2011 at 8:46 AM, Tony Garnock-Jones <tonyg at ccs.neu.edu>wrote:
> Hi Nicolas,
>
> On 2011-10-08 12:41 PM, nicolas.oury at gmail.com wrote:
> > I am trying to write a small implementation of Protocol Buffers
> > ( http://code.google.com/p/protobuf/ ) and I have difficulties
> > with bit manipulations, especially to transform a negative integer into
> > a series of bytes and back.
>
> You might also be interested to try out (require (planet
> tonyg/bitsyntax)). The documentation is at
>
> http://planet.racket-lang.org/package-source/tonyg/bitsyntax.plt/3/2/planet-docs/manual/index.html
>
> If, for example, you wanted to parse a little-endian 32-bit length
> prefixed blob from a packet, you might write
>
> (bit-string-case packet
> ([ (len :: little-endian integer bits 32)
> (body :: binary bytes len) ]
> body))
>
> The library supports arbitrary-width integers, and 32- or 64-bit floats.
> It uses the primitives that Matthew mentioned internally.
>
> Regards,
> Tony
> _________________________________________________
> For list-related administrative tasks:
> http://lists.racket-lang.org/listinfo/users
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.racket-lang.org/users/archive/attachments/20111011/edb3322d/attachment.html>