From 61eebc9e4d1a31f34b1b2fabf7b81c5d9554a419 Mon Sep 17 00:00:00 2001 From: szTheory Date: Thu, 3 Dec 2020 17:33:44 +0000 Subject: [PATCH] README: markdown syntax highlighting --- README.md | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index a63f5d9..c7e26ac 100644 --- a/README.md +++ b/README.md @@ -7,6 +7,7 @@ Hex.pm: https://hex.pm/packages/binpp Example usage: +```erlang 1> Bin. <<12,242,207,49,82,69,45,130,212,69,80,88,8,81,23,36,86,7, 68,19,133,97,51,216,56,145,88,8,81,...>> @@ -17,11 +18,13 @@ Example usage: 0003 05 81 0F 09 15 C5 61 33 D8 54 91 52 5D 81 17 24 ....Åa3ØT‘R].$ 0004 11 14 60 23 D1 3D 55 80 ..`#Ñ=U€ ok +``` Binpp will use io:format to output the formatted binary by default, however there are options making pprint functions return formatted data instead of performing direct IO write: +```erlang 1> Bin2 = <<"foo bar baz">>. <<"foo bar baz">> 2> binpp:pprint(Bin2, [{return, iolist}]). @@ -29,21 +32,27 @@ of performing direct IO write: "foo bar baz","\n"]] 3> binpp:pprint(Bin2, [{return, binary}]). <<"0000 66 6F 6F 20 62 61 72 20 62 61 7A foo bar baz\n">> +``` You may use a custom printer function as well: +```erlang 4> binpp:pprint(Bin2, [{printer, fun(O) -> io:format("~s~n", [O]) end}]). 0000 66 6F 6F 20 62 61 72 20 62 61 7A foo bar baz ok +``` An additional API is provided for printing binary fragments: +```erlang 5> binpp:pprint(Bin2, {0, 3}, []). 0000 66 6F 6F foo +``` Also, binary byte-to-byte comparsion: +```erlang 6> binpp:compare(<<1,2,1024:512,3,4>>, <<1,3,1024:512,5,6>>). -- 02 -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 03 -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- @@ -51,9 +60,11 @@ Also, binary byte-to-byte comparsion: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 03 04 -- -- 05 06 ok +``` Plus a handy little helper: +```erlang 7> binpp:compare(<<1,2,255,3,1024:512>>, binpp:from_str("01 02 FF CC")). -- -- -- 03 00 00 00 00 00 00 00 00 00 00 00 00 -- -- -- CC ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? @@ -61,7 +72,7 @@ Plus a handy little helper: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? 00 00 04 00 ?? ?? ?? ?? ok - +``` Edoc available at http://jtendo.github.com/binpp/doc/.