Created
March 29, 2021 06:58
-
-
Save mpugach/0c2e68423831e247a202713f4d08522f to your computer and use it in GitHub Desktop.
What implementation of Foo.mega_to_payload/3 do you prefer? Why?
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
defmodule Foo do | |
def mega_to_payload( | |
%MyMegaProtobuf{ | |
c_seq: c_seq, | |
call_id: call_id | |
}, | |
timestamp, | |
message_id | |
) do | |
%{ | |
c_seq: c_seq, | |
call_id: call_id, | |
message_id: message_id, | |
timestamp: timestamp, | |
update_id: DateTime.to_unix(timestamp, :microsecond) | |
} | |
|> DB.insert_one() | |
end | |
def mega_to_payload( | |
%MyMegaProtobuf{} = mega_struct, | |
timestamp, | |
message_id | |
) do | |
keys_to_store = [ | |
:c_seq, | |
:call_id | |
] | |
mega_struct | |
|> Map.take(keys_to_store) | |
|> Map.merge(%{ | |
message_id: message_id, | |
timestamp: timestamp, | |
update_id: DateTime.to_unix(timestamp, :microsecond) | |
}) | |
|> DB.insert_one() | |
end | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
defmodule MyMegaProtobuf do | |
@moduledoc """ | |
This is autogenerated file. Do not change it manually. | |
""" | |
defstruct [ | |
:c_seq, | |
:call_id, | |
:recipient_id, | |
:sender_id, | |
:status | |
] | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment