Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100644 87 lines (62 sloc) 2.584 kB
227b208 @ngerakines Misc cleanup. Updating README. Starting to add stub docs.
ngerakines authored
1 # README
5f0c883 @ngerakines Initial commit
ngerakines authored
2
227b208 @ngerakines Misc cleanup. Updating README. Starting to add stub docs.
ngerakines authored
3 This module is a composite of other open source modules and original code to
4 make interfacing with the Protocol Buffers protocol easy.
5f0c883 @ngerakines Initial commit
ngerakines authored
5
6 ## Encode / Decode
7
8 Encoding is simple.
9
19ff6ed adding quickcheck code
Jacob Vorreuter authored
10 1> protobuffs:encode(1, 1, uint32).
5f0c883 @ngerakines Initial commit
ngerakines authored
11 <<8,1>>
227b208 @ngerakines Misc cleanup. Updating README. Starting to add stub docs.
ngerakines authored
12 2> erlang:iolist_to_binary([
13 protobuffs:encode(1, <<"Nick">>, string),
14 protobuffs:encode(2, 25, uint32)
15 ]).
5f0c883 @ngerakines Initial commit
ngerakines authored
16 <<10,4,78,105,99,107,16,25>>
17
18 Decoding is simple too.
19
20 1> protobuffs:decode(<<8, 1>>, uint32).
21 {{1, 1}, <<>>}
22 2> protobuffs:decode(<<10,4,78,105,99,107,16,25>>, bytes).
23 {{1, <<"Nick">>}, <<16,25>>}
24 3> protobuffs:decode(<<16,25>>, bytes).
25 {{2, 25}, <<>>}
26
27 ## Using .proto Files
28
227b208 @ngerakines Misc cleanup. Updating README. Starting to add stub docs.
ngerakines authored
29 The main objective of this module is to allow developers to use .proto files
30 easily. This module provides very basic functionality to do so.
5f0c883 @ngerakines Initial commit
ngerakines authored
31
32 Consider the `t/simple.proto` file.
33
34 message Person {
35 required string name = 1;
36 required string address = 2;
37 required string phone_number = 3;
38 required int32 age = 4;
39 }
40
227b208 @ngerakines Misc cleanup. Updating README. Starting to add stub docs.
ngerakines authored
41 From that file we can create an Erlang module that can encode and decode the
42 Person message into records.
5f0c883 @ngerakines Initial commit
ngerakines authored
43
44 1> protobuffs_compile:scan_file("simple.proto").
45 ok
227b208 @ngerakines Misc cleanup. Updating README. Starting to add stub docs.
ngerakines authored
46 2> simple_pb:decode_person(<<10,4,78,105,99,107,18,13,77,111,...>>).
5f0c883 @ngerakines Initial commit
ngerakines authored
47 {person,<<"Nick">>,<<"Mountain View">>, <<"+1 (000) 555-1234">>,25}
227b208 @ngerakines Misc cleanup. Updating README. Starting to add stub docs.
ngerakines authored
48 3> simple_pb:encode_person({person, <<"Nick">>, <<"Mountain View">>,
49 <<"+1 (000) 555-1234">>,25}).
50 <<10,4,78,105,99,107,18,13,77,111,117,110,116,97,105,110,32,86,105,...>>
5f0c883 @ngerakines Initial commit
ngerakines authored
51
227b208 @ngerakines Misc cleanup. Updating README. Starting to add stub docs.
ngerakines authored
52 How cool is that? From .proto files, we create modules that export encode and
53 decode functions for the messages defined.
5f0c883 @ngerakines Initial commit
ngerakines authored
54
55 ## CAVEATS
56
227b208 @ngerakines Misc cleanup. Updating README. Starting to add stub docs.
ngerakines authored
57 Support for parsing proto files and creating code from it is volatile and
8b491ba @freke Updated test, updated README
freke authored
58 should be considered alpha software at best. Please do not use this in production.
5f0c883 @ngerakines Initial commit
ngerakines authored
59
c39901e removing no_debug_info
Jacob Vorreuter authored
60 ## no_debug_info
61
62 The protobuffs_compile module relies on the pokemon_pb module being compiled
63 with debug info. This is because pokemon_pb serves as a template for generated
64 _pb modules. Running protobuffs_compile:scan_file/1 reads the erlang forms from
65 the pokemon_pb.beam file and expands and alters those forms to create the generated
66 module.
67
0501b69 @freke Updated README
freke authored
68 ## Building with rebar
69 To compile
70 %>./rebar compile
c5ab9b2 @freke source generation is back
freke authored
71
0501b69 @freke Updated README
freke authored
72 To run all tests
73 %>./rebar eunit
74 %>./rebar ct
c5ab9b2 @freke source generation is back
freke authored
75
0501b69 @freke Updated README
freke authored
76 Se rebar doc for more information.
9505808 @freke Improved Rake and restructured
freke authored
77
5f0c883 @ngerakines Initial commit
ngerakines authored
78 ## CREDITS
79
80 Some of the protobuffs.erl module came from code written by Brian Buchanan.
81
227b208 @ngerakines Misc cleanup. Updating README. Starting to add stub docs.
ngerakines authored
82 Some of the protobuffs\_compile.erl module came from code written by Tim
83 Fletcher.
5f0c883 @ngerakines Initial commit
ngerakines authored
84
227b208 @ngerakines Misc cleanup. Updating README. Starting to add stub docs.
ngerakines authored
85 The rest of it and it's test suite was written by Nick Gerakines. Major
86 contributions have been made by Jacob Vorreuter.
Something went wrong with that request. Please try again.