index.jade 9.1 KB

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