Permalink
Browse files

Merge branch 'master' of https://github.com/freke/erlang_protobuffs i…

…nto az2-merge-protobuffs-with-upstream

Conflicts:
	Makefile
	rebar
	src/protobuffs_parser.erl
	support/include.mk
	t/Makefile
	t/hasdefault.proto
	t/protobuffs_t_001.t
	t/protobuffs_t_002.t
	t/protobuffs_t_003.t
	t/protobuffs_t_005.t
	t/protobuffs_t_006.t
	t/protobuffs_t_007.t
	t/protobuffs_t_008.t
  • Loading branch information...
2 parents 84bd7e2 + 10f46ae commit 47476c1d790afc5d1fcc1b1009ff64df6512109c @Vagabond Vagabond committed Apr 4, 2011
Showing with 2,224 additions and 1,053 deletions.
  1. +8 −1 .gitignore
  2. +3 −0 AUTHORS
  3. +13 −0 ChangeLog
  4. +11 −3 README.markdown
  5. +10 −0 bin/protoc-erl
  6. +0 −18 ebin/protobuffs.app
  7. BIN rebar
  8. +3 −1 rebar.config
  9. +0 −9 src/Makefile
  10. +39 −10 src/pokemon_pb.erl
  11. +8 −0 src/protobuffs.app.src
  12. +192 −18 src/protobuffs.erl
  13. +481 −94 src/protobuffs_compile.erl
  14. +0 −247 src/protobuffs_parser.erl
  15. +69 −0 src/protobuffs_parser.yrl
  16. +31 −0 src/protobuffs_scanner.xrl
  17. +0 −43 support/include.mk
  18. +0 −12 t/Makefile
  19. +0 −40 t/empty.proto
  20. +0 −13 t/hasdefault.proto
  21. +0 −276 t/protobuffs_eqc.erl
  22. +0 −15 t/protobuffs_t_001.t
  23. +0 −10 t/protobuffs_t_002.t
  24. +0 −42 t/protobuffs_t_003.t
  25. +0 −27 t/protobuffs_t_005.t
  26. +0 −45 t/protobuffs_t_006.t
  27. +0 −73 t/protobuffs_t_007.t
  28. +0 −33 t/protobuffs_t_008.t
  29. +0 −22 t/protobuffs_t_009.t
  30. +346 −0 test/erlang_protobuffs_SUITE.erl
  31. +1 −0 test/erlang_protobuffs_SUITE_data/.gitignore
  32. +34 −0 test/erlang_protobuffs_SUITE_data/addressbook.proto
  33. +4 −0 test/erlang_protobuffs_SUITE_data/boolean.proto
  34. +17 −0 test/erlang_protobuffs_SUITE_data/empty.proto
  35. +8 −0 test/erlang_protobuffs_SUITE_data/enum.proto
  36. +8 −0 test/erlang_protobuffs_SUITE_data/enum_outside.proto
  37. +5 −0 test/erlang_protobuffs_SUITE_data/extend.proto
  38. +5 −0 test/erlang_protobuffs_SUITE_data/extend_in_reserved_range.proto
  39. +5 −0 test/erlang_protobuffs_SUITE_data/extend_out_of_range.proto
  40. +7 −0 test/erlang_protobuffs_SUITE_data/extensions.proto
  41. +18 −0 test/erlang_protobuffs_SUITE_data/hasdefault.proto
  42. +5 −0 test/erlang_protobuffs_SUITE_data/import.proto
  43. +3 −0 test/erlang_protobuffs_SUITE_data/import_target.proto
  44. +18 −0 test/erlang_protobuffs_SUITE_data/nested1.proto
  45. +19 −0 test/erlang_protobuffs_SUITE_data/nested2.proto
  46. +15 −0 test/erlang_protobuffs_SUITE_data/nested3.proto
  47. +15 −0 test/erlang_protobuffs_SUITE_data/nested4.proto
  48. +9 −0 test/erlang_protobuffs_SUITE_data/nested5.proto
  49. +16 −0 test/erlang_protobuffs_SUITE_data/packed_repeated.proto
  50. +1 −0 {t → test/erlang_protobuffs_SUITE_data}/repeater.proto
  51. +11 −0 test/erlang_protobuffs_SUITE_data/service.proto
  52. +2 −1 {t → test/erlang_protobuffs_SUITE_data}/simple.proto
  53. +3 −0 test/erlang_protobuffs_SUITE_data/single.proto
  54. +66 −0 test/erlang_protobuffs_SUITE_data/special_words.proto
  55. +378 −0 test/protobuffs_eqc.erl
  56. +67 −0 test/protobuffs_parser_tests.erl
  57. +270 −0 test/protobuffs_tests.erl
View
@@ -1,3 +1,10 @@
ebin
*.beam
-*~
+*.gz
+*~
+doc
+logs
+.eunit
+.directory
+src/protobuffs_parser.erl
+src/protobuffs_scanner.erl
View
@@ -0,0 +1,3 @@
+Nick Gerakines
+Jacob Vorreuter
+erlrc integration by Cliff Moon
View
@@ -0,0 +1,13 @@
+* Thu Dec 03 2009 Anthony Molinaro <anthony.molinaro@openx.org> 0.0.1
+- Fixed path for unit tests
+- Have .gitignore ignore all generated files
+- Fixed bool type, they were being improperly left as 0 and 1 instead of using
+ the true and false atoms
+- Nested types should now work according to spec (as much as there is one)
+- Fixed bool defaults, they were being improperly scanned, so falling back to
+ keywords
+* freke <davabe@hotmail.com>
+- Fixed enum support
+- Changed build system to Rake
+- Added QuickCheck tests
+- Changed so parsing of proto files is done by leex and yecc
View
@@ -55,9 +55,7 @@ decode functions for the messages defined.
## CAVEATS
Support for parsing proto files and creating code from it is volatile and
-should be considered alpha software at best. It currently only supports flat
-messages, simple types (ints, strings, etc) and will break on ENUM types and
-any sort of nesting. Please do not use this in production.
+should be considered alpha software at best. Please do not use this in production.
## no_debug_info
@@ -67,6 +65,16 @@ _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.
+
## CREDITS
Some of the protobuffs.erl module came from code written by Brian Buchanan.
View
@@ -0,0 +1,10 @@
+#!/usr/bin/env escript
+%% -*- erlang -*-
+%%! -sasl errlog_type error -boot start_sasl -noshell
+
+main ([File]) ->
+ protobuffs_compile:generate_source (File);
+main (_) ->
+ io:format ("usage: ~s <protofile>~n",
+ [filename:basename (escript:script_name())]),
+ halt (1).
View
@@ -1,18 +0,0 @@
-{application, protobuffs,
- [
- {description, "Google protobuffs implementation for Erlang."},
- {vsn, "0.5.0"},
- {modules, [
- pokemon_pb,
- protobuffs,
- protobuffs_compile,
- protobuffs_parser
- ]},
- {registered, []},
- {applications, [
- kernel,
- stdlib,
- sasl,
- crypto
- ]}
-]}.
View
BIN rebar
Binary file not shown.
View
@@ -1 +1,3 @@
-{erl_opts, [debug_info]}.
+{erl_opts, [debug_info]}.
+
+{clean_files, ["*~","**/*~"]}.
View
@@ -1,9 +0,0 @@
-include ../support/include.mk
-
-all: $(EBIN_FILES)
-
-debug:
- $(MAKE) DEBUG=-DDEBUG
-
-clean:
- rm -rf $(EBIN_FILES) erl_crash.dump
View
@@ -24,10 +24,13 @@
%% OTHER DEALINGS IN THE SOFTWARE.
-module(pokemon_pb).
-export([encode_pikachu/1, decode_pikachu/1]).
--compile([export_all]).
+-export([encode/1]).
-record(pikachu, {abc, def}).
%% ENCODE
+encode(Record) ->
+ encode(element(1, Record), Record).
+
encode_pikachu(Record) when is_record(Record, pikachu) ->
encode(pikachu, Record).
@@ -44,6 +47,9 @@ with_default(Val, _) -> Val.
pack(_, optional, undefined, _, _) -> [];
pack(_, repeated, undefined, _, _) -> [];
+
+pack(_, repeated_packed, undefined, _, _) -> [];
+pack(_, repeated_packed, [], _, _) -> [];
pack(FNum, required, undefined, Type, _) ->
exit({error, {required_field_is_undefined, FNum, Type}});
@@ -54,12 +60,28 @@ pack(_, repeated, [], _, Acc) ->
pack(FNum, repeated, [Head|Tail], Type, Acc) ->
pack(FNum, repeated, Tail, Type, [pack(FNum, optional, Head, Type, [])|Acc]);
+pack(FNum, repeated_packed, Data, Type, _) ->
+ protobuffs:encode_packed(FNum, Data, Type);
+
pack(FNum, _, Data, _, _) when is_tuple(Data) ->
[RecName|_] = tuple_to_list(Data),
protobuffs:encode(FNum, encode(RecName, Data), bytes);
-pack(FNum, _, Data, Type, _) ->
- protobuffs:encode(FNum, Data, Type).
+pack(FNum, _, Data, Type, _) when Type=:=bool;Type=:=int32;Type=:=uint32;
+ Type=:=int64;Type=:=uint64;Type=:=sint32;
+ Type=:=sint64;Type=:=fixed32;Type=:=sfixed32;
+ Type=:=fixed64;Type=:=sfixed64;Type=:=string;
+ Type=:=bytes;Type=:=float;Type=:=double ->
+ protobuffs:encode(FNum, Data, Type);
+
+pack(FNum, _, Data, Type, _) when is_atom(Data) ->
+ protobuffs:encode(FNum, enum_to_int(Type,Data), enum).
+
+enum_to_int(pikachu,value) ->
+ 1.
+
+int_to_enum(_,Val) ->
+ Val.
%% DECODE
decode_pikachu(Bytes) when is_binary(Bytes) ->
@@ -72,29 +94,36 @@ decode(pikachu, Bytes) when is_binary(Bytes) ->
decode(<<>>, _, Acc) -> Acc;
decode(Bytes, Types, Acc) ->
- {{FNum, WireType}, Rest} = protobuffs:read_field_num_and_wire_type(Bytes),
+ {ok, FNum} = protobuffs:next_field_num(Bytes),
case lists:keysearch(FNum, 1, Types) of
{value, {FNum, Name, Type, Opts}} ->
{Value1, Rest1} =
case lists:member(is_record, Opts) of
true ->
- {V, R} = protobuffs:decode_value(Rest, WireType, bytes),
+ {{FNum, V}, R} = protobuffs:decode(Bytes, bytes),
RecVal = decode(list_to_atom(string:to_lower(atom_to_list(Type))), V),
{RecVal, R};
false ->
- {V, R} = protobuffs:decode_value(Rest, WireType, Type),
- {unpack_value(V, Type), R}
+ case lists:member(repeated_packed, Opts) of
+ true ->
+ {{FNum, V}, R} = protobuffs:decode_packed(Bytes, Type),
+ {V, R};
+ false ->
+ {{FNum, V}, R} = protobuffs:decode(Bytes, Type),
+ {unpack_value(V, Type), R}
+ end
+
end,
case lists:member(repeated, Opts) of
true ->
case lists:keytake(FNum, 1, Acc) of
{value, {FNum, Name, List}, Acc1} ->
- decode(Rest1, Types, [{FNum, Name, lists:reverse([Value1|lists:reverse(List)])}|Acc1]);
+ decode(Rest1, Types, [{FNum, Name, lists:reverse([int_to_enum(Type,Value1)|lists:reverse(List)])}|Acc1]);
false ->
- decode(Rest1, Types, [{FNum, Name, [Value1]}|Acc])
+ decode(Rest1, Types, [{FNum, Name, [int_to_enum(Type,Value1)]}|Acc])
end;
false ->
- decode(Rest1, Types, [{FNum, Name, Value1}|Acc])
+ decode(Rest1, Types, [{FNum, Name, int_to_enum(Type,Value1)}|Acc])
end;
false ->
exit({error, {unexpected_field_index, FNum}})
View
@@ -0,0 +1,8 @@
+{ application, protobuffs,
+ [ { description, "Google protobuffs implementation for Erlang." },
+ { vsn, "0.6.0" },
+ { registered, [] },
+ { applications, [kernel,stdlib] },
+ { env, [] }
+ ]
+}.
Oops, something went wrong.

0 comments on commit 47476c1

Please sign in to comment.