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!
In theory anything can be packed as long as you can agree on *how* it should be
packed. For example, if you have a point '(struct point (x y))', how should
that be packed? There is no "point" type in MessagePack and no direct
correspondance, so you would have to tell the recipient of your data "a point
looks like this: ...". You could use the MessagePack 'ext' type, it consist of
an 8-bit integer as a type tag and raw binary data, so you could agree with the
recipient that the tag '13' stands for point and the data is two big-endian
64-bit numbers in the order 'x' and 'y'. Or you could pack a transparent struct
as a string that you can 'read' and 'write' in Racket.
For hash tables there is the map type and for vectors and lists there is the
array type, so those are direct 1:1 correspondences. The elements of these are
themselves individually packed, so if you have a list of hash tables that
structure will be preserved.
I think adding the ability to define your own packing functions as additions to
the library is something that's worth looking into later. Then you could define
your own 'pack-point' and add it to the generic 'pack' function.
--
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.