Simulator first commit
This commit is contained in:
6
node_modules/ref-struct/.jshintrc
generated
vendored
Normal file
6
node_modules/ref-struct/.jshintrc
generated
vendored
Normal file
@ -0,0 +1,6 @@
|
||||
{
|
||||
"asi": true,
|
||||
"laxcomma": true,
|
||||
"node": true,
|
||||
"strict": false
|
||||
}
|
1
node_modules/ref-struct/.npmignore
generated
vendored
Normal file
1
node_modules/ref-struct/.npmignore
generated
vendored
Normal file
@ -0,0 +1 @@
|
||||
/test
|
33
node_modules/ref-struct/.travis.yml
generated
vendored
Normal file
33
node_modules/ref-struct/.travis.yml
generated
vendored
Normal file
@ -0,0 +1,33 @@
|
||||
sudo: false
|
||||
|
||||
env:
|
||||
- CXX=g++-4.8
|
||||
addons:
|
||||
apt:
|
||||
sources:
|
||||
- ubuntu-toolchain-r-test
|
||||
packages:
|
||||
- g++-4.8
|
||||
|
||||
language: node_js
|
||||
|
||||
node_js:
|
||||
- "0.8"
|
||||
- "0.10"
|
||||
- "0.12"
|
||||
- "iojs-v2.5"
|
||||
- "iojs-v3"
|
||||
|
||||
install:
|
||||
- PATH="`npm bin`:`npm bin -g`:$PATH"
|
||||
# Node 0.8 comes with a too obsolete npm
|
||||
- if [[ "`node --version`" =~ ^v0\.8\. ]]; then npm install -g npm@1.4.28 ; fi
|
||||
# Install dependencies and build
|
||||
- npm install
|
||||
|
||||
script:
|
||||
# Output useful info for debugging
|
||||
- node --version
|
||||
- npm --version
|
||||
# Run tests
|
||||
- npm test
|
99
node_modules/ref-struct/History.md
generated
vendored
Normal file
99
node_modules/ref-struct/History.md
generated
vendored
Normal file
@ -0,0 +1,99 @@
|
||||
|
||||
1.1.0 / 2015-08-27
|
||||
==================
|
||||
|
||||
* [[`eb4550fdaa`](https://github.com/TooTallNate/ref-struct/commit/eb4550fdaa)] - Implement `pack` option (Lee, SungUk)
|
||||
* [[`17c1c7a8ef`](https://github.com/TooTallNate/ref-struct/commit/17c1c7a8ef)] - fix StructType constructor name in README (typo) (David Corticchiato)
|
||||
* [[`54b72bde07`](https://github.com/TooTallNate/ref-struct/commit/54b72bde07)] - **appveyor**: fix node v0.8, test io.js v2.5 and v3 (Nathan Rajlich)
|
||||
|
||||
1.0.2 / 2015-08-27
|
||||
==================
|
||||
|
||||
* appveyor: drop v0.11, iojs v1.5.1, test x64
|
||||
* travis: drop v0.11, test iojs v2.5 and v3
|
||||
* package: add license attribute (#17, @pdehaan)
|
||||
* package: update "ref-array" to v1.1.2
|
||||
* package: update "nan" v2 for native tests
|
||||
* README: use SVG for appveyor badge
|
||||
|
||||
1.0.1 / 2015-03-24
|
||||
==================
|
||||
|
||||
* removed travis testing for node_js version "0.6" and added 0.12 and iojs
|
||||
* added appveyor test versions as per node-ffi library for iojs & 0.12
|
||||
* package: allow any "ref" v "1"
|
||||
* npmignore: add `test` dir
|
||||
|
||||
1.0.0 / 2014-11-03
|
||||
==================
|
||||
|
||||
* bumping to v1.0.0 for better-defined semver semantics
|
||||
|
||||
0.0.7 / 2014-11-03
|
||||
==================
|
||||
|
||||
* gitignore: ignore single letter ?.js test files
|
||||
* lib: only slice buffer in set() in the non-instance case
|
||||
* package: allow any "debug" v2
|
||||
|
||||
0.0.6 / 2014-06-19
|
||||
==================
|
||||
|
||||
* package: update "ref" to v0.3.2
|
||||
* package: update "debug" to v1.0.1
|
||||
* test: remove v8 namespace import
|
||||
* test: use "bindings" module to load the native tests
|
||||
* README: add appveyor build badge
|
||||
* History: match `git changelog` syntax
|
||||
* package: loosely pin the deps
|
||||
* test: nan-ify tests
|
||||
* README: fix Travis badge
|
||||
* README: use svg for Travis badge
|
||||
* travis: test node v0.8, v0.10, and v0.11
|
||||
* add appveyor.yml file for Windows testing
|
||||
* package: remove "engines" field
|
||||
* package: beautify
|
||||
* add a couple comments
|
||||
|
||||
0.0.5 / 2013-01-24
|
||||
==================
|
||||
|
||||
* rename the backing buffer property to `ref.buffer`
|
||||
* add .jshintrc file
|
||||
* some minor optimizations
|
||||
|
||||
0.0.4 / 2012-09-26
|
||||
==================
|
||||
|
||||
* struct: correct the field alignment logic (TJ Fontaine)
|
||||
* test: add failing test from #1
|
||||
* test: more stucts with arrays tests
|
||||
* add support for "ref-array" types
|
||||
* add `toObject()`, `toJSON()`, and `inspect()` functions to struct instances
|
||||
* change `_pointer` to `buffer`
|
||||
* don't allow types with size == 0 like 'void'
|
||||
* test: add test case using "void *" as the type
|
||||
* test: fix deprecation warning
|
||||
* package: use the -C switch on node-gyp for the `npm test` command
|
||||
* travis: test node v0.7 and node v0.8
|
||||
* adjust the custom `toString()` output
|
||||
|
||||
0.0.3 / 2012-06-01
|
||||
==================
|
||||
|
||||
* set the "name" property of StructType instances
|
||||
* add a `toString()` override
|
||||
* fix a bug in the alignment calculation logic
|
||||
|
||||
0.0.2 / 2012-05-16
|
||||
==================
|
||||
|
||||
* Windows support (only the test suite needed tweaks)
|
||||
* make ref().deref() work
|
||||
* make string type identifiers work (type coersion)
|
||||
* don't make the constructors' prototype inherit from `Function.protoype`
|
||||
|
||||
0.0.1 / 2012-05-09
|
||||
==================
|
||||
|
||||
* Initial release
|
111
node_modules/ref-struct/README.md
generated
vendored
Normal file
111
node_modules/ref-struct/README.md
generated
vendored
Normal file
@ -0,0 +1,111 @@
|
||||
ref-struct
|
||||
==========
|
||||
### Create ABI-compliant "[struct][]" instances on top of Buffers
|
||||
[](https://travis-ci.org/TooTallNate/ref-struct)
|
||||
[](https://ci.appveyor.com/project/TooTallNate/ref-struct)
|
||||
|
||||
|
||||
This module offers a "struct" implementation on top of Node.js Buffers
|
||||
using the ref "type" interface.
|
||||
|
||||
Installation
|
||||
------------
|
||||
|
||||
Install with `npm`:
|
||||
|
||||
``` bash
|
||||
$ npm install ref-struct
|
||||
```
|
||||
|
||||
|
||||
Examples
|
||||
--------
|
||||
|
||||
Say you wanted to emulate the `timeval` struct from the stdlib:
|
||||
|
||||
``` c
|
||||
struct timeval {
|
||||
time_t tv_sec; /* seconds since Jan. 1, 1970 */
|
||||
suseconds_t tv_usec; /* and microseconds */
|
||||
};
|
||||
```
|
||||
|
||||
``` js
|
||||
var ref = require('ref')
|
||||
var StructType = require('ref-struct')
|
||||
|
||||
// define the time types
|
||||
var time_t = ref.types.long
|
||||
var suseconds_t = ref.types.long
|
||||
|
||||
// define the "timeval" struct type
|
||||
var timeval = StructType({
|
||||
tv_sec: time_t,
|
||||
tv_usec: suseconds_t
|
||||
})
|
||||
|
||||
// now we can create instances of it
|
||||
var tv = new timeval
|
||||
```
|
||||
|
||||
#### With `node-ffi`
|
||||
|
||||
This gets very powerful when combined with `node-ffi` to invoke C functions:
|
||||
|
||||
``` js
|
||||
var ffi = require('ffi')
|
||||
|
||||
var tv = new timeval
|
||||
gettimeofday(tv.ref(), null)
|
||||
```
|
||||
|
||||
#### Progressive API
|
||||
|
||||
You can build up a Struct "type" incrementally (useful when interacting with a
|
||||
parser) using the `defineProperty()` function. But as soon as you _create_ an
|
||||
instance of the struct type, then the struct type is finalized, and no more
|
||||
properties may be added to it.
|
||||
|
||||
``` js
|
||||
var ref = require('ref')
|
||||
var StructType = require('ref-struct')
|
||||
|
||||
var MyStruct = StructType()
|
||||
MyStruct.defineProperty('width', ref.types.int)
|
||||
MyStruct.defineProperty('height', ref.types.int)
|
||||
|
||||
var i = new MyStruct({ width: 5, height: 10 })
|
||||
|
||||
MyStruct.defineProperty('weight', ref.types.int)
|
||||
// AssertionError: an instance of this Struct type has already been created, cannot add new "fields" anymore
|
||||
// at Function.defineProperty (/Users/nrajlich/ref-struct/lib/struct.js:180:3)
|
||||
```
|
||||
|
||||
|
||||
License
|
||||
-------
|
||||
|
||||
(The MIT License)
|
||||
|
||||
Copyright (c) 2012 Nathan Rajlich <nathan@tootallnate.net>
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining
|
||||
a copy of this software and associated documentation files (the
|
||||
'Software'), to deal in the Software without restriction, including
|
||||
without limitation the rights to use, copy, modify, merge, publish,
|
||||
distribute, sublicense, and/or sell copies of the Software, and to
|
||||
permit persons to whom the Software is furnished to do so, subject to
|
||||
the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be
|
||||
included in all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
|
||||
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
||||
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
||||
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
||||
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
||||
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
|
||||
[struct]: http://wikipedia.org/wiki/Struct_(C_programming_language)
|
47
node_modules/ref-struct/appveyor.yml
generated
vendored
Normal file
47
node_modules/ref-struct/appveyor.yml
generated
vendored
Normal file
@ -0,0 +1,47 @@
|
||||
# http://www.appveyor.com/docs/appveyor-yml
|
||||
|
||||
# Test against these versions of Node.js.
|
||||
environment:
|
||||
# Visual Studio Version
|
||||
MSVS_VERSION: 2013
|
||||
# Test against these versions of Node.js and io.js
|
||||
matrix:
|
||||
# node.js
|
||||
- nodejs_version: "0.8"
|
||||
- nodejs_version: "0.10"
|
||||
- nodejs_version: "0.12"
|
||||
# io.js
|
||||
- nodejs_version: "2.5"
|
||||
- nodejs_version: "3.2"
|
||||
|
||||
platform:
|
||||
- x86
|
||||
- x64
|
||||
|
||||
# Install scripts. (runs after repo cloning)
|
||||
install:
|
||||
# Get the latest stable version of Node 0.STABLE.latest
|
||||
- ps: if($env:nodejs_version -eq "0.8") {Install-Product node $env:nodejs_version}
|
||||
- ps: if($env:nodejs_version -ne "0.8") {Update-NodeJsInstallation (Get-NodeJsLatestBuild $env:nodejs_version)}
|
||||
# Node 0.8 comes with a too obsolete npm
|
||||
- IF %nodejs_version% == 0.8 (npm install -g npm@1.4.28)
|
||||
# Install latest NPM only for node.js versions until built in node-gyp adds io.js support
|
||||
# Update is required for node.js 0.8 because built in npm(node-gyp) does not know VS2013
|
||||
- IF %nodejs_version% LSS 1 (npm install -g npm@2)
|
||||
- IF %nodejs_version% LSS 1 set PATH=%APPDATA%\npm;%PATH%
|
||||
# Typical npm stuff.
|
||||
- npm install --msvs_version=%MSVS_VERSION%
|
||||
|
||||
# Post-install test scripts.
|
||||
test_script:
|
||||
# Output useful info for debugging.
|
||||
- node --version
|
||||
- npm --version
|
||||
# run tests
|
||||
- npm test
|
||||
|
||||
# Don't actually build.
|
||||
build: off
|
||||
|
||||
# Set build version format here instead of in the admin panel.
|
||||
version: "{build}"
|
360
node_modules/ref-struct/lib/struct.js
generated
vendored
Normal file
360
node_modules/ref-struct/lib/struct.js
generated
vendored
Normal file
@ -0,0 +1,360 @@
|
||||
|
||||
/**
|
||||
* An interface for modeling and instantiating C-style data structures. This is
|
||||
* not a constructor per-say, but a constructor generator. It takes an array of
|
||||
* tuples, the left side being the type, and the right side being a field name.
|
||||
* The order should be the same order it would appear in the C-style struct
|
||||
* definition. It returns a function that can be used to construct an object that
|
||||
* reads and writes to the data structure using properties specified by the
|
||||
* initial field list.
|
||||
*
|
||||
* The only verboten field names are "ref", which is used used on struct
|
||||
* instances as a function to retrieve the backing Buffer instance of the
|
||||
* struct, and "ref.buffer" which contains the backing Buffer instance.
|
||||
*
|
||||
*
|
||||
* Example:
|
||||
*
|
||||
* ``` javascript
|
||||
* var ref = require('ref')
|
||||
* var Struct = require('ref-struct')
|
||||
*
|
||||
* // create the `char *` type
|
||||
* var charPtr = ref.refType(ref.types.char)
|
||||
* var int = ref.types.int
|
||||
*
|
||||
* // create the struct "type" / constructor
|
||||
* var PasswordEntry = Struct({
|
||||
* 'username': 'string'
|
||||
* , 'password': 'string'
|
||||
* , 'salt': int
|
||||
* })
|
||||
*
|
||||
* // create an instance of the struct, backed a Buffer instance
|
||||
* var pwd = new PasswordEntry()
|
||||
* pwd.username = 'ricky'
|
||||
* pwd.password = 'rbransonlovesnode.js'
|
||||
* pwd.salt = (Math.random() * 1000000) | 0
|
||||
*
|
||||
* pwd.username // → 'ricky'
|
||||
* pwd.password // → 'rbransonlovesnode.js'
|
||||
* pwd.salt // → 820088
|
||||
* ```
|
||||
*/
|
||||
|
||||
/**
|
||||
* Module dependencies.
|
||||
*/
|
||||
|
||||
var ref = require('ref')
|
||||
var util = require('util')
|
||||
var assert = require('assert')
|
||||
var debug = require('debug')('ref:struct')
|
||||
|
||||
/**
|
||||
* Module exports.
|
||||
*/
|
||||
|
||||
module.exports = Struct
|
||||
|
||||
/**
|
||||
* The Struct "type" meta-constructor.
|
||||
*/
|
||||
|
||||
function Struct () {
|
||||
debug('defining new struct "type"')
|
||||
|
||||
/**
|
||||
* This is the "constructor" of the Struct type that gets returned.
|
||||
*
|
||||
* Invoke it with `new` to create a new Buffer instance backing the struct.
|
||||
* Pass it an existing Buffer instance to use that as the backing buffer.
|
||||
* Pass in an Object containing the struct fields to auto-populate the
|
||||
* struct with the data.
|
||||
*/
|
||||
|
||||
function StructType (arg, data) {
|
||||
if (!(this instanceof StructType)) {
|
||||
return new StructType(arg, data)
|
||||
}
|
||||
debug('creating new struct instance')
|
||||
var store
|
||||
if (Buffer.isBuffer(arg)) {
|
||||
debug('using passed-in Buffer instance to back the struct', arg)
|
||||
assert(arg.length >= StructType.size, 'Buffer instance must be at least ' +
|
||||
StructType.size + ' bytes to back this struct type')
|
||||
store = arg
|
||||
arg = data
|
||||
} else {
|
||||
debug('creating new Buffer instance to back the struct (size: %d)', StructType.size)
|
||||
store = new Buffer(StructType.size)
|
||||
}
|
||||
|
||||
// set the backing Buffer store
|
||||
store.type = StructType
|
||||
this['ref.buffer'] = store
|
||||
|
||||
if (arg) {
|
||||
for (var key in arg) {
|
||||
// hopefully hit the struct setters
|
||||
this[key] = arg[key]
|
||||
}
|
||||
}
|
||||
StructType._instanceCreated = true
|
||||
}
|
||||
|
||||
// make instances inherit from the `proto`
|
||||
StructType.prototype = Object.create(proto, {
|
||||
constructor: {
|
||||
value: StructType
|
||||
, enumerable: false
|
||||
, writable: true
|
||||
, configurable: true
|
||||
}
|
||||
})
|
||||
|
||||
StructType.defineProperty = defineProperty
|
||||
StructType.toString = toString
|
||||
StructType.fields = {}
|
||||
|
||||
var opt = (arguments.length > 0 && arguments[1]) ? arguments[1] : {};
|
||||
// Setup the ref "type" interface. The constructor doubles as the "type" object
|
||||
StructType.size = 0
|
||||
StructType.alignment = 0
|
||||
StructType.indirection = 1
|
||||
StructType.isPacked = opt.packed ? Boolean(opt.packed) : false
|
||||
StructType.get = get
|
||||
StructType.set = set
|
||||
|
||||
// Read the fields list and apply all the fields to the struct
|
||||
// TODO: Better arg handling... (maybe look at ES6 binary data API?)
|
||||
var arg = arguments[0]
|
||||
if (Array.isArray(arg)) {
|
||||
// legacy API
|
||||
arg.forEach(function (a) {
|
||||
var type = a[0]
|
||||
var name = a[1]
|
||||
StructType.defineProperty(name, type)
|
||||
})
|
||||
} else if (typeof arg === 'object') {
|
||||
Object.keys(arg).forEach(function (name) {
|
||||
var type = arg[name]
|
||||
StructType.defineProperty(name, type)
|
||||
})
|
||||
}
|
||||
|
||||
return StructType
|
||||
}
|
||||
|
||||
/**
|
||||
* The "get" function of the Struct "type" interface
|
||||
*/
|
||||
|
||||
function get (buffer, offset) {
|
||||
debug('Struct "type" getter for buffer at offset', buffer, offset)
|
||||
if (offset > 0) {
|
||||
buffer = buffer.slice(offset)
|
||||
}
|
||||
return new this(buffer)
|
||||
}
|
||||
|
||||
/**
|
||||
* The "set" function of the Struct "type" interface
|
||||
*/
|
||||
|
||||
function set (buffer, offset, value) {
|
||||
debug('Struct "type" setter for buffer at offset', buffer, offset, value)
|
||||
var isStruct = value instanceof this
|
||||
if (isStruct) {
|
||||
// optimization: copy the buffer contents directly rather
|
||||
// than going through the ref-struct constructor
|
||||
value['ref.buffer'].copy(buffer, offset, 0, this.size)
|
||||
} else {
|
||||
if (offset > 0) {
|
||||
buffer = buffer.slice(offset)
|
||||
}
|
||||
new this(buffer, value)
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Custom `toString()` override for struct type instances.
|
||||
*/
|
||||
|
||||
function toString () {
|
||||
return '[StructType]'
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds a new field to the struct instance with the given name and type.
|
||||
* Note that this function will throw an Error if any instances of the struct
|
||||
* type have already been created, therefore this function must be called at the
|
||||
* beginning, before any instances are created.
|
||||
*/
|
||||
|
||||
function defineProperty (name, type) {
|
||||
debug('defining new struct type field', name)
|
||||
|
||||
// allow string types for convenience
|
||||
type = ref.coerceType(type)
|
||||
|
||||
assert(!this._instanceCreated, 'an instance of this Struct type has already ' +
|
||||
'been created, cannot add new "fields" anymore')
|
||||
assert.equal('string', typeof name, 'expected a "string" field name')
|
||||
assert(type && /object|function/i.test(typeof type) && 'size' in type &&
|
||||
'indirection' in type
|
||||
, 'expected a "type" object describing the field type: "' + type + '"')
|
||||
assert(type.indirection > 1 || type.size > 0,
|
||||
'"type" object must have a size greater than 0')
|
||||
assert(!(name in this.prototype), 'the field "' + name +
|
||||
'" already exists in this Struct type')
|
||||
|
||||
var field = {
|
||||
type: type
|
||||
}
|
||||
this.fields[name] = field
|
||||
|
||||
// define the getter/setter property
|
||||
var desc = { enumerable: true , configurable: true }
|
||||
desc.get = function () {
|
||||
debug('getting "%s" struct field (offset: %d)', name, field.offset)
|
||||
return ref.get(this['ref.buffer'], field.offset, type)
|
||||
}
|
||||
desc.set = function (value) {
|
||||
debug('setting "%s" struct field (offset: %d)', name, field.offset, value)
|
||||
return ref.set(this['ref.buffer'], field.offset, value, type)
|
||||
}
|
||||
|
||||
// calculate the new size and field offsets
|
||||
recalc(this)
|
||||
|
||||
Object.defineProperty(this.prototype, name, desc)
|
||||
}
|
||||
|
||||
function recalc (struct) {
|
||||
|
||||
// reset size and alignment
|
||||
struct.size = 0
|
||||
struct.alignment = 0
|
||||
|
||||
var fieldNames = Object.keys(struct.fields)
|
||||
|
||||
// first loop through is to determine the `alignment` of this struct
|
||||
fieldNames.forEach(function (name) {
|
||||
var field = struct.fields[name]
|
||||
var type = field.type
|
||||
var alignment = type.alignment || ref.alignof.pointer
|
||||
if (type.indirection > 1) {
|
||||
alignment = ref.alignof.pointer
|
||||
}
|
||||
if (struct.isPacked) {
|
||||
struct.alignment = Math.min(struct.alignment || alignment, alignment)
|
||||
} else {
|
||||
struct.alignment = Math.max(struct.alignment, alignment)
|
||||
}
|
||||
})
|
||||
|
||||
// second loop through sets the `offset` property on each "field"
|
||||
// object, and sets the `struct.size` as we go along
|
||||
fieldNames.forEach(function (name) {
|
||||
var field = struct.fields[name]
|
||||
var type = field.type
|
||||
|
||||
if (null != type.fixedLength) {
|
||||
// "ref-array" types set the "fixedLength" prop. don't treat arrays like one
|
||||
// contiguous entity. instead, treat them like individual elements in the
|
||||
// struct. doing this makes the padding end up being calculated correctly.
|
||||
field.offset = addType(type.type)
|
||||
for (var i = 1; i < type.fixedLength; i++) {
|
||||
addType(type.type)
|
||||
}
|
||||
} else {
|
||||
field.offset = addType(type)
|
||||
}
|
||||
})
|
||||
|
||||
function addType (type) {
|
||||
var offset = struct.size
|
||||
var align = type.indirection === 1 ? type.alignment : ref.alignof.pointer
|
||||
var padding = struct.isPacked ? 0 : (align - (offset % align)) % align
|
||||
var size = type.indirection === 1 ? type.size : ref.sizeof.pointer
|
||||
|
||||
offset += padding
|
||||
|
||||
if (!struct.isPacked) {
|
||||
assert.equal(offset % align, 0, "offset should align")
|
||||
}
|
||||
|
||||
// adjust the "size" of the struct type
|
||||
struct.size = offset + size
|
||||
|
||||
// return the calulated offset
|
||||
return offset
|
||||
}
|
||||
|
||||
// any final padding?
|
||||
var left = struct.size % struct.alignment
|
||||
if (left > 0) {
|
||||
debug('additional padding to the end of struct:', struct.alignment - left)
|
||||
struct.size += struct.alignment - left
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* this is the custom prototype of Struct type instances.
|
||||
*/
|
||||
|
||||
var proto = {}
|
||||
|
||||
/**
|
||||
* set a placeholder variable on the prototype so that defineProperty() will
|
||||
* throw an error if you try to define a struct field with the name "buffer".
|
||||
*/
|
||||
|
||||
proto['ref.buffer'] = ref.NULL
|
||||
|
||||
/**
|
||||
* Flattens the Struct instance into a regular JavaScript Object. This function
|
||||
* "gets" all the defined properties.
|
||||
*
|
||||
* @api public
|
||||
*/
|
||||
|
||||
proto.toObject = function toObject () {
|
||||
var obj = {}
|
||||
Object.keys(this.constructor.fields).forEach(function (k) {
|
||||
obj[k] = this[k]
|
||||
}, this)
|
||||
return obj
|
||||
}
|
||||
|
||||
/**
|
||||
* Basic `JSON.stringify(struct)` support.
|
||||
*/
|
||||
|
||||
proto.toJSON = function toJSON () {
|
||||
return this.toObject()
|
||||
}
|
||||
|
||||
/**
|
||||
* `.inspect()` override. For the REPL.
|
||||
*
|
||||
* @api public
|
||||
*/
|
||||
|
||||
proto.inspect = function inspect () {
|
||||
var obj = this.toObject()
|
||||
// add instance's "own properties"
|
||||
Object.keys(this).forEach(function (k) {
|
||||
obj[k] = this[k]
|
||||
}, this)
|
||||
return util.inspect(obj)
|
||||
}
|
||||
|
||||
/**
|
||||
* returns a Buffer pointing to this struct data structure.
|
||||
*/
|
||||
|
||||
proto.ref = function ref () {
|
||||
return this['ref.buffer']
|
||||
}
|
66
node_modules/ref-struct/package.json
generated
vendored
Normal file
66
node_modules/ref-struct/package.json
generated
vendored
Normal file
@ -0,0 +1,66 @@
|
||||
{
|
||||
"_from": "ref-struct@*",
|
||||
"_id": "ref-struct@1.1.0",
|
||||
"_inBundle": false,
|
||||
"_integrity": "sha1-XV7mWtQc78Olxf60BYcmHkee3BM=",
|
||||
"_location": "/ref-struct",
|
||||
"_phantomChildren": {},
|
||||
"_requested": {
|
||||
"type": "range",
|
||||
"registry": true,
|
||||
"raw": "ref-struct@*",
|
||||
"name": "ref-struct",
|
||||
"escapedName": "ref-struct",
|
||||
"rawSpec": "*",
|
||||
"saveSpec": null,
|
||||
"fetchSpec": "*"
|
||||
},
|
||||
"_requiredBy": [
|
||||
"/ogg-packet"
|
||||
],
|
||||
"_resolved": "https://registry.npmjs.org/ref-struct/-/ref-struct-1.1.0.tgz",
|
||||
"_shasum": "5d5ee65ad41cefc3a5c5feb40587261e479edc13",
|
||||
"_spec": "ref-struct@*",
|
||||
"_where": "/home/sergiu/linx-audio-simulator/node_modules/ogg-packet",
|
||||
"author": {
|
||||
"name": "Nathan Rajlich",
|
||||
"email": "nathan@tootallnate.net",
|
||||
"url": "http://tootallnate.net"
|
||||
},
|
||||
"bugs": {
|
||||
"url": "https://github.com/TooTallNate/ref-struct/issues"
|
||||
},
|
||||
"bundleDependencies": false,
|
||||
"dependencies": {
|
||||
"debug": "2",
|
||||
"ref": "1"
|
||||
},
|
||||
"deprecated": false,
|
||||
"description": "Create ABI-compliant \"struct\" instances on top of Buffers",
|
||||
"devDependencies": {
|
||||
"bindings": "~1.2.0",
|
||||
"mocha": "*",
|
||||
"nan": "2",
|
||||
"ref-array": "~1.1.2"
|
||||
},
|
||||
"homepage": "https://github.com/TooTallNate/ref-struct#readme",
|
||||
"keywords": [
|
||||
"struct",
|
||||
"ref",
|
||||
"abi",
|
||||
"c",
|
||||
"c++",
|
||||
"ffi"
|
||||
],
|
||||
"license": "MIT",
|
||||
"main": "./lib/struct.js",
|
||||
"name": "ref-struct",
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "git://github.com/TooTallNate/ref-struct.git"
|
||||
},
|
||||
"scripts": {
|
||||
"test": "node-gyp rebuild --directory test && mocha -gc --reporter spec"
|
||||
},
|
||||
"version": "1.1.0"
|
||||
}
|
Reference in New Issue
Block a user