Skip to content

Installation

This page covers installing the schema compilers and generating language bindings from the schemas.

Prerequisites

You need at least one of the three schema compilers installed. Install only the ones you plan to use.

Cap'n Proto

brew install capnp
sudo apt-get install capnproto libcapnp-dev
curl -O https://capnproto.org/capnproto-c++-1.0.2.tar.gz
tar zxf capnproto-c++-1.0.2.tar.gz
cd capnproto-c++-1.0.2
./configure && make -j$(nproc) && sudo make install

FlatBuffers

brew install flatbuffers
sudo apt-get install flatbuffers-compiler
git clone https://github.com/google/flatbuffers.git
cd flatbuffers && cmake -G "Unix Makefiles" && make && sudo make install

Protocol Buffers

brew install protobuf
sudo apt-get install protobuf-compiler libprotobuf-dev

Generating code

Clone the repository and use the Makefile:

git clone https://github.com/tipatterson-dev/SWECommonBinaryEncodings.git
cd SWECommonBinaryEncodings

Build all three at once:

make all

Or build individually:

make capnproto     # → gen/capnproto/
make flatbuffers   # → gen/flatbuffers/
make protobuf      # → gen/protobuf/

Generated code is written to gen/<format>/.

Choosing a target language

The Makefile defaults to C++. Override with variables:

# Cap'n Proto — Java
make capnproto CAPNP_LANG=java

# FlatBuffers — Python
make flatbuffers FLATC_LANG=python

# Protocol Buffers — Go
make protobuf PROTO_LANG=go

Direct compiler invocation

If you prefer not to use the Makefile:

capnp compile -oc++:gen/capnproto --src-prefix=capnproto capnproto/sweCommon3.capnp
flatc --cpp -o gen/flatbuffers flatbuffers/sweCommon3.fbs
protoc --cpp_out=gen/protobuf --proto_path=protobuf protobuf/sweCommon3.proto

Cleaning generated files

make clean    # removes the entire gen/ directory