_Else ->
case dict:find(Fid, SDict) of
{ok, {Type, Index}} ->
- {ok, Val} = read(IProto, Type),
- thrift_protocol:read(IProto, field_end),
- NewRTuple = setelement(Index, RTuple, Val),
- read_struct_loop(IProto, SDict, NewRTuple);
+ case term_to_typeid(Type) of
+ FType ->
+ {ok, Val} = read(IProto, Type),
+ thrift_protocol:read(IProto, field_end),
+ NewRTuple = setelement(Index, RTuple, Val),
+ read_struct_loop(IProto, SDict, NewRTuple);
+ Expected ->
+ error_logger:info_msg(
+ "Skipping field ~p with wrong type (~p != ~p)~n",
+ [Fid, FType, Expected]),
+ skip_field(FType, IProto, SDict, RTuple)
+ end;
_Else2 ->
- error_logger:info_msg("Skipping fid ~p~n", [Fid]),
- FTypeAtom = thrift_protocol:typeid_to_atom(FType),
- thrift_protocol:skip(IProto, FTypeAtom),
- read(IProto, field_end),
- read_struct_loop(IProto, SDict, RTuple)
+ error_logger:info_msg("Skipping field ~p with unknown fid~n", [Fid]),
+ skip_field(FType, IProto, SDict, RTuple)
end
end.
+skip_field(FType, IProto, SDict, RTuple) ->
+ FTypeAtom = thrift_protocol:typeid_to_atom(FType),
+ thrift_protocol:skip(IProto, FTypeAtom),
+ read(IProto, field_end),
+ read_struct_loop(IProto, SDict, RTuple).
+
skip(Proto, struct) ->
ok = read(Proto, struct_begin),
Result = TestData.
+t2() ->
+ {ok, Transport} = thrift_memory_buffer:new(),
+ {ok, Protocol} = thrift_binary_protocol:new(Transport),
+ TestData = test_data(),
+ ok = thrift_protocol:write(Protocol,
+ {{struct, element(2, thriftTest_types:struct_info('xtruct'))},
+ TestData}),
+ {ok, Result} = thrift_protocol:read(Protocol,
+ {struct, element(2, thriftTest_types:struct_info('xtruct3'))},
+ 'xtruct3'),
+
+ Result = #xtruct3{string_thing = TestData#xtruct.string_thing,
+ changed = undefined,
+ i32_thing = TestData#xtruct.i32_thing,
+ i64_thing = TestData#xtruct.i64_thing}.
+
+
t() ->
- t1().
+ t1(),
+ t2().