On Tuesday, July 25, 2017 at 11:37:48 PM UTC+2, Lehi Toskin wrote:
> One thing I'm curious about is what things can you and can you not pack? In
> the README it shows bytes being packed, which seems a little obvious, but
> what about (transparent) structs? Hashes? Lists? I'm very interested in this
> package... for science!
I am not packing bytes in the readme, I am packing an integer in hexadecimal
notation so one can see easier how the integer corresponds to the packed bytes:
#x1234 becomes #xCD #x12 #x34, the first byte is the type tag for unsigned
16-bit integers and the other two are the bytes of the integer.
Packing means turning a Racket object into a byte sequence that can be sent to
another process. The recipient might not know anything about Racket, but it
still needs to be able to figure out how to put the byte sequence back
that's why there is a type tag.
In theory you can pack anything as long as the recipient knows how it was
packed. Vectors and lists get packed into MessagePack arrays, hash tables into
MessagePack maps. If you want to pack a custom type like a point struct
'(struct point (x y))' you have a number of options. You could use the
MessagePack ext type which allows you to assign a custom type tag, then you
have to tell the recipient that for example the magic number 13 means point. If
the struct is transparent and you can 'read' and 'write' it in Racket you could
also pack the point as a string, but then you somehow have to make sure the
recipient knows that the string is meant to be an object and not just some
I think it would be worthwhile to later add the ability to define your own
packing functions so that you could then just call '(pack my-point out)'.
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.