David pointed out that I failed to do a reply all when I pointed him to the
packed-binary package on PLaneT that does what he wants. Here is the text
of that post in case anyone else ever needs it.
I have a packed-binary package on PLaneT that we use for for reading binary
data based on a similar capability in Python. It can read or write from
byte strings or directly to/from binary files. It uses format strings to
define the data types to read:
unsigned long long
and for byte order, size, and alignment:
Size and Alignment
network (big endian)
The documentation is at https://planet.racket-lang.
And the PLaneT entry is at https://planet.racket-lang.
On Mon, Oct 17, 2016 at 6:38 PM, David Storrs <david.sto...@gmail.com>
> What is the best way to write binary data such that I have control of the
> representation? Basically, I want the Racket equivalent of the Perl 'pack
> <http://perldoc.perl.org/functions/pack.html>' and 'unpack
> functions, where I can do: pack('C', 202) and get back a one-byte binary
> representation of the decimal number 202 (or pack('s', 202) to get a 2-byte
> version) that I could then write to a port.
> The reason that I'm looking for this is that I'm going to be writing
> binary data across the network and I want to be able to control the
> representation. For a fairly trivial example, I want to be able to decide
> how many bytes the number 202 should take up. Furthermore, I'd like to
> have an easy way to do quick and dirty testing; I thought that writing to a
> byte string would be that way, but I'm not having much success with it, as
> I haven't figured out how to make things go in as raw bytes instead of
> I've looked at fasl, binary-class, the implementation of protobuf, and
> everything in the racket-lang docs that I could think of keywords for, with
> no luck. This feels like it should be a straightforward task, so I'm
> frustrated with myself for not figuring it out more quickly.
>  I keep using the number 202 because that's the size of one particular
> message that I'm using in my text script and I'm trying to do RLE on it.
> You received this message because you are subscribed to the Google Groups
> "Racket Users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to racket-users+unsubscr...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.
You received this message because you are subscribed to the Google Groups
"Racket Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email
For more options, visit https://groups.google.com/d/optout.