Skip to content

Instantly share code, notes, and snippets.

@mpugach
Created March 29, 2021 06:58
Show Gist options
  • Save mpugach/0c2e68423831e247a202713f4d08522f to your computer and use it in GitHub Desktop.
Save mpugach/0c2e68423831e247a202713f4d08522f to your computer and use it in GitHub Desktop.
What implementation of Foo.mega_to_payload/3 do you prefer? Why?
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
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