epgsql_codec_test_enum.erl 404 B

12345678910111213141516171819
  1. -module(epgsql_codec_test_enum).
  2. -behaviour(epgsql_codec).
  3. -export([init/2, names/0, encode/3, decode/3]).
  4. init(Choices, _) -> Choices.
  5. names() ->
  6. [my_type].
  7. encode(Atom, my_type, Choices) ->
  8. true = lists:member(Atom, Choices),
  9. atom_to_binary(Atom, utf8).
  10. decode(Bin, my_type, Choices) ->
  11. Atom = binary_to_existing_atom(Bin, utf8),
  12. true = lists:member(Atom, Choices),
  13. Atom.