Hello,
during the CHICKEN spring thing in Cologne I started to work on a new
egg [1] implementing the protocol buffer [2] serialization format, which
is now in a usable and tested state.
If you don't need or want to use a specific schema for your data, you
can use the protobuf egg as a generic serialization solution that
produces platform-independent binary representations of (almost) any
CHICKEN values:
$ cat source.scm
(require-library protobuf)
(import protobuf-generic)
(serialize (lambda (x) (print (* 2 x))))
$ csi -s source.scm >lambda.pbf
$ cat sink.scm
(require-library protobuf)
(import protobuf-generic)
((deserialize) 42)
$ csi -s sink.scm <lambda.pbf
84
The serialized data can be read by other protocol buffer enabled
applications, it may not have the most convenient structure, though.
So if you have a need to communicate with other software that uses
protocol buffer definitions, you can use the protoc compiler plugin that
comes with this egg to generate a CHICKEN binding automatically from
existing schema definitions:
$ cat person.proto
package person;
message Person {
required int32 id = 1;
required string name = 2;
optional string email = 3;
}
$ protoc --proto_path=. --chicken_out=. person.proto
$ cat test.scm
(require-library protobuf)
(include "person.scm")
(import protobuf person)
(serialize (make-person id: 42 name: "Jane Doe"))
$ csi -s test.scm | \
> protoc --proto_path=. person.proto --decode=person.Person
id: 42
name: "Jane Doe"
Deserialization is just as simple with a call to (deserialize person).
The protobuf messages are represented as SRFI-99 records in CHICKEN that
can be manipulated as usual. Enumeration values are represented as symbols.
If you're interested, check the egg documentation for advanced features
and give the library a try :-)
Ciao,
Thomas
--
[1] https://wiki.call-cc.org/eggref/4/protobuf
[2] http://protobuf.googlecode.com/