index.jade
9.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
doctype 5
html(lang="en")
head
meta(charset="utf-8")
title "ref" documentation v#{package.version}
meta(name="description", content=package.description)
meta(name="keywords", content=['node.js', package.name].concat(package.keywords).join(', '))
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")
body
.container
.columns.three.logo
a(href="")
h1 #{package.name}
span.pointer *
span.version v#{package.version}
.columns.thirteen.subtitle
h3= package.description
.columns.sixteen.intro
h4 What is <code>ref</code>?
p
code ref
| is a native addon for
a(href="http://nodejs.org") Node.js
| that aids in doing C programming in JavaScript, by extending
| the built-in
a(href="http://nodejs.org/api/buffer.html")
code Buffer
| class
| with some fancy additions like:
ul
li Getting the memory address of a Buffer
li Checking the endianness of the processor
li Checking if a Buffer represents the NULL pointer
li Reading and writing "pointers" with Buffers
li Reading and writing C Strings (NULL-terminated)
li Reading and writing JavaScript Object references
li Reading and writing
strong int64_t
| and
strong uint64_t
| values
li A "type" convention to define the contents of a Buffer
p
| There is indeed a lot of
em meat
| to
code ref
| , but it all fits together in one way or another in the end.
br
| For simplicity,
code ref
| 's API can be broken down into 3 sections:
a.nav.columns.five(href='#exports')
h4 ref <code>exports</code>
p
| All the static versions of
code ref
| 's functions and default "types" available on the exports returned from
code require('ref')
| .
a.nav.columns.five(href='#types')
h4 <em>"type"</em> system
p
| The
em "type"
| system allows you to define a "type" on any Buffer instance, and then
| use generic
code ref()
| and
code deref()
| functions to reference and dereference values.
a.nav.columns.five(href='#extensions')
h4 <code>Buffer</code> extensions
p
code Buffer.prototype
| gets extended with some convenience functions. These all just mirror
| their static counterpart, using the Buffer's
code this
| variable as the
code buffer
| variable.
hr
.columns.eight.section.exports
a(name="exports")
a(href="#exports")
h2 ref exports
.columns.sixteen.intro
p
| This section documents all the functions exported from
code require('ref')
| .
each doc in exports
if (!doc.ignore)
.columns.sixteen.section
a(name='exports-' + doc.name)
a(href='#exports-' + doc.name)
isFunc = doc.type == 'method' || doc.isPrivate
h3
| ref.#{doc.name}
if (isFunc)
| (
each param, i in doc.paramTypes
span.param #{param.types.join('|')} #{param.name}
if (i + 1 < doc.paramTypes.length)
| ,
| )
if (doc.returnType)
|
span.rtn → #{doc.returnType.types.join('|')}
if (!isFunc)
|
span.rtn ⇒ #{doc.type}
if (doc.paramTypes.length > 0 || doc.returnType)
ul
each param in doc.paramTypes
li #{param.name} - !{param.description}
if (doc.returnType)
li
strong Return:
| !{doc.returnType.description}
!= (doc && doc.description.full || '').replace(/\<br ?\/?\>/g, ' ')
hr
.columns.eight.section.types
a(name="types")
a(href="#types")
h2
em "type"
| system
.columns.sixteen.intro.types
p
| A "type" in
code ref
| is simply an plain 'ol JavaScript Object, with a set
| of expected properties attached that implement the logic for getting
| & setting values on a given
code Buffer
| instance.
p
| To attach a "type" to a Buffer instance, you simply attach the "type"
| object to the Buffer's <code>type</code> property.
code ref
| comes with a set of commonly used types which are described in this
| section.
h4 Creating your own "type"
p
| It's trivial to create your own "type" that reads and writes your
| own custom datatype/class to and from Buffer instances using
code ref
| 's unified API.
br
| To create your own "type", simply create a JavaScript Object with
| the following properties defined:
table
tr
th Name
th Data Type
th Description
tr
td: code size
td: code Number
td The size in bytes required to hold this datatype.
tr
td: code indirection
td: code Number
td
| The current level of indirection of the buffer. When defining
| your own "types", just set this value to <code>1</code>.
tr
td: code get
td: code Function
td
| The function to invoke when
a(href="#exports-get")
code ref.get()
| is invoked on a buffer of this type.
tr
td: code set
td: code Function
td
| The function to invoke when
a(href="#exports-set")
code ref.set()
| is invoked on a buffer of this type.
tr
td: code name
td: code String
td
em (Optional)
| The name to use during debugging for this datatype.
tr
td: code alignment
td: code Number
td
em (Optional)
| The alignment of this datatype when placed inside a struct.
| Defaults to the type's
code size
| .
h4 The built-in "types"
p
| Here is the list of
code ref
| 's built-in "type" Objects. All these built-in "types" can be found
| on the
code ref.types
| export Object. All the built-in types use "native endianness" when
| multi-byte datatypes are involved.
each doc in types
if (!doc.ignore)
.columns.sixteen.section
a(name='types-' + doc.name)
a(href='#types-' + doc.name)
h3 types.#{doc.name}
!= doc.description.full.replace(/\<br ?\/?\>/g, ' ')
hr
.columns.eight.section.exports
a(name="extensions")
a(href="#extensions")
h2 Buffer extensions
.columns.sixteen.intro
p
code Buffer.prototype
| gets extended with some convenience functions that you can use in
| your modules and/or applications.
each doc in extensions
if (!doc.ignore)
.columns.sixteen.section
a(name='extensions-' + doc.name)
a(href='#extensions-' + doc.name)
h3 Buffer##{doc.name}()
if (doc.name === 'inspect')
!= doc.description.full.replace(/\<br ?\/?\>/g, ' ')
else
p
| Shorthand for
a(href='#exports-' + doc.name)
code ref.#{doc.name}(this, …)
| .
!= (doc.ref && doc.ref.description.full || '').replace(/\<br ?\/?\>/g, ' ')
.ribbon
a(href="https://github.com/TooTallNate/ref", rel="me") Fork me on GitHub
script(src="scripts/jquery-1.7.2.min.js")
script(src="scripts/main.js")