[Top][All Lists]

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

[Chicken-announce] Protocol Buffers for CHICKEN

From: Thomas Chust
Subject: [Chicken-announce] Protocol Buffers for CHICKEN
Date: Wed, 29 May 2013 00:15:20 +0200
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:17.0) Gecko/20130510 Thunderbird/17.0.6


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

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 :-)



When C++ is your hammer, every problem looks like your thumb.

reply via email to

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