You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@thrift.apache.org by dr...@apache.org on 2010/08/31 00:05:59 UTC

svn commit: r991000 - in /incubator/thrift/trunk: lib/erl/src/thrift_protocol.erl test/erl/src/test_membuffer.erl

Author: dreiss
Date: Mon Aug 30 22:05:58 2010
New Revision: 991000

URL: http://svn.apache.org/viewvc?rev=991000&view=rev
Log:
erlang: Verify elt/key/val when reading list/set/map

For now, exit on a badmatch if one is wrong.

Modified:
    incubator/thrift/trunk/lib/erl/src/thrift_protocol.erl
    incubator/thrift/trunk/test/erl/src/test_membuffer.erl

Modified: incubator/thrift/trunk/lib/erl/src/thrift_protocol.erl
URL: http://svn.apache.org/viewvc/incubator/thrift/trunk/lib/erl/src/thrift_protocol.erl?rev=991000&r1=990999&r2=991000&view=diff
==============================================================================
--- incubator/thrift/trunk/lib/erl/src/thrift_protocol.erl (original)
+++ incubator/thrift/trunk/lib/erl/src/thrift_protocol.erl Mon Aug 30 22:05:58 2010
@@ -135,6 +135,7 @@ read(IProto, S={struct, Structure}) when
 read(IProto0, {list, Type}) ->
     {IProto1, #protocol_list_begin{etype = EType, size = Size}} =
         read(IProto0, list_begin),
+    {EType, EType} = {term_to_typeid(Type), EType},
     {List, IProto2} = lists:mapfoldl(fun(_, ProtoS0) ->
                                              {ProtoS1, {ok, Item}} = read(ProtoS0, Type),
                                              {Item, ProtoS1}
@@ -145,8 +146,10 @@ read(IProto0, {list, Type}) ->
     {IProto3, {ok, List}};
 
 read(IProto0, {map, KeyType, ValType}) ->
-    {IProto1, #protocol_map_begin{size = Size}} =
+    {IProto1, #protocol_map_begin{size = Size, ktype = KType, vtype = VType}} =
         read(IProto0, map_begin),
+    {KType, KType} = {term_to_typeid(KeyType), KType},
+    {VType, VType} = {term_to_typeid(ValType), VType},
     {List, IProto2} = lists:mapfoldl(fun(_, ProtoS0) ->
                                              {ProtoS1, {ok, Key}} = read(ProtoS0, KeyType),
                                              {ProtoS2, {ok, Val}} = read(ProtoS1, ValType),
@@ -160,6 +163,7 @@ read(IProto0, {map, KeyType, ValType}) -
 read(IProto0, {set, Type}) ->
     {IProto1, #protocol_set_begin{etype = EType, size = Size}} =
         read(IProto0, set_begin),
+    {EType, EType} = {term_to_typeid(Type), EType},
     {List, IProto2} = lists:mapfoldl(fun(_, ProtoS0) ->
                                              {ProtoS1, {ok, Item}} = read(ProtoS0, Type),
                                              {Item, ProtoS1}

Modified: incubator/thrift/trunk/test/erl/src/test_membuffer.erl
URL: http://svn.apache.org/viewvc/incubator/thrift/trunk/test/erl/src/test_membuffer.erl?rev=991000&r1=990999&r2=991000&view=diff
==============================================================================
--- incubator/thrift/trunk/test/erl/src/test_membuffer.erl (original)
+++ incubator/thrift/trunk/test/erl/src/test_membuffer.erl Mon Aug 30 22:05:58 2010
@@ -74,8 +74,23 @@ t3() ->
     true = TestData#bools.im_false =:= Result#bools.im_false.
 
 
+t4() ->
+    {ok, Transport} = thrift_memory_buffer:new(),
+    {ok, Protocol0} = thrift_binary_protocol:new(Transport),
+    TestData = #insanity{xtructs=[]},
+		{Protocol1, ok} = thrift_protocol:write(Protocol0,
+			       {{struct, element(2, thriftTest_types:struct_info('insanity'))},
+				TestData}),
+		{_Protocol2, {ok, Result}} = thrift_protocol:read(Protocol1,
+					{struct, element(2, thriftTest_types:struct_info('insanity'))},
+					'insanity'),
+
+    TestData = Result.
+
+
 t() ->
     t1(),
     t2(),
-    t3().
+    t3(),
+    t4().