Cobenian / expcap

Elixir PCAP library
Apache License 2.0
30 stars 13 forks source link

Cannot override exist protocol implementation #3

Open gyson opened 5 years ago

gyson commented 5 years ago

When I follow README instructions and try to override PayloadType for Protocol.Udp like following:

defimpl PayloadType, for: Protocol.Udp do
  def payload_parser(_data) do
    nil # override default Protocol.Dns
  end
end

Above code will override exist protocol implementation, which results two issues:

  1. warning about redefining module:

    warning: redefining module PayloadType.Protocol.Udp (current version loaded from /app/_build/prod/lib/expcap/ebin/Elixir.PayloadType.Protocol.Udp.beam)
    lib/my_app/path/to/file.ex:123
  2. compile with mix release (1.9) would result error:

    ** (Mix) Duplicated modules:
        'Elixir.PayloadType.Protocol.Udp' specified in my_app and expcap

I googled a little bit, it does not seem to have a general way to override an exist protocol implementation, e.g. this thread.

Thanks for the nice library! Any suggestion on this ?