{
  "name": "ref",
  "description": "Turn Buffer instances into \"pointers\"",
  "keywords": [
    "native",
    "buffer",
    "extensions",
    "c++",
    "pointer",
    "reference",
    "dereference",
    "type",
    "int",
    "long",
    "float",
    "double",
    "byte",
    "64"
  ],
  "version": "0.3.2",
  "author": {
    "name": "Nathan Rajlich",
    "email": "nathan@tootallnate.net",
    "url": "http://tootallnate.net"
  },
  "repository": {
    "type": "git",
    "url": "git://github.com/TooTallNate/ref.git"
  },
  "main": "./lib/ref.js",
  "scripts": {
    "docs": "node docs/compile",
    "test": "mocha -gc --reporter spec",
    "install": "node-gyp rebuild"
  },
  "dependencies": {
    "bindings": "~1.2.0",
    "debug": "~1.0.1",
    "nan": "~1.2.0"
  },
  "devDependencies": {
    "dox": "0.4.4",
    "highlight.js": "1",
    "jade": "0.35.0",
    "marked": "0.3.2",
    "mocha": "*",
    "weak": "0.3.2"
  },
  "gypfile": true,
  "readme": "ref\n===\n### Turn Buffer instances into \"pointers\"\n[![Build Status](https://secure.travis-ci.org/TooTallNate/ref.svg)](https://travis-ci.org/TooTallNate/ref)\n[![Build Status](https://ci.appveyor.com/api/projects/status/n8mswogp2im4uot8)](https://ci.appveyor.com/project/TooTallNate/ref)\n\n\nThis module is inspired by the old `Pointer` class from node-ffi, but with the\nintent of using Node's fast `Buffer` instances instead of a slow C++ `Pointer`\nclass. These two concepts were previously very similar, but now this module\nbrings over the functionality that Pointers had and Buffers are missing, so\nnow Buffers are a lot more powerful.\n\n### Features:\n\n * Get the memory address of any `Buffer` instance\n * Read/write references to JavaScript Objects into `Buffer` instances\n * Read/write `Buffer` instances' memory addresses to other `Buffer` instances\n * Read/write `int64_t` and `uint64_t` data values (Numbers or Strings)\n * A \"type\" convention, so that you can specify a buffer as an `int *`,\n   and reference/dereference at will.\n * Offers a buffer instance representing the `NULL` pointer\n\n\nInstallation\n------------\n\nInstall with `npm`:\n\n``` bash\n$ npm install ref\n```\n\n\nExamples\n--------\n\n#### referencing and derefencing\n\n``` js\nvar ref = require('ref')\n\n// so we can all agree that a buffer with the int value written\n// to it could be represented as an \"int *\"\nvar buf = new Buffer(4)\nbuf.writeInt32LE(12345, 0)\n\n// first, what is the memory address of the buffer?\nconsole.log(buf.address())  // ← 140362165284824\n\n// using `ref`, you can set the \"type\", and gain magic abilities!\nbuf.type = ref.types.int\n\n// now we can dereference to get the \"meaningful\" value\nconsole.log(buf.deref())  // ← 12345\n\n\n// you can also get references to the original buffer if you need it.\n// this buffer could be thought of as an \"int **\"\nvar one = buf.ref()\n\n// and you can dereference all the way back down to an int\nconsole.log(one.deref().deref())  // ← 12345\n```\n\nSee the [full API Docs][docs] for more examples.\n\n\nThe \"type\" interface\n--------------------\n\nYou can easily define your own \"type\" objects at attach to `Buffer` instances.\nIt just needs to be a regular JavaScript Object that contains the following\nproperties:\n\n| **Name**      | **Data Type**                    | **Description**\n|:--------------|:---------------------------------|:----------------------------------\n| `size`        | Number                           | The size in bytes required to hold this type.\n| `indirection` | Number                           | The current level of indirection of the buffer. Usually this would be _1_, and gets incremented on Buffers from `ref()` calls. A value of less than or equal to _0_ is invalid.\n| `get`         | Function (buffer, offset)        | The function to invoke when dereferencing this type when the indirection level is _1_.\n| `set`         | Function (buffer, offset, value) | The function to invoke when setting a value to a buffer instance.\n| `name`        | String                           | _(optional)_ The name to use during debugging for this type.\n| `alignment`   | Number                           | _(optional)_ The alignment of this type when placed in a struct. Defaults to the type's `size`.\n\nFor example, you could define a \"bigint\" type that dereferences into a\n[`bigint`](https://github.com/substack/node-bigint) instance:\n\n``` js\nvar ref = require('ref')\nvar bigint = require('bigint')\n\n// define the \"type\" instance according to the spec\nvar BigintType = {\n    size: ref.sizeof.int64\n  , indirection: 1\n  , get: function (buffer, offset) {\n      // return a bigint instance from the buffer\n      return bigint.fromBuffer(buffer)\n    }\n  , set: function (buffer, offset, value) {\n      // 'value' would be a bigint instance\n      var val = value.toString()\n      return ref.writeInt64(buffer, offset || 0, val)\n    }\n}\n\n// now we can create instances of the type from existing buffers.\n// \"buf\" is some Buffer instance returned from some external data\n// source, which should contain \"bigint\" binary data.\nbuf.type = BigintType\n\n// and now you can create \"bigint\" instances using this generic \"types\" API\nvar val = buf.deref()\n            .add('1234')\n            .sqrt()\n            .shiftLeft(5)\n```\n\nBuild the docs\n--------------\n\nInstall the dev dependencies:\n\n``` bash\n$ npm install\n```\n\nGenerate the docs:\n\n``` bash\n$ npm run docs\n```\n\n\nLicense\n-------\n\n(The MIT License)\n\nCopyright (c) 2012 Nathan Rajlich &lt;nathan@tootallnate.net&gt;\n\nPermission is hereby granted, free of charge, to any person obtaining\na copy of this software and associated documentation files (the\n'Software'), to deal in the Software without restriction, including\nwithout limitation the rights to use, copy, modify, merge, publish,\ndistribute, sublicense, and/or sell copies of the Software, and to\npermit persons to whom the Software is furnished to do so, subject to\nthe following conditions:\n\nThe above copyright notice and this permission notice shall be\nincluded in all copies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,\nEXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF\nMERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.\nIN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY\nCLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,\nTORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE\nSOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.\n\n[docs]: http://tootallnate.github.com/ref\n",
  "readmeFilename": "README.md",
  "bugs": {
    "url": "https://github.com/TooTallNate/ref/issues"
  },
  "_id": "ref@0.3.2",
  "dist": {
    "shasum": "b51369ca44f15331b4058dbd871c08daa1323ab5"
  },
  "_from": "ref@*",
  "_resolved": "https://registry.npmjs.org/ref/-/ref-0.3.2.tgz"
}
