Piqi is a multi-format data serialization system for OCaml. It provides a
uniform interface for serializing OCaml data structures to JSON, XML and
Protocol Buffers formats.
A typical Piqi usage scenario involves the following steps:
1. Install piqi-ocaml -- see installation instructions below.
2. Describe data structures using the Piqi data definition language or
The Piqi data definition language can describe many
OCaml types, both primitive and user-defined. This includes integers, floats,
booleans, strings, binaries, lists, records and polymorphic variants.
.piqi modules can be converted to and from Protocol Buffers
piqi to-proto X.piqi piqi of-proto X.proto
3. Call the Piqi compiler (piqic-ocaml) to generate OCaml type definitions and
4. Use generated serializes/deserializers in a user's program -- the desired
serialization format can be specified at runtime. For
% deserialize a data structure from Protocol Buffers let buf = Piqirun.init_from_string bytes in let addressbook = Addressbook_piqi.parse_address_book buf in ... % serialize it as JSON let json = Addressbook_piqi_ext.gen_address_book addressbook `json in ... % serialize it as pretty-printed JSON let json_pretty = Addressbook_piqi_ext.gen_address_book addressbook `json_pretty in ... % serialize it as XML let xml = Addressbook_piqi_ext.gen_address_book addressbook `xml in ...
Installing using OPAM
In order to install Piqi using OPAM, run the
opam install piqi
This command will install the latest stable version of Piqi that includes
piqic-ocaml executables and runtime libraries for OCaml.
To install the latest development version of Piqi, use opam pinning.
opam pin add -n --dev-repo piqilib opam pin add -n --dev-repo piqi opam install piqi
Installing from source code
Download and install piqi and piqilib
Follow general build and installation instructions from the INSTALL file.
After that, build and install the
piqilib OCaml library by running
make ocaml make ocaml-install
Build and install
make make install
Piqi OCaml documentation is available at http://piqi.org/doc/ocaml/
The master copy is located in this repository:
Please report found problems using GitHub
Your contributions are always welcome. Just open a pull request. Check TODO
list for ideas.
Some useful commands: