mirror of
https://github.com/valitydev/bouncer.git
synced 2024-11-06 02:15:18 +00:00
fix: Add thrift encoding for boolean values (#31)
* fix: Add typespecs * fix: Fix typespecs * fix: Fix typespecs * refactor: Fix formattinc * fix: Add bool encoding
This commit is contained in:
parent
105005f237
commit
315a251f86
@ -25,6 +25,11 @@
|
||||
| {set, field_type()}
|
||||
| {map, field_type(), field_type()}.
|
||||
|
||||
-type field_thrift_value(_Type) :: term().
|
||||
-type field_native_value(_Type) :: term().
|
||||
|
||||
-type name_mapping_fun() :: fun((term()) -> binary()).
|
||||
|
||||
-type struct_field_info() ::
|
||||
{field_num(), field_req(), field_type(), field_name(), any()}.
|
||||
|
||||
@ -63,6 +68,8 @@ to_thrift_struct([], MapLeft, _Idx, Acc, _NameFun) ->
|
||||
error({excess_data, MapLeft})
|
||||
end.
|
||||
|
||||
-spec to_thrift_value(Type :: field_type(), field_native_value(Type), name_mapping_fun()) ->
|
||||
field_thrift_value(Type).
|
||||
to_thrift_value({struct, struct, {Mod, Name}}, V = #{}, NameFun) ->
|
||||
{struct, _, StructDef} = Mod:struct_info(Name),
|
||||
Acc = erlang:make_tuple(length(StructDef) + 1, undefined, [{1, Mod:record_name(Name)}]),
|
||||
@ -78,6 +85,8 @@ to_thrift_value(i32, V, _NameFun) ->
|
||||
to_thrift_value(i16, V, _NameFun) ->
|
||||
V;
|
||||
to_thrift_value(byte, V, _NameFun) ->
|
||||
V;
|
||||
to_thrift_value(bool, V, _NameFun) ->
|
||||
V.
|
||||
|
||||
from_thrift_struct(StructDef, Struct) ->
|
||||
@ -98,6 +107,7 @@ from_thrift_struct([{_, _Req, Type, Name, _Default} | Rest], Struct, Idx, Acc) -
|
||||
from_thrift_struct([], _Struct, _, Acc) ->
|
||||
Acc.
|
||||
|
||||
-spec from_thrift_value(Type :: field_type(), field_thrift_value(Type)) -> field_native_value(Type).
|
||||
from_thrift_value({struct, struct, {Mod, Name}}, V) ->
|
||||
{struct, _, StructDef} = Mod:struct_info(Name),
|
||||
from_thrift_struct(StructDef, V);
|
||||
@ -112,6 +122,8 @@ from_thrift_value(i32, V) ->
|
||||
from_thrift_value(i16, V) ->
|
||||
V;
|
||||
from_thrift_value(byte, V) ->
|
||||
V;
|
||||
from_thrift_value(bool, V) ->
|
||||
V.
|
||||
|
||||
identity(V) ->
|
||||
|
Loading…
Reference in New Issue
Block a user