HiPhish
2018-09-19 12:33:22 UTC
Hello Schemers,
I am pleased to announce to the public a project I have been working on for a
while: an implementation of the MessagePack[1] data serialization format for
GNU Guile.
https://gitlab.com/HiPhish/guile-msgpack
## What is MessagePack ##
MessagePack is a specification for how to turn data into byte and vice-versa.
Think of it like JSON, except instead of human readability it stresses speed
and size efficiency. The format is binary and well suited for data exchange
between processes. It also forms the basis of the MessagePack RPC protocol[2].
## About the Guile implementation ##
My implementation is written in pure Guile Scheme, so it should work out of
the box. You can try it out without installing anything. Just clone the repo
and give it a try:
$ guile -L .
scheme@(guile-user)> ,use (msgpack)
scheme@(guile-user)> (pack "hello" 1337 #t)
$1 = #vu8(165 104 101 108 108 111 205 5 57 195)
As you can see, the three objects passed to the `pack` procedure have been
turned into one big bytevector. We could now unpack this bytevector again,
write it to a file, or send if off to a port. Since using MessagePack with
ports is a frequent task there is also a `pack!` procedure which takes in a
port to pack to as well.
(define hodgepodge (vector 1 2 '#(3 #t) "foo"))
(pack! hodgepodge (current-output-port))
To get our object back we `unpack` it:
(unpack #vu8(#xA5 #x68 #x65 #x6C #x6C #x6F)) ; Returns "hello"
(unpack! (current-input-port))
The readme goes into more detail and the (Texinfo) manual has the complete
documentation. Building it is simple enough with the included makefile.
## What's next? ##
Next is your feedback! Once the library has settled down I would like to make
it into a Guix package. From there I can then start building a MessagePack RPC
implementation and finally a Neovim client which will allow people to write
plugins for Neovim in GNU Guile. (yes, Vim plugins written in Lisp, who would
have thought?)
## Help needed ##
This is my first time making a full project in Guile, so I would appreciate it
if someone with more experience could look over my code. I have written down
some things I could think of in the todo file. In particular I would like to
know:
How much is portability a concern? I know Guile implements *some* or r6rs, but
I wasn't paying much attention to that. Is it something worth considering or
should I just treat Guile as its own language that just so happens to be based
on Scheme?
The extension type `ext` (msgpack/ext.scm) is a pair of a signed 8-bit integer
and a bytevector. The constructor does not enforce this condition, the two
slots can be really anything. What it the proper way of enforcing this in
Guile? I know Common Lisp has type declarations and Racket has contracts, but
what does Guile have?
The `pack` procedure takes any number of objects and packs them into a large
bytevector. However, the `unpack` procedure only returns the first object it
unpacks. Is there a way of making it unpack as many as it can? I thought of
`values`, but you would need to know the number of values in advance. Also the
caller would have to know in advance how many objects he is going to get
unpacked.
As I said, there is more in the todo file, but the other questions are under
the hood, not user-visible.
## The inevitable panhandling ##
I don't want to go into this too much, because no one likes to read it, but if
you like my MessagePack implementation I would really appreciate if you could
spare some cash. Links are in the readme; at the moment I only have Liberapay
set up, if anyone can recommend me a service for one-time donations that would
be cool. All the services I could find were about fundraising for charity and
stuff, not what I was looking for.
_______________________________________________________________________________
[1] https://msgpack.org/
[2] https://github.com/msgpack-rpc/msgpack-rpc
I am pleased to announce to the public a project I have been working on for a
while: an implementation of the MessagePack[1] data serialization format for
GNU Guile.
https://gitlab.com/HiPhish/guile-msgpack
## What is MessagePack ##
MessagePack is a specification for how to turn data into byte and vice-versa.
Think of it like JSON, except instead of human readability it stresses speed
and size efficiency. The format is binary and well suited for data exchange
between processes. It also forms the basis of the MessagePack RPC protocol[2].
## About the Guile implementation ##
My implementation is written in pure Guile Scheme, so it should work out of
the box. You can try it out without installing anything. Just clone the repo
and give it a try:
$ guile -L .
scheme@(guile-user)> ,use (msgpack)
scheme@(guile-user)> (pack "hello" 1337 #t)
$1 = #vu8(165 104 101 108 108 111 205 5 57 195)
As you can see, the three objects passed to the `pack` procedure have been
turned into one big bytevector. We could now unpack this bytevector again,
write it to a file, or send if off to a port. Since using MessagePack with
ports is a frequent task there is also a `pack!` procedure which takes in a
port to pack to as well.
(define hodgepodge (vector 1 2 '#(3 #t) "foo"))
(pack! hodgepodge (current-output-port))
To get our object back we `unpack` it:
(unpack #vu8(#xA5 #x68 #x65 #x6C #x6C #x6F)) ; Returns "hello"
(unpack! (current-input-port))
The readme goes into more detail and the (Texinfo) manual has the complete
documentation. Building it is simple enough with the included makefile.
## What's next? ##
Next is your feedback! Once the library has settled down I would like to make
it into a Guix package. From there I can then start building a MessagePack RPC
implementation and finally a Neovim client which will allow people to write
plugins for Neovim in GNU Guile. (yes, Vim plugins written in Lisp, who would
have thought?)
## Help needed ##
This is my first time making a full project in Guile, so I would appreciate it
if someone with more experience could look over my code. I have written down
some things I could think of in the todo file. In particular I would like to
know:
How much is portability a concern? I know Guile implements *some* or r6rs, but
I wasn't paying much attention to that. Is it something worth considering or
should I just treat Guile as its own language that just so happens to be based
on Scheme?
The extension type `ext` (msgpack/ext.scm) is a pair of a signed 8-bit integer
and a bytevector. The constructor does not enforce this condition, the two
slots can be really anything. What it the proper way of enforcing this in
Guile? I know Common Lisp has type declarations and Racket has contracts, but
what does Guile have?
The `pack` procedure takes any number of objects and packs them into a large
bytevector. However, the `unpack` procedure only returns the first object it
unpacks. Is there a way of making it unpack as many as it can? I thought of
`values`, but you would need to know the number of values in advance. Also the
caller would have to know in advance how many objects he is going to get
unpacked.
As I said, there is more in the todo file, but the other questions are under
the hood, not user-visible.
## The inevitable panhandling ##
I don't want to go into this too much, because no one likes to read it, but if
you like my MessagePack implementation I would really appreciate if you could
spare some cash. Links are in the readme; at the moment I only have Liberapay
set up, if anyone can recommend me a service for one-time donations that would
be cool. All the services I could find were about fundraising for charity and
stuff, not what I was looking for.
_______________________________________________________________________________
[1] https://msgpack.org/
[2] https://github.com/msgpack-rpc/msgpack-rpc