This repository has been archived by the owner. It is now read-only.
Find file
Fetching contributors…
Cannot retrieve contributors at this time
105 lines (70 sloc) 2.7 KB


This module is a composite of other open source modules and original code to make interfacing with the Protocol Buffers protocol easy.

Encode / Decode

Encoding is simple.

1> protobuffs:encode(1, 1, uint32).
2> erlang:iolist_to_binary([
    protobuffs:encode(1, <<"Nick">>, string),
    protobuffs:encode(2, 25, uint32)

Decoding is simple too.

1> protobuffs:decode(<<8, 1>>, uint32).
{{1, 1}, <<>>}
2> protobuffs:decode(<<10,4,78,105,99,107,16,25>>, bytes).
{{1, <<"Nick">>}, <<16,25>>}
3> protobuffs:decode(<<16,25>>, bytes).
{{2, 25}, <<>>}

Using .proto Files

The main objective of this module is to allow developers to use .proto files easily. This module provides very basic functionality to do so.

Consider the t/simple.proto file.

message Person {
	required string name = 1;
	required string address = 2;
	required string phone_number = 3;
	required int32 age = 4;

From that file we can create an Erlang module that can encode and decode the Person message into records.

1> protobuffs_compile:scan_file("simple.proto").
2> simple_pb:decode_person(<<10,4,78,105,99,107,18,13,77,111,...>>).
{person,<<"Nick">>,<<"Mountain View">>, <<"+1 (000) 555-1234">>,25}
3> simple_pb:encode_person({person, <<"Nick">>, <<"Mountain View">>,
    <<"+1 (000) 555-1234">>,25}).

How cool is that? From .proto files, we create modules that export encode and decode functions for the messages defined.


It't also posible to create a escript "bin/protoc-erl" this self contained script generates a source code (.erl) file and a header (.hrl) file.

 &>./protoc-erl path_to_proto_file


The protobuffs_compile module relies on the pokemon_pb module being compiled with debug info. This is because pokemon_pb serves as a template for generated _pb modules. Running protobuffs_compile:scan_file/1 reads the erlang forms from the pokemon_pb.beam file and expands and alters those forms to create the generated module.

Building with rebar

To compile

&>./rebar compile

To run all tests

&>./rebar eunit

&>./rebar ct

Se rebar doc for more information.

A simple makefile is also included


&>make test

&>make eunit

&>make ct

&>make escriptize


Some of the protobuffs.erl module came from code written by Brian Buchanan.

Some of the protobuffs_compile.erl module came from code written by Tim Fletcher.

Original written by Nick Gerakines. Major contributions have been made by Jacob Vorreuter.

Leex/Yecc parser, and most of the test cases by David Åberg