Skip to content

Commit

Permalink
update the docs
Browse files Browse the repository at this point in the history
  • Loading branch information
TooTallNate committed Jul 12, 2012
1 parent 08562bb commit cdaa9f2
Showing 1 changed file with 10 additions and 10 deletions.
20 changes: 10 additions & 10 deletions index.html
@@ -1,4 +1,4 @@
<!DOCTYPE html><html lang="en"><head><meta charset="utf-8"><title>"ref" documentation v0.0.20</title><meta name="description" content="Turn Buffer instances into &quot;pointers&quot;"><meta name="keywords" content="node.js, ref, native, buffer, extensions, c++, pointer, reference, dereference, type, int, long, float, double, byte, 64"><meta name="author" content="Nathan Rajlich"><meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1"><link rel="stylesheet" href="stylesheets/hightlight.css"><link rel="stylesheet" href="stylesheets/base.css"><link rel="stylesheet" href="stylesheets/skeleton.css"><link rel="stylesheet" href="stylesheets/layout.css"></head><body><div class="container"><div class="columns three logo"><a href=""><h1>ref <span class="pointer">*</span><span class="version">v0.0.20</span></h1></a></div><div class="columns thirteen subtitle"><h3>Turn Buffer instances into &quot;pointers&quot;</h3></div><div class="columns sixteen intro"><h4>What is <code>ref</code>?</h4><p><code>ref</code> is a native addon for <a href="http://nodejs.org">Node.js</a> that aids in doing C programming in JavaScript, by extending
<!DOCTYPE html><html lang="en"><head><meta charset="utf-8"><title>"ref" documentation v0.0.20</title><meta name="description" content="Turn Buffer instances into &quot;pointers&quot;"><meta name="keywords" content="node.js, ref, native, buffer, extensions, c++, pointer, reference, dereference, type, int, long, float, double, byte, 64"><meta name="author" content="Nathan Rajlich"><meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1"><link rel="stylesheet" href="stylesheets/hightlight.css"><link rel="stylesheet" href="stylesheets/base.css"><link rel="stylesheet" href="stylesheets/skeleton.css"><link rel="stylesheet" href="stylesheets/layout.css"><link rel="shortcut icon" href="images/favicon.ico"><link rel="apple-touch-icon" href="images/apple-touch-icon.png"><link rel="apple-touch-icon" sizes="72x72" href="images/apple-touch-icon-72x72.png"><link rel="apple-touch-icon" sizes="114x114" href="images/apple-touch-icon-114x114.png"></head><body><div class="container"><div class="columns three logo"><a href=""><h1>ref <span class="pointer">*</span><span class="version">v0.0.20</span></h1></a></div><div class="columns thirteen subtitle"><h3>Turn Buffer instances into &quot;pointers&quot;</h3></div><div class="columns sixteen intro"><h4>What is <code>ref</code>?</h4><p><code>ref</code> is a native addon for <a href="http://nodejs.org">Node.js</a> that aids in doing C programming in JavaScript, by extending
the built-in <a href="http://nodejs.org/api/buffer.html"><code>Buffer</code> class</a> with some fancy additions like:<ul><li>Getting the memory address of a Buffer</li><li>Checking the endianness of the processor</li><li>Checking if a Buffer represents the NULL pointer</li><li>Reading and writing "pointers" with Buffers</li><li>Reading and writing C Strings (NULL-terminated)</li><li>Reading and writing JavaScript Object references</li><li>Reading and writing <strong>int64_t</strong> and <strong>uint64_t</strong> values</li><li>A "type" convention to define the contents of a Buffer</li></ul></p><p>There is indeed a lot of <em>meat </em> to <code>ref</code>, but it all fits together in one way or another in the end.<br>For simplicity, <code>ref</code>'s API can be broken down into 3 sections:</p></div><a href="#exports" class="nav columns five"><h4>ref <code>exports</code></h4><p>All the static versions of <code>ref</code>'s functions and default "types" available on the exports returned from <code>require('ref')</code>.</p></a><a href="#types" class="nav columns five"><h4><em>"type"</em> system</h4><p>The <em>"type"</em> system allows you to define a "type" on any Buffer instance, and then
use generic <code>ref()</code> and <code>deref()</code> functions to reference and dereference values.</p></a><a href="#extensions" class="nav columns five"><h4><code>Buffer</code> extensions</h4><p><code>Buffer.prototype</code> gets extended with some convenience functions. These all just mirror
their static counterpart, using the Buffer's <code>this</code> variable as the <code>buffer</code> variable.</p></a><hr><div class="columns eight section exports"><a name="exports"></a><a href="#exports"><h2>ref exports</h2></a></div><div class="columns sixteen intro"><p>This section documents all the functions exported from <code>require('ref')</code>.</p></div><div class="columns sixteen section"><a name="exports-NULL"></a><a href="#exports-NULL"><h3>ref.NULL <span class="rtn"> &rArr; Buffer</span></h3></a><p>A <code>Buffer</code> that references the C NULL pointer. That is, its memory address
Expand Down Expand Up @@ -48,9 +48,9 @@
<li><code>ref.types.int</code> gets translated into <code>ref.types.int</code> (returns itself)</li>
</ul>
<p>Throws an Error if no valid &quot;type&quot; object could be determined. Most <code>ref</code>
functions use this function under the, so anywhere a &quot;type&quot; object is expected,
a String may be passed as well, including simply setting the <code>buffer.type</code>
property.
functions use this function under the hood, so anywhere a &quot;type&quot; object is
expected, a String may be passed as well, including simply setting the
<code>buffer.type</code> property.

</p>
<pre><code><span class="keyword">var</span> type = ref.coerceType(<span class="string">'int **'</span>);
Expand Down Expand Up @@ -95,10 +95,10 @@
NULL pointer, <em>false</em> otherwise.

</p>
<pre><code>console.log(<span class="keyword">new</span> Buffer(<span class="number">1</span>).isNull());
<pre><code>console.log(ref.isNull(<span class="keyword">new</span> Buffer(<span class="number">1</span>)));
<span class="literal">false</span>

console.log(ref.NULL.isNull());
console.log(ref.isNull(ref.NULL));
<span class="literal">true</span></code></pre>
</div><div class="columns sixteen section"><a name="exports-readCString"></a><a href="#exports-readCString"><h3>ref.readCString(<span class="param">Buffer buffer</span>, <span class="param">Number offset</span>) <span class="rtn">&rarr; String</span></h3></a><ul><li>buffer - The buffer to read a Buffer from.</li><li>offset - The offset to begin reading from.</li><li><strong>Return: </strong>The String that was read from <em>buffer</em>.</li></ul><p>Returns a JavaScript String read from <em>buffer</em> at the given <em>offset</em>. The
C String is read until the first NULL byte, which indicates the end of the
Expand Down Expand Up @@ -190,7 +190,7 @@
<span class="keyword">var</span> val = ref.readUInt64LE(buf, <span class="number">0</span>)
console.log(val)
<span class="string">'18446744073709551615'</span></code></pre>
</div><div class="columns sixteen section"><a name="exports-ref"></a><a href="#exports-ref"><h3>ref.ref(<span class="param">Buffer buffer</span>) <span class="rtn">&rarr; Buffer</span></h3></a><ul><li>buffer - A Buffer instance to create a reference to.</li><li><strong>Return: </strong>A new Buffer instance pointing to &quot;buffer&quot;.</li></ul><p><code>ref()</code> acceps a Buffer instance and returns a new Buffer
</div><div class="columns sixteen section"><a name="exports-ref"></a><a href="#exports-ref"><h3>ref.ref(<span class="param">Buffer buffer</span>) <span class="rtn">&rarr; Buffer</span></h3></a><ul><li>buffer - A Buffer instance to create a reference to.</li><li><strong>Return: </strong>A new Buffer instance pointing to <em>buffer</em>.</li></ul><p><code>ref()</code> acceps a Buffer instance and returns a new Buffer
instance that is &quot;pointer&quot; sized and has it&#39;s data pointing to the given
Buffer instance. Essentially the created Buffer is a &quot;reference&quot; to the
original pointer, equivalent to the following C code:
Expand Down Expand Up @@ -411,10 +411,10 @@
NULL pointer, <em>false</em> otherwise.

</p>
<pre><code>console.log(<span class="keyword">new</span> Buffer(<span class="number">1</span>).isNull());
<pre><code>console.log(ref.isNull(<span class="keyword">new</span> Buffer(<span class="number">1</span>)));
<span class="literal">false</span>

console.log(ref.NULL.isNull());
console.log(ref.isNull(ref.NULL));
<span class="literal">true</span></code></pre>
</div><div class="columns sixteen section"><a name="extensions-readCString"></a><a href="#extensions-readCString"><h3>Buffer#readCString()</h3></a><p>Shorthand for <a href="#exports-readCString"><code>ref.readCString(this, …)</code></a>.</p><p>Returns a JavaScript String read from <em>buffer</em> at the given <em>offset</em>. The
C String is read until the first NULL byte, which indicates the end of the
Expand Down Expand Up @@ -586,4 +586,4 @@
</p>
<pre><code><span class="keyword">var</span> buf = ref.alloc(<span class="string">'uint64'</span>);
ref.writeUInt64LE(buf, <span class="number">0</span>, <span class="string">'18446744073709551615'</span>);</code></pre>
</div></div><div class="ribbon"><a href="https://github.com/TooTallNate/ref" rel="me">Fork me on GitHub</a></div><script src="scripts/jquery-1.7.2.min.js"></script><script src="scripts/main.js"></script></body></html>
</div></div><div class="ribbon"><a href="https://github.com/TooTallNate/ref" rel="me">Fork me on GitHub</a></div><script src="scripts/jquery-1.7.2.min.js"></script><script src="scripts/main.js"></script></body></html>

0 comments on commit cdaa9f2

Please sign in to comment.