Generator for alternative erl bindings, as well as a few more changes to lib code.
- Exceptions don't work yet, but it looks like everything else does.
- Seems to work fine on our pricing service
- Code could need some cleanup
git-svn-id: https://svn.apache.org/repos/asf/incubator/thrift/trunk@666377 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/lib/alterl/src/thrift_processor.erl b/lib/alterl/src/thrift_processor.erl
index 546bcfe..742bc28 100644
--- a/lib/alterl/src/thrift_processor.erl
+++ b/lib/alterl/src/thrift_processor.erl
@@ -29,44 +29,13 @@
case thrift_protocol:read(IProto, message_begin) of
#protocol_message_begin{name = Function,
type = ?tMessageType_CALL} ->
- ok = handle_function(State, list_to_atom(binary_to_list(Function))),
+ ok= handle_function(State, list_to_atom(binary_to_list(Function))),
loop(State);
{error, closed} ->
- error_logger:info_msg("Processor finished~n"),
+ error_logger:info_msg("Client disconnected~n"),
ok
end.
-%handle_function(State = #state{in_protocol = IProto,
-% out_protocol = OProto},
-% add) ->
-% io:format("Reading struct~n"),
-% {ok, Struct} = thrift_protocol:read(IProto,
-% {struct, [{1, i32},
-% {2, i32}]}),
-% io:format("Struct: ~p~n", [Struct]),
-
-% {A, B} = Struct,
-
-% thrift_protocol:write(OProto, #protocol_message_begin{
-% name = "addResult",
-% type = ?tMessageType_REPLY,
-% seqid = 0}),
-% thrift_protocol:write(OProto, {{struct, [{0, i32}]},
-% {A + B}}),
-% thrift_protocol:write(OProto, message_end);
-
-%handle_function(State = #state{in_protocol = IProto,
-% out_protocol = OProto},
-% complexTest) ->
-% io:format("Reading struct~n"),
-% Struct = thrift_protocol:read(
-% IProto,
-% {struct, [{1, {struct,
-% [{1, {list, i32}},
-% {2, {map, string, {struct, [{1, i16}]}}}]}}]}),
-
-% io:format("Struct: ~p~n", [Struct]);
-
handle_function(State = #state{in_protocol = IProto,
out_protocol = OProto,
@@ -76,17 +45,21 @@
InParams = Service:function_info(Function, params_type),
{ok, Params} = thrift_protocol:read(IProto, InParams),
- Result = Handler:handle_function(Function, Params),
+
+ {Micro, Result} = timer:tc(Handler, handle_function, [Function, Params]),
+ error_logger:info_msg("Processed ~p(~p) in ~.4fms~n",
+ [Function, Params, Micro/1000.0]),
ReplyType = Service:function_info(Function, reply_type),
case Result of
{reply, Reply} ->
+ StructName = atom_to_list(Function) ++ "_result",
thrift_protocol:write(OProto, #protocol_message_begin{
- name = atom_to_list(Function) ++ "_result",
+ name = StructName,
type = ?tMessageType_REPLY,
seqid = 0}),
- thrift_protocol:write(OProto, {{struct, [{0, ReplyType}]}, {Reply}}),
+ thrift_protocol:write(OProto, {{struct, [{0, ReplyType}]}, {StructName, Reply}}),
thrift_protocol:write(OProto, message_end)
end,
ok.
diff --git a/lib/alterl/src/thrift_protocol.erl b/lib/alterl/src/thrift_protocol.erl
index 75c2d4b..c94fde1 100644
--- a/lib/alterl/src/thrift_protocol.erl
+++ b/lib/alterl/src/thrift_protocol.erl
@@ -75,6 +75,14 @@
end || Index <- lists:seq(1, length(Structure))],
{ok, list_to_tuple(List)};
+read(IProto, {struct, {Module, StructureName}}) when is_atom(Module),
+ is_atom(StructureName) ->
+ case read(IProto, Module:struct_info(StructureName)) of
+ {ok, StructureElems} ->
+ {ok, list_to_tuple([StructureName | tuple_to_list(StructureElems)])};
+ Else -> Else
+ end;
+
read(IProto, {list, Type}) ->
#protocol_list_begin{etype = EType, size = Size} =
read(IProto, list_begin),
@@ -217,12 +225,21 @@
%% Description:
%%--------------------------------------------------------------------
write(Proto, {{struct, StructDef}, Data})
- when is_list(StructDef), is_tuple(Data), length(StructDef) == size(Data) ->
- ok = write(Proto, #protocol_struct_begin{}),
- ok = struct_write_loop(Proto, StructDef, tuple_to_list(Data)),
+ when is_list(StructDef), is_tuple(Data), length(StructDef) == size(Data) - 1 ->
+
+ [StructName | Elems] = tuple_to_list(Data),
+ ok = write(Proto, #protocol_struct_begin{name = StructName}),
+ ok = struct_write_loop(Proto, StructDef, Elems),
ok = write(Proto, struct_end),
ok;
+write(Proto, {{struct, {Module, StructureName}}, Data})
+ when is_atom(Module),
+ is_atom(StructureName),
+ element(1, Data) =:= StructureName ->
+ StructType = Module:struct_info(StructureName),
+ write(Proto, {Module:struct_info(StructureName), Data});
+
write(Proto, {{list, Type}, Data})
when is_list(Data) ->
ok = write(Proto,