Skip to content

Instantly share code, notes, and snippets.

@brweber2
Created September 25, 2015 13:28
Show Gist options
  • Save brweber2/a0b89a7c7dbdfaf0763c to your computer and use it in GitHub Desktop.
Save brweber2/a0b89a7c7dbdfaf0763c to your computer and use it in GitHub Desktop.
Custom Sigil with pattern matching...
def magic(nbr) do
a = ~x(a1b2c3d4)
b = ~x(d4c3b2a1)
c = ~x(a1b23c4d)
d = ~x(4d3cb2a1)
case nbr do
^a -> %Pcap.Global.MagicNumber{ magic_number: nbr, swap_fields: false, nanoseconds: false }
^b -> %Pcap.Global.MagicNumber{ magic_number: nbr, swap_fields: true, nanoseconds: false }
^c -> %Pcap.Global.MagicNumber{ magic_number: nbr, swap_fields: false, nanoseconds: true }
^d -> %Pcap.Global.MagicNumber{ magic_number: nbr, swap_fields: true, nanoseconds: true }
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment