Building a library that uses binary communication over the internet… here is what a common structure looks like when it is being inspected:
%Structure{
data: <<218, 84, 144, 157, 59, 107, 55, 125, 38, 84, 224, 136, 117, 150,
180, 159, 142, 54, 196, 48, 15, 219, 158, 185, 227, 228, 58, 71, 220, 237,
167, 137>>
}
Now, people tend to discuss about it using hex… so it would be much easier to reason with if it looked more like this:
%Structure{
data: <<0xda54909d3b6b377d2654e0887596b49f8e36c4300fdb9eb9e3e43a47dceda789::256>>
}
A nice benefit of that notation is that when pasted in a REPL, it parses just fine.
I tried to use defimpl
for Structure
, redefining the inspect
function and it works… problem is, inspect ends up returning a green string without indentation. Trying to fix this, I was in the process of writing a ton of code, which doesn’t feel right…
So… is there way to instruct elixir to output to the 2nd example without messing up with the formatting?