Author: dreiss
Date: Tue Jun 10 15:58:21 2008
New Revision: 666383
URL: http://svn.apache.org/viewvc?rev=666383&view=rev
Log:
Fix reading of empty structs/arg lists
Modified:
incubator/thrift/trunk/lib/alterl/src/thrift_protocol.erl
Modified: incubator/thrift/trunk/lib/alterl/src/thrift_protocol.erl
URL:
http://svn.apache.org/viewvc/incubator/thrift/trunk/lib/alterl/src/thrift_protocol.erl?rev=666383&r1=666382&r2=666383&view=diff
==============================================================================
--- incubator/thrift/trunk/lib/alterl/src/thrift_protocol.erl (original)
+++ incubator/thrift/trunk/lib/alterl/src/thrift_protocol.erl Tue Jun 10
15:58:21 2008
@@ -59,9 +59,14 @@
%% Structure is like:
%% [{Fid, Type}, ...]
read(IProto, {struct, Structure}) when is_list(Structure) ->
+ IndexList = case length(Structure) of
+ N when N > 0 -> lists:seq(1, N);
+ _ -> []
+ end,
+
SWithIndices = [{Fid, {Type, Index}} ||
{{Fid, Type}, Index} <-
- lists:zip(Structure, lists:seq(1,
length(Structure)))],
+ lists:zip(Structure, IndexList)],
% Fid -> {Type, Index}
SDict = dict:from_list(SWithIndices),
@@ -72,7 +77,7 @@
List = [case dict:find(Index, RDict) of
{ok, Val} -> Val;
error -> undefined
- end || Index <- lists:seq(1, length(Structure))],
+ end || Index <- IndexList],
{ok, list_to_tuple(List)};
read(IProto, {struct, {Module, StructureName}}) when is_atom(Module),
@@ -87,7 +92,7 @@
#protocol_list_begin{etype = EType, size = Size} =
read(IProto, list_begin),
List = [Result || {ok, Result} <-
- [read(IProto, Type) || _X <- lists:seq(1, Size)]],
+ [read(IProto, Type) || _X <- lists:duplicate(Size,
0)]],
ok = read(IProto, list_end),
{ok, List};
@@ -97,7 +102,7 @@
List = [{Key, Val} || {{ok, Key}, {ok, Val}} <-
[{read(IProto, KeyType),
- read(IProto, ValType)} || _X <- lists:seq(1,
Size)]],
+ read(IProto, ValType)} || _X <-
lists:duplicate(Size, 0)]],
ok = read(IProto, map_end),
{ok, dict:from_list(List)};
@@ -106,7 +111,7 @@
size = Size} =
read(IProto, set_begin),
List = [Result || {ok, Result} <-
- [read(IProto, Type) || _X <- lists:seq(1, Size)]],
+ [read(IProto, Type) || _X <- lists:duplicate(Size,
0)]],
ok = read(IProto, set_end),
{ok, sets:from_list(List)};