Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

io:format string rendering for bytes >= 0x8E #12

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 0 additions & 16 deletions Makefile

This file was deleted.

61 changes: 0 additions & 61 deletions README.md

This file was deleted.

92 changes: 92 additions & 0 deletions doc/binpp.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Module binpp</title>
<link rel="stylesheet" type="text/css" href="stylesheet.css" title="EDoc">
</head>
<body bgcolor="white">
<div class="navbar"><a name="#navbar_top"></a><table width="100%" border="0" cellspacing="0" cellpadding="2" summary="navigation bar"><tr><td><a href="overview-summary.html" target="overviewFrame">Overview</a></td><td><a href="http://www.erlang.org/"><img src="erlang.png" align="right" border="0" alt="erlang logo"></a></td></tr></table></div>
<hr>

<h1>Module binpp</h1>
<ul class="index"><li><a href="#description">Description</a></li><li><a href="#types">Data Types</a></li><li><a href="#index">Function Index</a></li><li><a href="#functions">Function Details</a></li></ul>Pretty printer for Erlang binaries.


<h2><a name="description">Description</a></h2>Pretty printer for Erlang binaries.

<h2><a name="types">Data Types</a></h2>

<h3 class="typedecl"><a name="type-opts">opts()</a></h3>
<p><b>abstract datatype</b>: <tt>opts()</tt></p>


<h2><a name="index">Function Index</a></h2>
<table width="100%" border="1" cellspacing="0" cellpadding="2" summary="function index"><tr><td valign="top"><a href="#compare-2">compare/2</a></td><td>Pretty print byte-to-byte comparsion of two binaries to stdout.</td></tr>
<tr><td valign="top"><a href="#convert-1">convert/1</a></td><td>Convert binary to hex string.</td></tr>
<tr><td valign="top"><a href="#convert-2">convert/2</a></td><td>Convert binary to hex string or binary (base-2) string.</td></tr>
<tr><td valign="top"><a href="#from_str-1">from_str/1</a></td><td>Construct binary from hex string.</td></tr>
<tr><td valign="top"><a href="#pprint-1">pprint/1</a></td><td>Pretty print a binary to stdout using <em>io:format/2</em>
Note: <em>io:format/2</em> is a blocking call.</td></tr>
<tr><td valign="top"><a href="#pprint-2">pprint/2</a></td><td>Print a binary using custom function or return the formatted result.</td></tr>
<tr><td valign="top"><a href="#pprint-3">pprint/3</a></td><td>Pretty print a slice of binary.</td></tr>
</table>

<h2><a name="functions">Function Details</a></h2>

<h3 class="function"><a name="compare-2">compare/2</a></h3>
<div class="spec">
<p><tt>compare(Bin1::binary() | bitstring(), Bin2::binary() | bitstring()) -&gt; ok</tt><br></p>
</div><p>Pretty print byte-to-byte comparsion of two binaries to stdout.</p>

<h3 class="function"><a name="convert-1">convert/1</a></h3>
<div class="spec">
<p><tt>convert(Bin::binary() | bitstring()) -&gt; {ok, list()}</tt><br></p>
</div><p>Convert binary to hex string.</p>

<h3 class="function"><a name="convert-2">convert/2</a></h3>
<div class="spec">
<p><tt>convert(Bin::binary() | bitstring(), X2::hex | bin) -&gt; {ok, list()}</tt><br></p>
</div><p>Convert binary to hex string or binary (base-2) string.</p>

<h3 class="function"><a name="from_str-1">from_str/1</a></h3>
<div class="spec">
<p><tt>from_str(Str::string()) -&gt; binary()</tt><br></p>
</div><p>Construct binary from hex string.
Hex string octets can be optionally separated with spaces.
Valid hex strings:
<ul>
<li>"AA BB FF 01"</li>
<li>"AABBFF01"</li>
</ul></p>

<h3 class="function"><a name="pprint-1">pprint/1</a></h3>
<div class="spec">
<p><tt>pprint(Bin::binary() | bitstring()) -&gt; ok</tt><br></p>
</div><p>Pretty print a binary to stdout using <em>io:format/2</em>
Note: <em>io:format/2</em> is a blocking call.</p>

<h3 class="function"><a name="pprint-2">pprint/2</a></h3>
<div class="spec">
<p><tt>pprint(Bin::binary() | bitstring(), Opts::<a href="#type-opts">opts()</a>) -&gt; ok | any()</tt><br></p>
</div><p>Print a binary using custom function or return the formatted result.
Valid options are:
<ul>
<li>{return, binary}</li>
<li>{return, iolist}</li>
<li>{printer, CustomFunction}</li>
</ul>

Custom functions should be of arity 1, accepting the prettified result as
an <em>iolist()</em> input. Returned value can be <em>any()</em>.</p>

<h3 class="function"><a name="pprint-3">pprint/3</a></h3>
<div class="spec">
<p><tt>pprint(Bin::binary() | bitstring(), X2::{non_neg_integer(), non_neg_integer()}, Opts::<a href="#type-opts">opts()</a>) -&gt; ok | any()</tt><br></p>
</div><p>Pretty print a slice of binary.</p>
<hr>

<div class="navbar"><a name="#navbar_bottom"></a><table width="100%" border="0" cellspacing="0" cellpadding="2" summary="navigation bar"><tr><td><a href="overview-summary.html" target="overviewFrame">Overview</a></td><td><a href="http://www.erlang.org/"><img src="erlang.png" align="right" border="0" alt="erlang logo"></a></td></tr></table></div>
<p><i>Generated by EDoc, Oct 30 2012, 14:26:44.</i></p>
</body>
</html>
3 changes: 3 additions & 0 deletions doc/edoc-info
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{application,binpp}.
{packages,[]}.
{modules,[binpp]}.
Binary file added doc/erlang.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
17 changes: 17 additions & 0 deletions doc/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>The binpp application</title>
</head>
<frameset cols="20%,80%">
<frame src="modules-frame.html" name="modulesFrame" title="">

<frame src="overview-summary.html" name="overviewFrame" title="">
<noframes>
<h2>This page uses frames</h2>
<p>Your browser does not accept frames.
<br>You should go to the <a href="overview-summary.html">non-frame version</a> instead.
</p>
</noframes>
</frameset>
</html>
12 changes: 12 additions & 0 deletions doc/modules-frame.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>The binpp application</title>
<link rel="stylesheet" type="text/css" href="stylesheet.css" title="EDoc">
</head>
<body bgcolor="white">
<h2 class="indextitle">Modules</h2>
<table width="100%" border="0" summary="list of modules">
<tr><td><a href="binpp.html" target="overviewFrame" class="module">binpp</a></td></tr></table>
</body>
</html>
121 changes: 121 additions & 0 deletions doc/overview-summary.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,121 @@
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>binpp - Erlang Binary Pretty Printer</title>
<link rel="stylesheet" type="text/css" href="stylesheet.css" title="EDoc">
</head>
<body bgcolor="white">
<div class="navbar"><a name="#navbar_top"></a><table width="100%" border="0" cellspacing="0" cellpadding="2" summary="navigation bar"><tr><td><a href="overview-summary.html" target="overviewFrame">Overview</a></td><td><a href="http://www.erlang.org/"><img src="erlang.png" align="right" border="0" alt="erlang logo"></a></td></tr></table></div>
<h1>binpp - Erlang Binary Pretty Printer</h1>
<p>Copyright � 2012 (c) Adam Rutkowski &lt;[email protected]&gt;</p>
<p><b>Version:</b> 1.1
</p>
<p>This lilbrary provides additional utility functions for working with Erlang
<em>binary()</em> and <em>bitstring()</em> types.</p>

You might find it useful if you are going to:
<ul>
<li>Implement or debug arbitrary protocols</li>
<li>Log/dump binary data</li>
<li>Learn how Erlang binaries work</li>
</ul>

<h2>Installation</h2>

<ol>

<li><p>binpp comes with a Makefile that requires rebar build tool.</p>

If you don't have rebar installed, you may get it from <a href="https://github.com/basho/rebar">Rebar Github repository</a>
</li>

<li><p>
Download the sources from <a href="http://github.com/jtendo/binpp">binpp Github repository</a>.</p>

<ul>
<li>To build the library run <em>make</em>.</li>
<li>To run the tests run <em>make test</em>.</li>
<li>To generate documentation run <em>make docs</em>.</li>
</ul>
</li>
</ol>



<h2>Example usage</h2>

<pre> 1&gt; Bin.
&lt;&lt;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,...&gt;&gt;
2&gt; binpp:pprint(Bin).
0C F2 CF 31 52 45 2D 82 D4 45 50 58 08 51 17 24 .òÏ1RE-‚ÔEPX.Q.$
56 07 44 13 85 61 33 D8 38 91 58 08 51 17 24 56 V.D.…a3Ø8‘X.Q.$V
0A 14 20 4E 24 16 09 60 F4 0A 15 11 01 30 13 89 .. N$..`ô....0.‰
05 81 0F 09 15 C5 61 33 D8 54 91 52 5D 81 17 24 ....Åa3ØT‘R].$
11 14 60 23 D1 3D 55 80 ..`#Ñ=U€
ok</pre>

<p>Binpp will use <em>io:format</em> to output the formatted binary by default, however
there are options making pprint functions return formatted data instead
of performing direct IO write:</p>

<pre> 1&gt; Bin2 = &lt;&lt;"foo bar baz"&gt;&gt;.
&lt;&lt;"foo bar baz"&gt;&gt;
2&gt; binpp:pprint(Bin2, [{return, iolist}]).
[["66 6F 6F 20 62 61 72 20 62 61 7A ",32,
"foo bar baz","\n"]]
3&gt; binpp:pprint(Bin2, [{return, binary}]).
&lt;&lt;"66 6F 6F 20 62 61 72 20 62 61 7A foo bar baz\n"&gt;&gt;</pre>

<p>You may use a custom printer function as well:</p>

<pre> 4&gt; binpp:pprint(Bin2, [{printer, fun(O) -&gt; io:format("~s~n", [O]) end}]).
66 6F 6F 20 62 61 72 20 62 61 7A foo bar baz

ok</pre>

<p>An additional API is provided for printing binary fragments:</p>

<pre> 5&gt; binpp:pprint(Bin2, {0, 3}, []).
66 6F 6F foo</pre>

<p>Also, binary byte-to-byte comparsion:</p>

<pre> 6&gt; binpp:compare(&lt;&lt;1,2,1024:512,3,4&gt;&gt;, &lt;&lt;1,3,1024:512,5,6&gt;&gt;).
-- 02 -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 03 -- -- -- -- -- -- -- -- -- -- -- -- -- --
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
-- -- 03 04 -- -- 05 06
ok</pre>

<p>Plus a handy little helper:</p>

<pre> 7&gt; binpp:compare(&lt;&lt;1,2,255,3,1024:512&gt;&gt;, 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 ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ??
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ??
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ??
00 00 04 00 ?? ?? ?? ??
ok</pre>

<p>That's all folks!</p>

<h2>Get involved</h2>

<p>Bug reports can be submitted to: <a href="http://github.com/jtendo/binpp/issues/">binpp issues @ Github</a>.</p>

<p>Patches and feature requests are always welcome!</p>

<h2>Module index:</h2>
<dl>
<dt><a href="binpp.html"><code>binpp</code></a></dt>
<dd>Erlang Binary Pretty Printer</dd>
</dl>

<hr>
<div class="navbar"><a name="#navbar_bottom"></a><table width="100%" border="0" cellspacing="0" cellpadding="2" summary="navigation bar"><tr><td><a href="overview-summary.html" target="overviewFrame">Overview</a></td><td><a href="http://www.erlang.org/"><img src="erlang.png" align="right" border="0" alt="erlang logo"></a></td></tr></table></div>
<p><i>Generated by EDoc, Oct 30 2012, 14:26:44.</i></p>
</body>
</html>
11 changes: 11 additions & 0 deletions doc/packages-frame.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>The binpp application</title>
<link rel="stylesheet" type="text/css" href="stylesheet.css" title="EDoc">
</head>
<body bgcolor="white">
<h2 class="indextitle">Packages</h2>
<table width="100%" border="0" summary="list of packages"></table>
</body>
</html>
55 changes: 55 additions & 0 deletions doc/stylesheet.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
/* standard EDoc style sheet */
body {
font-family: Verdana, Arial, Helvetica, sans-serif;
margin-left: .25in;
margin-right: .2in;
margin-top: 0.2in;
margin-bottom: 0.2in;
color: #000000;
background-color: #ffffff;
}
h1,h2 {
margin-left: -0.2in;
}
div.navbar {
background-color: #add8e6;
padding: 0.2em;
}
h2.indextitle {
padding: 0.4em;
background-color: #add8e6;
}
h3.function,h3.typedecl {
background-color: #add8e6;
padding-left: 1em;
}
div.spec {
margin-left: 2em;
background-color: #eeeeee;
}
a.module,a.package {
text-decoration:none
}
a.module:hover,a.package:hover {
background-color: #eeeeee;
}
ul.definitions {
list-style-type: none;
}
ul.index {
list-style-type: none;
background-color: #eeeeee;
}

/*
* Minor style tweaks
*/
ul {
list-style-type: square;
}
table {
border-collapse: collapse;
}
td {
padding: 3
}
Loading