Permalink
Browse files

Test changes to see if leaving the encoded protocol buffer as an ioli…

…st is faster if sending to a TCP socket.
  • Loading branch information...
1 parent 7f6da83 commit e564c06563a8f6eba74661b48d4ab3a55a637152 Jon Meredith committed with Vagabond Aug 21, 2009
Showing with 17 additions and 5 deletions.
  1. +4 −3 src/pokemon_pb.erl
  2. +13 −2 src/protobuffs_compile.erl
View
@@ -35,9 +35,10 @@ encode_pikachu(Record) when is_record(Record, pikachu) ->
encode(pikachu, Record).
encode(pikachu, Record) ->
- iolist_to_binary([
- pack(1, required, with_default(Record#pikachu.abc, none), string, [])
- ]).
+ iolist_to_binary(iolist(pikachu, Record)).
+
+iolist(pikachu, Record) ->
+ [pack(1, required, with_default(Record#pikachu.abc, none), string, [])].
with_default(undefined, none) -> undefined;
with_default(undefined, Default) -> Default;
@@ -198,6 +198,9 @@ filter_forms(Msgs, Enums, [{function,L,encode_pikachu,1,[Clause]}|Tail], Basenam
filter_forms(Msgs, Enums, [{function,L,encode,2,[Clause]}|Tail], Basename, Acc) ->
filter_forms(Msgs, Enums, Tail, Basename, [expand_encode_function(Msgs, L, Clause)|Acc]);
+ filter_forms(Msgs, Enums, [{function,L,iolist,2,[Clause]}|Tail], Basename, Acc) ->
+ filter_forms(Msgs, Enums, Tail, Basename, [expand_iolist_function(Msgs, L, Clause)|Acc]);
+
filter_forms(Msgs, Enums, [{function,L,decode_pikachu,1,[Clause]}|Tail], Basename, Acc) ->
Functions = [begin
{function,
@@ -231,6 +234,15 @@ expand_encode_function(Msgs, Line, Clause) ->
%% @hidden
filter_encode_clause({MsgName, Fields}, {clause,L,_Args,Guards,_Content}) ->
+ ToBin = {call,L,{atom,L,iolist_to_binary},[{call,L,
+ {atom,L,iolist},
+ [{atom,L,atomize(MsgName)},{var,L,'Record'}]}]},
+ {clause,L,[{atom,L,atomize(MsgName)},{var,L,'Record'}],Guards,[ToBin]}.
+
+expand_iolist_function(Msgs, Line, Clause) ->
+ {function,Line,iolist,2,[filter_iolist_clause(Msg, Clause) || Msg <- Msgs]}.
+
+filter_iolist_clause({MsgName, Fields}, {clause,L,_Args,Guards,_Content}) ->
Cons = lists:foldl(
fun({FNum,Tag,SType,SName,Default}, Acc) ->
{cons,L,
@@ -246,8 +258,7 @@ filter_encode_clause({MsgName, Fields}, {clause,L,_Args,Guards,_Content}) ->
{nil,L}]},
Acc}
end, {nil,L}, Fields),
- ToBin = {call,L,{atom,L,iolist_to_binary},[Cons]},
- {clause,L,[{atom,L,atomize(MsgName)},{var,L,'Record'}],Guards,[ToBin]}.
+ {clause,L,[{atom,L,atomize(MsgName)},{var,L,'Record'}],Guards,[Cons]}.
%% @hidden
expand_decode_function(Msgs, Line, Clause) ->

0 comments on commit e564c06

Please sign in to comment.