mirror of
https://github.com/valitydev/elixir-thrift.git
synced 2024-11-07 10:38:50 +00:00
Remove bool_to_int (#89)
This moves a bit of complexity from struct_deserializer into value_serializer(:bool). Things are a little more coherent overall, and it also helps simplify struct_deserializer, which is getting complex.
This commit is contained in:
parent
220e7fe91e
commit
60da661c94
@ -92,10 +92,6 @@ defmodule Thrift.Generator.StructBinaryProtocol do
|
||||
unquote([field_serializers, <<0>>] |> Utils.merge_binaries)
|
||||
end
|
||||
|
||||
def bool_to_int(false), do: 0
|
||||
def bool_to_int(nil), do: 0
|
||||
def bool_to_int(_), do: 1
|
||||
|
||||
def deserialize(binary) do
|
||||
deserialize(binary, %unquote(name){})
|
||||
end
|
||||
@ -807,7 +803,15 @@ defmodule Thrift.Generator.StructBinaryProtocol do
|
||||
|> list_deserializer(name, file_group)
|
||||
end
|
||||
|
||||
defp value_serializer(:bool, var, _file_group), do: quote do: <<bool_to_int(unquote(var))>>
|
||||
defp value_serializer(:bool, var, _file_group) do
|
||||
quote do
|
||||
case unquote(var) do
|
||||
nil -> <<0>>
|
||||
false -> <<0>>
|
||||
_ -> <<1>>
|
||||
end
|
||||
end
|
||||
end
|
||||
defp value_serializer(:byte, var, _file_group), do: quote do: <<unquote(var) :: 8-signed>>
|
||||
defp value_serializer(:i8, var, _file_group), do: quote do: <<unquote(var) :: 8-signed>>
|
||||
defp value_serializer(:double, var, _file_group), do: quote do: <<unquote(var) :: signed-float>>
|
||||
|
Loading…
Reference in New Issue
Block a user