Wednesday, July 23, 2008

70 61 63 6b

I posted earlier about creating the new opentick package. Since it requires reading/writing binary data to a socket connection, I wrote some utility functions to made the conversion to/from raw data easier.

These functions are tangential to opentick and potentially useful to others, so I created yet another package... called pack. pack attempts to replicate the functionality of PERL's pack and unpack functions.

The functions are probably best illustrated via an example:

> computer <- pack('C A3 v x V a*', 3, 'foo', 21, 50000, 'bar')
> computer
[1] 03 66 6f 6f 15 00 00 50 c3 00 00 62 61 72
> human <- unpack('C/A v x V A3', computer)
> human
[[1]]
[1] "foo"

[[2]]
[1] 21

[[3]]
[1] 50000

[[4]]
[1] "bar"

>
(For those curious, the post title is pack in hexadecimal... sorry, but I find it amusing.)

No comments: