UNPKG

structjs

Version:

**Structjs** allows mapping of contiguously allocated binary data to JavaScript objects for both Node.js and the Browser.

33 lines (31 loc) 967 B
var StructReference = require('./types/reference') exports.methodsFor = function(obj, prop, get, set) { obj[get] = function(parent) { if (!this[prop]) return 0 if (this[prop] instanceof StructReference) return parent[this[prop].prop] else if (typeof this[prop] === 'function') return this[prop].call(parent) return this[prop] } if (!set) return obj[set] = function(value, parent) { if (this[prop] instanceof StructReference) parent[this[prop].prop] = value else this[prop] = value } } exports.options = function(opts) { if (typeof opts === 'object') { this._offset = opts.offset this._length = opts.length this._size = opts.size this.$unpacked = opts.$unpacked this.$packing = opts.$packing this.external = opts.external === true this.storage = opts.storage this.littleEndian = opts.littleEndian === true } else { this._length = opts } }