Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use pattern matching to serialize bool values #104

Merged
merged 3 commits into from
Dec 30, 2016
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 2 additions & 8 deletions lib/thrift/protocols/binary.ex
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,6 @@ defmodule Thrift.Protocols.Binary do
def int_type({:set, _}), do: 14
def int_type({:list, _}), do: 15

defp bool_to_int(false), do: 0
defp bool_to_int(nil), do: 0
defp bool_to_int(_), do: 1

defp to_message_type(:call), do: 1
defp to_message_type(:reply), do: 2
defp to_message_type(:exception), do: 3
Expand All @@ -53,10 +49,8 @@ defmodule Thrift.Protocols.Binary do
def serialize(_, nil) do
[]
end
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This clause should not exist. The way we serialize nil depends on its context.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That sounds right to me. I'll remove it in its own PR so we can track the specific motivation.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This clause is removed in #105.

def serialize(:bool, value) do
value = bool_to_int(value)
<<value::8-signed>>
end
def serialize(:bool, false), do: <<0::8-signed>>
def serialize(:bool, true), do: <<1::8-signed>>
def serialize(:i8, value) do
<<value::8-signed>>
end
Expand Down