mirror of
https://github.com/valitydev/bouncer.git
synced 2024-11-06 02:15:18 +00:00
Fix generic thrift→json encoding (#13)
Tags (which are integer field designators in thrift serializations) were wrongly interpreted as indices in Erlang record tuples. * Update for recent rebar3_lint w/ elvis_core 1.0.0
This commit is contained in:
parent
2445f446d6
commit
2850275de0
14
rebar.config
14
rebar.config
@ -122,6 +122,8 @@
|
||||
{elvis_style, used_ignored_variable, disable},
|
||||
% Tests are usually more comprehensible when a bit more verbose.
|
||||
{elvis_style, dont_repeat_yourself, #{min_complexity => 20}},
|
||||
% Too opionated
|
||||
{elvis_style, state_record_and_type, disable},
|
||||
{elvis_style, god_modules, #{ignore => [ct_gun_event_h]}}
|
||||
]
|
||||
},
|
||||
@ -134,18 +136,18 @@
|
||||
dirs => ["."],
|
||||
filter => "rebar.config",
|
||||
rules => [
|
||||
{elvis_style, line_length, #{limit => 100, skip_comments => false}},
|
||||
{elvis_style, no_tabs},
|
||||
{elvis_style, no_trailing_whitespace}
|
||||
{elvis_text_style, line_length, #{limit => 100, skip_comments => false}},
|
||||
{elvis_text_style, no_tabs},
|
||||
{elvis_text_style, no_trailing_whitespace}
|
||||
]
|
||||
},
|
||||
#{
|
||||
dirs => ["src"],
|
||||
filter => "*.app.src",
|
||||
rules => [
|
||||
{elvis_style, line_length, #{limit => 100, skip_comments => false}},
|
||||
{elvis_style, no_tabs},
|
||||
{elvis_style, no_trailing_whitespace}
|
||||
{elvis_text_style, line_length, #{limit => 100, skip_comments => false}},
|
||||
{elvis_text_style, no_tabs},
|
||||
{elvis_text_style, no_trailing_whitespace}
|
||||
]
|
||||
}
|
||||
]}.
|
||||
|
@ -56,9 +56,13 @@ from_thrift(#bctx_v1_ContextFragment{} = Ctx0) ->
|
||||
from_thrift_context(Ctx) ->
|
||||
{struct, _, [_VsnField | StructDef]} =
|
||||
bouncer_context_v1_thrift:struct_info('ContextFragment'),
|
||||
% NOTE
|
||||
% This 3 refers to the first data field in a ContextFragment, after version field.
|
||||
from_thrift_struct(StructDef, Ctx, 3, #{}).
|
||||
|
||||
from_thrift_struct(StructDef, Struct) ->
|
||||
% NOTE
|
||||
% This 2 refers to the first field in a record tuple.
|
||||
from_thrift_struct(StructDef, Struct, 2, #{}).
|
||||
|
||||
from_thrift_struct([{_, _Req, Type, Name, _Default} | Rest], Struct, Idx, Acc) ->
|
||||
@ -117,18 +121,23 @@ to_thrift(Context) ->
|
||||
{struct, _, StructDef} = bouncer_context_v1_thrift:struct_info('ContextFragment'),
|
||||
to_thrift_struct(StructDef, Context, #bctx_v1_ContextFragment{}).
|
||||
|
||||
to_thrift_struct([{Idx, _Req, Type, Name, Default} | Rest], Map, Acc) ->
|
||||
to_thrift_struct(StructDef, Map, Acc) ->
|
||||
% NOTE
|
||||
% This 2 refers to the first field in a record tuple.
|
||||
to_thrift_struct(StructDef, Map, 2, Acc).
|
||||
|
||||
to_thrift_struct([{_Tag, _Req, Type, Name, Default} | Rest], Map, Idx, Acc) ->
|
||||
case maps:take(Name, Map) of
|
||||
{V, MapLeft} ->
|
||||
Acc1 = erlang:setelement(Idx + 1, Acc, to_thrift_value(Type, V)),
|
||||
to_thrift_struct(Rest, MapLeft, Acc1);
|
||||
Acc1 = erlang:setelement(Idx, Acc, to_thrift_value(Type, V)),
|
||||
to_thrift_struct(Rest, MapLeft, Idx + 1, Acc1);
|
||||
error when Default /= undefined ->
|
||||
Acc1 = erlang:setelement(Idx + 1, Acc, Default),
|
||||
to_thrift_struct(Rest, Map, Acc1);
|
||||
Acc1 = erlang:setelement(Idx, Acc, Default),
|
||||
to_thrift_struct(Rest, Map, Idx + 1, Acc1);
|
||||
error ->
|
||||
to_thrift_struct(Rest, Map, Acc)
|
||||
to_thrift_struct(Rest, Map, Idx + 1, Acc)
|
||||
end;
|
||||
to_thrift_struct([], MapLeft, Acc) ->
|
||||
to_thrift_struct([], MapLeft, _Idx, Acc) ->
|
||||
case map_size(MapLeft) of
|
||||
0 ->
|
||||
Acc;
|
||||
|
Loading…
Reference in New Issue
Block a user