ppbert 0.1.0

simple pretty printer for Erlang's External Term Format
Documentation

ppbert

A simple command-line utility to pretty print structures encoded using Erlang's External Term Format. The input is read from stdin and output on stdout, making ppbert a good candidate for shell pipelines.

At the moment, ppbert supports only a subset of the field types of the External Term Format:

  • integers;
  • big integers;
  • floats;
  • atoms (latin-1 and UTF-8);
  • binaries;
  • tuples;
  • lists.

Usage

$ ppbert <mini_dict.bert
[
  {host, "localhost"},
  {port, 80},
  {
    headers,
    [
      {
        <<"X-Real-Ip">>,
        {127, 0, 0, 1}
      },
      {<<"Keep-alive">>, true}
    ]
  }
]

$ printf "\x83\x77\x04atom" | ppbert
atom

Performance

Ppbert is written in Rust and offers an appreciable performance gain over using Erlang's erlang:binary_to_term/1 and io:format/2.

$ cat erl_ppbert
#!/usr/bin/env escript

main(Args) ->
    lists:foreach(fun (Filename) ->
        {ok, Binary} = file:read_file(Filename),
        io:format("~p~n", [binary_to_term(Binary)])
    end, Args).

$ du large.bert
96M     large.bert

$ time ./erl_ppbert large.bert >/dev/null

real    1m10.968s
user    0m49.644s
sys     0m13.628s

$ time ppbert <large.bert >/dev/null

real    0m19.670s
user    0m19.092s
sys     0m0.432s

Future work

  • Add flags to control the pretty printing (e.g., indentation width, number of basic values on a single line, etc.).
  • Do latin-1 encoding for atoms and strings.
  • Add a jq-like query language.
  • Write a man page.