chicken-users
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Chicken-users] Protocol Buffers for CHICKEN


From: Dan Leslie
Subject: Re: [Chicken-users] Protocol Buffers for CHICKEN
Date: Tue, 28 May 2013 15:32:20 -0700
User-agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:17.0) Gecko/20130107 Thunderbird/17.0.2

This is very welcome!

I wonder if this would be useful for storing data in a posix shared memory block...

-Dan

On 5/28/2013 3:15 PM, Thomas Chust wrote:
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/






reply via email to

[Prev in Thread] Current Thread [Next in Thread]