restructure
Advanced tools
Comparing version
65
index.js
@@ -1,43 +0,26 @@ | ||
// Generated by CoffeeScript 1.7.1 | ||
(function() { | ||
var key, val, _ref, _ref1; | ||
let key, val; | ||
exports.EncodeStream = require('./src/EncodeStream'); | ||
exports.DecodeStream = require('./src/DecodeStream'); | ||
exports.Array = require('./src/Array'); | ||
exports.LazyArray = require('./src/LazyArray'); | ||
exports.Bitfield = require('./src/Bitfield'); | ||
exports.Boolean = require('./src/Boolean'); | ||
exports.Buffer = require('./src/Buffer'); | ||
exports.Enum = require('./src/Enum'); | ||
exports.Optional = require('./src/Optional'); | ||
exports.Reserved = require('./src/Reserved'); | ||
exports.String = require('./src/String'); | ||
exports.Struct = require('./src/Struct'); | ||
exports.VersionedStruct = require('./src/VersionedStruct'); | ||
exports.EncodeStream = require('./src/EncodeStream'); | ||
const object = require('./src/Number'); | ||
for (key in object) { | ||
val = object[key]; | ||
exports[key] = val; | ||
} | ||
exports.DecodeStream = require('./src/DecodeStream'); | ||
exports.Array = require('./src/Array'); | ||
exports.LazyArray = require('./src/LazyArray'); | ||
exports.Bitfield = require('./src/Bitfield'); | ||
exports.Boolean = require('./src/Boolean'); | ||
exports.Buffer = require('./src/Buffer'); | ||
exports.Enum = require('./src/Enum'); | ||
exports.Optional = require('./src/Optional'); | ||
exports.Reserved = require('./src/Reserved'); | ||
exports.String = require('./src/String'); | ||
exports.Struct = require('./src/Struct'); | ||
exports.VersionedStruct = require('./src/VersionedStruct'); | ||
_ref = require('./src/Number'); | ||
for (key in _ref) { | ||
val = _ref[key]; | ||
exports[key] = val; | ||
} | ||
_ref1 = require('./src/Pointer'); | ||
for (key in _ref1) { | ||
val = _ref1[key]; | ||
exports[key] = val; | ||
} | ||
}).call(this); | ||
const object1 = require('./src/Pointer'); | ||
for (key in object1) { | ||
val = object1[key]; | ||
exports[key] = val; | ||
} |
{ | ||
"name": "restructure", | ||
"version": "0.5.4", | ||
"version": "1.0.0", | ||
"description": "Declaratively encode and decode binary data", | ||
@@ -11,9 +11,7 @@ "main": "index.js", | ||
"chai": "~1.9.1", | ||
"coffee-coverage": "~0.4.2", | ||
"coffee-script": "~1.7.1", | ||
"concat-stream": "~1.4.5", | ||
"coveralls": "^2.10.0", | ||
"coveralls": "^3.0.3", | ||
"iconv-lite": "^0.4.7", | ||
"mocha": "~1.18.2", | ||
"mocha-lcov-reporter": "0.0.1" | ||
"mocha": "~6.0.2", | ||
"nyc": "^13.3.0" | ||
}, | ||
@@ -27,6 +25,4 @@ "browserify": { | ||
"test": "mocha", | ||
"cover": "mocha --require coverage.js --reporter html-cov > coverage.html", | ||
"coveralls": "mocha --require coverage.js --reporter mocha-lcov-reporter | coveralls", | ||
"prepublish": "coffee -c src/ index.coffee", | ||
"postpublish": "rm -rf index.js src/*.js" | ||
"cover": "nyc --reporter=html --reporter=text mocha", | ||
"coveralls": "nyc report --reporter=text-lcov | coveralls" | ||
}, | ||
@@ -33,0 +29,0 @@ "repository": { |
180
src/Array.js
@@ -1,105 +0,101 @@ | ||
// Generated by CoffeeScript 1.7.1 | ||
(function() { | ||
var ArrayT, NumberT, utils; | ||
const {Number:NumberT} = require('./Number'); | ||
const utils = require('./utils'); | ||
NumberT = require('./Number').Number; | ||
class ArrayT { | ||
constructor(type, length, lengthType = 'count') { | ||
this.type = type; | ||
this.length = length; | ||
this.lengthType = lengthType; | ||
} | ||
utils = require('./utils'); | ||
decode(stream, parent) { | ||
let length; | ||
const { pos } = stream; | ||
ArrayT = (function() { | ||
function ArrayT(type, length, lengthType) { | ||
this.type = type; | ||
this.length = length; | ||
this.lengthType = lengthType != null ? lengthType : 'count'; | ||
const res = []; | ||
let ctx = parent; | ||
if (this.length != null) { | ||
length = utils.resolveLength(this.length, stream, parent); | ||
} | ||
ArrayT.prototype.decode = function(stream, parent) { | ||
var ctx, i, length, pos, res, target, _i; | ||
pos = stream.pos; | ||
res = []; | ||
ctx = parent; | ||
if (this.length != null) { | ||
length = utils.resolveLength(this.length, stream, parent); | ||
} | ||
if (this.length instanceof NumberT) { | ||
Object.defineProperties(res, { | ||
parent: { | ||
value: parent | ||
}, | ||
_startOffset: { | ||
value: pos | ||
}, | ||
_currentOffset: { | ||
value: 0, | ||
writable: true | ||
}, | ||
_length: { | ||
value: length | ||
} | ||
}); | ||
ctx = res; | ||
} | ||
if ((length == null) || this.lengthType === 'bytes') { | ||
target = length != null ? stream.pos + length : (parent != null ? parent._length : void 0) ? parent._startOffset + parent._length : stream.length; | ||
while (stream.pos < target) { | ||
res.push(this.type.decode(stream, ctx)); | ||
} | ||
} else { | ||
for (i = _i = 0; _i < length; i = _i += 1) { | ||
res.push(this.type.decode(stream, ctx)); | ||
} | ||
} | ||
return res; | ||
}; | ||
if (this.length instanceof NumberT) { | ||
// define hidden properties | ||
Object.defineProperties(res, { | ||
parent: { value: parent }, | ||
_startOffset: { value: pos }, | ||
_currentOffset: { value: 0, writable: true }, | ||
_length: { value: length } | ||
}); | ||
ArrayT.prototype.size = function(array, ctx) { | ||
var item, size, _i, _len; | ||
if (!array) { | ||
return this.type.size(null, ctx) * utils.resolveLength(this.length, null, ctx); | ||
ctx = res; | ||
} | ||
if ((length == null) || (this.lengthType === 'bytes')) { | ||
const target = (length != null) ? | ||
stream.pos + length | ||
: (parent != null ? parent._length : undefined) ? | ||
parent._startOffset + parent._length | ||
: | ||
stream.length; | ||
while (stream.pos < target) { | ||
res.push(this.type.decode(stream, ctx)); | ||
} | ||
size = 0; | ||
if (this.length instanceof NumberT) { | ||
size += this.length.size(); | ||
ctx = { | ||
parent: ctx | ||
}; | ||
} | ||
for (_i = 0, _len = array.length; _i < _len; _i++) { | ||
item = array[_i]; | ||
size += this.type.size(item, ctx); | ||
} | ||
return size; | ||
}; | ||
ArrayT.prototype.encode = function(stream, array, parent) { | ||
var ctx, i, item, ptr, _i, _len; | ||
ctx = parent; | ||
if (this.length instanceof NumberT) { | ||
ctx = { | ||
pointers: [], | ||
startOffset: stream.pos, | ||
parent: parent | ||
}; | ||
ctx.pointerOffset = stream.pos + this.size(array, ctx); | ||
this.length.encode(stream, array.length); | ||
} else { | ||
for (let i = 0, end = length; i < end; i++) { | ||
res.push(this.type.decode(stream, ctx)); | ||
} | ||
for (_i = 0, _len = array.length; _i < _len; _i++) { | ||
item = array[_i]; | ||
this.type.encode(stream, item, ctx); | ||
} | ||
if (this.length instanceof NumberT) { | ||
i = 0; | ||
while (i < ctx.pointers.length) { | ||
ptr = ctx.pointers[i++]; | ||
ptr.type.encode(stream, ptr.val); | ||
} | ||
} | ||
}; | ||
} | ||
return ArrayT; | ||
return res; | ||
} | ||
})(); | ||
size(array, ctx) { | ||
if (!array) { | ||
return this.type.size(null, ctx) * utils.resolveLength(this.length, null, ctx); | ||
} | ||
module.exports = ArrayT; | ||
let size = 0; | ||
if (this.length instanceof NumberT) { | ||
size += this.length.size(); | ||
ctx = {parent: ctx}; | ||
} | ||
}).call(this); | ||
for (let item of array) { | ||
size += this.type.size(item, ctx); | ||
} | ||
return size; | ||
} | ||
encode(stream, array, parent) { | ||
let ctx = parent; | ||
if (this.length instanceof NumberT) { | ||
ctx = { | ||
pointers: [], | ||
startOffset: stream.pos, | ||
parent | ||
}; | ||
ctx.pointerOffset = stream.pos + this.size(array, ctx); | ||
this.length.encode(stream, array.length); | ||
} | ||
for (let item of array) { | ||
this.type.encode(stream, item, ctx); | ||
} | ||
if (this.length instanceof NumberT) { | ||
let i = 0; | ||
while (i < ctx.pointers.length) { | ||
const ptr = ctx.pointers[i++]; | ||
ptr.type.encode(stream, ptr.val); | ||
} | ||
} | ||
} | ||
} | ||
module.exports = ArrayT; |
@@ -1,50 +0,37 @@ | ||
// Generated by CoffeeScript 1.7.1 | ||
(function() { | ||
var Bitfield; | ||
class Bitfield { | ||
constructor(type, flags = []) { | ||
this.type = type; | ||
this.flags = flags; | ||
} | ||
decode(stream) { | ||
const val = this.type.decode(stream); | ||
Bitfield = (function() { | ||
function Bitfield(type, flags) { | ||
this.type = type; | ||
this.flags = flags != null ? flags : []; | ||
const res = {}; | ||
for (let i = 0; i < this.flags.length; i++) { | ||
const flag = this.flags[i]; | ||
if (flag != null) { | ||
res[flag] = !!(val & (1 << i)); | ||
} | ||
} | ||
Bitfield.prototype.decode = function(stream) { | ||
var flag, i, res, val, _i, _len, _ref; | ||
val = this.type.decode(stream); | ||
res = {}; | ||
_ref = this.flags; | ||
for (i = _i = 0, _len = _ref.length; _i < _len; i = ++_i) { | ||
flag = _ref[i]; | ||
if (flag != null) { | ||
res[flag] = !!(val & (1 << i)); | ||
} | ||
} | ||
return res; | ||
}; | ||
return res; | ||
} | ||
Bitfield.prototype.size = function() { | ||
return this.type.size(); | ||
}; | ||
size() { | ||
return this.type.size(); | ||
} | ||
Bitfield.prototype.encode = function(stream, keys) { | ||
var flag, i, val, _i, _len, _ref; | ||
val = 0; | ||
_ref = this.flags; | ||
for (i = _i = 0, _len = _ref.length; _i < _len; i = ++_i) { | ||
flag = _ref[i]; | ||
if (flag != null) { | ||
if (keys[flag]) { | ||
val |= 1 << i; | ||
} | ||
} | ||
encode(stream, keys) { | ||
let val = 0; | ||
for (let i = 0; i < this.flags.length; i++) { | ||
const flag = this.flags[i]; | ||
if (flag != null) { | ||
if (keys[flag]) { val |= (1 << i); } | ||
} | ||
return this.type.encode(stream, val); | ||
}; | ||
} | ||
return Bitfield; | ||
return this.type.encode(stream, val); | ||
} | ||
} | ||
})(); | ||
module.exports = Bitfield; | ||
}).call(this); | ||
module.exports = Bitfield; |
@@ -1,28 +0,19 @@ | ||
// Generated by CoffeeScript 1.7.1 | ||
(function() { | ||
var BooleanT; | ||
class BooleanT { | ||
constructor(type) { | ||
this.type = type; | ||
} | ||
BooleanT = (function() { | ||
function BooleanT(type) { | ||
this.type = type; | ||
} | ||
decode(stream, parent) { | ||
return !!this.type.decode(stream, parent); | ||
} | ||
BooleanT.prototype.decode = function(stream, parent) { | ||
return !!this.type.decode(stream, parent); | ||
}; | ||
size(val, parent) { | ||
return this.type.size(val, parent); | ||
} | ||
BooleanT.prototype.size = function(val, parent) { | ||
return this.type.size(val, parent); | ||
}; | ||
encode(stream, val, parent) { | ||
return this.type.encode(stream, +val, parent); | ||
} | ||
} | ||
BooleanT.prototype.encode = function(stream, val, parent) { | ||
return this.type.encode(stream, +val, parent); | ||
}; | ||
return BooleanT; | ||
})(); | ||
module.exports = BooleanT; | ||
}).call(this); | ||
module.exports = BooleanT; |
@@ -1,40 +0,30 @@ | ||
// Generated by CoffeeScript 1.7.1 | ||
(function() { | ||
var BufferT, NumberT, utils; | ||
const utils = require('./utils'); | ||
const {Number:NumberT} = require('./Number'); | ||
utils = require('./utils'); | ||
class BufferT { | ||
constructor(length) { | ||
this.length = length; | ||
} | ||
decode(stream, parent) { | ||
const length = utils.resolveLength(this.length, stream, parent); | ||
return stream.readBuffer(length); | ||
} | ||
NumberT = require('./Number').Number; | ||
size(val, parent) { | ||
if (!val) { | ||
return utils.resolveLength(this.length, null, parent); | ||
} | ||
return val.length; | ||
} | ||
BufferT = (function() { | ||
function BufferT(length) { | ||
this.length = length; | ||
encode(stream, buf, parent) { | ||
if (this.length instanceof NumberT) { | ||
this.length.encode(stream, buf.length); | ||
} | ||
return stream.writeBuffer(buf); | ||
} | ||
} | ||
BufferT.prototype.decode = function(stream, parent) { | ||
var length; | ||
length = utils.resolveLength(this.length, stream, parent); | ||
return stream.readBuffer(length); | ||
}; | ||
BufferT.prototype.size = function(val, parent) { | ||
if (!val) { | ||
return utils.resolveLength(this.length, null, parent); | ||
} | ||
return val.length; | ||
}; | ||
BufferT.prototype.encode = function(stream, buf, parent) { | ||
if (this.length instanceof NumberT) { | ||
this.length.encode(stream, buf.length); | ||
} | ||
return stream.writeBuffer(buf); | ||
}; | ||
return BufferT; | ||
})(); | ||
module.exports = BufferT; | ||
}).call(this); | ||
module.exports = BufferT; |
@@ -1,102 +0,85 @@ | ||
// Generated by CoffeeScript 1.7.1 | ||
(function() { | ||
var DecodeStream, iconv; | ||
let iconv; | ||
try { iconv = require('iconv-lite'); } catch (error) {} | ||
try { | ||
iconv = require('iconv-lite'); | ||
} catch (_error) {} | ||
class DecodeStream { | ||
constructor(buffer) { | ||
this.buffer = buffer; | ||
this.pos = 0; | ||
this.length = this.buffer.length; | ||
} | ||
DecodeStream = (function() { | ||
var key; | ||
readString(length, encoding = 'ascii') { | ||
switch (encoding) { | ||
case 'utf16le': case 'ucs2': case 'utf8': case 'ascii': | ||
return this.buffer.toString(encoding, this.pos, (this.pos += length)); | ||
function DecodeStream(buffer) { | ||
this.buffer = buffer; | ||
this.pos = 0; | ||
this.length = this.buffer.length; | ||
} | ||
case 'utf16be': | ||
var buf = new Buffer(this.readBuffer(length)); | ||
DecodeStream.TYPES = { | ||
UInt8: 1, | ||
UInt16: 2, | ||
UInt24: 3, | ||
UInt32: 4, | ||
Int8: 1, | ||
Int16: 2, | ||
Int24: 3, | ||
Int32: 4, | ||
Float: 4, | ||
Double: 8 | ||
}; | ||
// swap the bytes | ||
for (let i = 0, end = buf.length - 1; i < end; i += 2) { | ||
const byte = buf[i]; | ||
buf[i] = buf[i + 1]; | ||
buf[i + 1] = byte; | ||
} | ||
for (key in Buffer.prototype) { | ||
if (key.slice(0, 4) === 'read') { | ||
(function(key) { | ||
var bytes; | ||
bytes = DecodeStream.TYPES[key.replace(/read|[BL]E/g, '')]; | ||
return DecodeStream.prototype[key] = function() { | ||
var ret; | ||
ret = this.buffer[key](this.pos); | ||
this.pos += bytes; | ||
return ret; | ||
}; | ||
})(key); | ||
} | ||
} | ||
return buf.toString('utf16le'); | ||
DecodeStream.prototype.readString = function(length, encoding) { | ||
var buf, byte, i, _i, _ref; | ||
if (encoding == null) { | ||
encoding = 'ascii'; | ||
} | ||
switch (encoding) { | ||
case 'utf16le': | ||
case 'ucs2': | ||
case 'utf8': | ||
case 'ascii': | ||
return this.buffer.toString(encoding, this.pos, this.pos += length); | ||
case 'utf16be': | ||
buf = new Buffer(this.readBuffer(length)); | ||
for (i = _i = 0, _ref = buf.length - 1; _i < _ref; i = _i += 2) { | ||
byte = buf[i]; | ||
buf[i] = buf[i + 1]; | ||
buf[i + 1] = byte; | ||
} | ||
return buf.toString('utf16le'); | ||
default: | ||
buf = this.readBuffer(length); | ||
if (iconv) { | ||
try { | ||
return iconv.decode(buf, encoding); | ||
} catch (_error) {} | ||
} | ||
return buf; | ||
} | ||
}; | ||
default: | ||
buf = this.readBuffer(length); | ||
if (iconv) { | ||
try { | ||
return iconv.decode(buf, encoding); | ||
} catch (error1) {} | ||
} | ||
DecodeStream.prototype.readBuffer = function(length) { | ||
return this.buffer.slice(this.pos, this.pos += length); | ||
}; | ||
return buf; | ||
} | ||
} | ||
DecodeStream.prototype.readUInt24BE = function() { | ||
return (this.readUInt16BE() << 8) + this.readUInt8(); | ||
}; | ||
readBuffer(length) { | ||
return this.buffer.slice(this.pos, (this.pos += length)); | ||
} | ||
DecodeStream.prototype.readUInt24LE = function() { | ||
return this.readUInt16LE() + (this.readUInt8() << 16); | ||
}; | ||
readUInt24BE() { | ||
return (this.readUInt16BE() << 8) + this.readUInt8(); | ||
} | ||
DecodeStream.prototype.readInt24BE = function() { | ||
return (this.readInt16BE() << 8) + this.readUInt8(); | ||
}; | ||
readUInt24LE() { | ||
return this.readUInt16LE() + (this.readUInt8() << 16); | ||
} | ||
DecodeStream.prototype.readInt24LE = function() { | ||
return this.readUInt16LE() + (this.readInt8() << 16); | ||
}; | ||
readInt24BE() { | ||
return (this.readInt16BE() << 8) + this.readUInt8(); | ||
} | ||
return DecodeStream; | ||
readInt24LE() { | ||
return this.readUInt16LE() + (this.readInt8() << 16); | ||
} | ||
} | ||
})(); | ||
DecodeStream.TYPES = { | ||
UInt8: 1, | ||
UInt16: 2, | ||
UInt24: 3, | ||
UInt32: 4, | ||
Int8: 1, | ||
Int16: 2, | ||
Int24: 3, | ||
Int32: 4, | ||
Float: 4, | ||
Double: 8 | ||
}; | ||
module.exports = DecodeStream; | ||
for (let key in Buffer.prototype) { | ||
if (key.slice(0, 4) === 'read') { | ||
const bytes = DecodeStream.TYPES[key.replace(/read|[BL]E/g, '')]; | ||
DecodeStream.prototype[key] = function() { | ||
const ret = this.buffer[key](this.pos); | ||
this.pos += bytes; | ||
return ret; | ||
}; | ||
} | ||
} | ||
}).call(this); | ||
module.exports = DecodeStream; |
@@ -1,151 +0,125 @@ | ||
// Generated by CoffeeScript 1.7.1 | ||
(function() { | ||
var DecodeStream, EncodeStream, iconv, stream, | ||
__hasProp = {}.hasOwnProperty, | ||
__extends = function(child, parent) { for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; }; | ||
let iconv; | ||
const stream = require('stream'); | ||
const DecodeStream = require('./DecodeStream'); | ||
try { iconv = require('iconv-lite'); } catch (error) {} | ||
stream = require('stream'); | ||
class EncodeStream extends stream.Readable { | ||
constructor(bufferSize = 65536) { | ||
super(...arguments); | ||
this.buffer = new Buffer(bufferSize); | ||
this.bufferOffset = 0; | ||
this.pos = 0; | ||
} | ||
DecodeStream = require('./DecodeStream'); | ||
_read() {} | ||
// do nothing, required by node | ||
try { | ||
iconv = require('iconv-lite'); | ||
} catch (_error) {} | ||
EncodeStream = (function(_super) { | ||
var key; | ||
__extends(EncodeStream, _super); | ||
function EncodeStream(bufferSize) { | ||
if (bufferSize == null) { | ||
bufferSize = 65536; | ||
} | ||
EncodeStream.__super__.constructor.apply(this, arguments); | ||
this.buffer = new Buffer(bufferSize); | ||
this.bufferOffset = 0; | ||
this.pos = 0; | ||
ensure(bytes) { | ||
if ((this.bufferOffset + bytes) > this.buffer.length) { | ||
return this.flush(); | ||
} | ||
for (key in Buffer.prototype) { | ||
if (key.slice(0, 5) === 'write') { | ||
(function(key) { | ||
var bytes; | ||
bytes = +DecodeStream.TYPES[key.replace(/write|[BL]E/g, '')]; | ||
return EncodeStream.prototype[key] = function(value) { | ||
this.ensure(bytes); | ||
this.buffer[key](value, this.bufferOffset); | ||
this.bufferOffset += bytes; | ||
return this.pos += bytes; | ||
}; | ||
})(key); | ||
} | ||
} | ||
flush() { | ||
if (this.bufferOffset > 0) { | ||
this.push(new Buffer(this.buffer.slice(0, this.bufferOffset))); | ||
return this.bufferOffset = 0; | ||
} | ||
} | ||
EncodeStream.prototype._read = function() {}; | ||
writeBuffer(buffer) { | ||
this.flush(); | ||
this.push(buffer); | ||
return this.pos += buffer.length; | ||
} | ||
EncodeStream.prototype.ensure = function(bytes) { | ||
if (this.bufferOffset + bytes > this.buffer.length) { | ||
return this.flush(); | ||
} | ||
}; | ||
writeString(string, encoding = 'ascii') { | ||
switch (encoding) { | ||
case 'utf16le': case 'ucs2': case 'utf8': case 'ascii': | ||
return this.writeBuffer(new Buffer(string, encoding)); | ||
EncodeStream.prototype.flush = function() { | ||
if (this.bufferOffset > 0) { | ||
this.push(new Buffer(this.buffer.slice(0, this.bufferOffset))); | ||
return this.bufferOffset = 0; | ||
} | ||
}; | ||
case 'utf16be': | ||
var buf = new Buffer(string, 'utf16le'); | ||
EncodeStream.prototype.writeBuffer = function(buffer) { | ||
this.flush(); | ||
this.push(buffer); | ||
return this.pos += buffer.length; | ||
}; | ||
// swap the bytes | ||
for (let i = 0, end = buf.length - 1; i < end; i += 2) { | ||
const byte = buf[i]; | ||
buf[i] = buf[i + 1]; | ||
buf[i + 1] = byte; | ||
} | ||
EncodeStream.prototype.writeString = function(string, encoding) { | ||
var buf, byte, i, _i, _ref; | ||
if (encoding == null) { | ||
encoding = 'ascii'; | ||
} | ||
switch (encoding) { | ||
case 'utf16le': | ||
case 'ucs2': | ||
case 'utf8': | ||
case 'ascii': | ||
return this.writeBuffer(new Buffer(string, encoding)); | ||
case 'utf16be': | ||
buf = new Buffer(string, 'utf16le'); | ||
for (i = _i = 0, _ref = buf.length - 1; _i < _ref; i = _i += 2) { | ||
byte = buf[i]; | ||
buf[i] = buf[i + 1]; | ||
buf[i + 1] = byte; | ||
} | ||
return this.writeBuffer(buf); | ||
default: | ||
if (iconv) { | ||
return this.writeBuffer(iconv.encode(string, encoding)); | ||
} else { | ||
throw new Error('Install iconv-lite to enable additional string encodings.'); | ||
} | ||
} | ||
}; | ||
return this.writeBuffer(buf); | ||
EncodeStream.prototype.writeUInt24BE = function(val) { | ||
this.ensure(3); | ||
this.buffer[this.bufferOffset++] = val >>> 16 & 0xff; | ||
this.buffer[this.bufferOffset++] = val >>> 8 & 0xff; | ||
this.buffer[this.bufferOffset++] = val & 0xff; | ||
return this.pos += 3; | ||
}; | ||
default: | ||
if (iconv) { | ||
return this.writeBuffer(iconv.encode(string, encoding)); | ||
} else { | ||
throw new Error('Install iconv-lite to enable additional string encodings.'); | ||
} | ||
} | ||
} | ||
EncodeStream.prototype.writeUInt24LE = function(val) { | ||
this.ensure(3); | ||
this.buffer[this.bufferOffset++] = val & 0xff; | ||
this.buffer[this.bufferOffset++] = val >>> 8 & 0xff; | ||
this.buffer[this.bufferOffset++] = val >>> 16 & 0xff; | ||
return this.pos += 3; | ||
}; | ||
writeUInt24BE(val) { | ||
this.ensure(3); | ||
this.buffer[this.bufferOffset++] = (val >>> 16) & 0xff; | ||
this.buffer[this.bufferOffset++] = (val >>> 8) & 0xff; | ||
this.buffer[this.bufferOffset++] = val & 0xff; | ||
return this.pos += 3; | ||
} | ||
EncodeStream.prototype.writeInt24BE = function(val) { | ||
if (val >= 0) { | ||
return this.writeUInt24BE(val); | ||
} else { | ||
return this.writeUInt24BE(val + 0xffffff + 1); | ||
} | ||
}; | ||
writeUInt24LE(val) { | ||
this.ensure(3); | ||
this.buffer[this.bufferOffset++] = val & 0xff; | ||
this.buffer[this.bufferOffset++] = (val >>> 8) & 0xff; | ||
this.buffer[this.bufferOffset++] = (val >>> 16) & 0xff; | ||
return this.pos += 3; | ||
} | ||
EncodeStream.prototype.writeInt24LE = function(val) { | ||
if (val >= 0) { | ||
return this.writeUInt24LE(val); | ||
} else { | ||
return this.writeUInt24LE(val + 0xffffff + 1); | ||
} | ||
}; | ||
writeInt24BE(val) { | ||
if (val >= 0) { | ||
return this.writeUInt24BE(val); | ||
} else { | ||
return this.writeUInt24BE(val + 0xffffff + 1); | ||
} | ||
} | ||
EncodeStream.prototype.fill = function(val, length) { | ||
var buf; | ||
if (length < this.buffer.length) { | ||
this.ensure(length); | ||
this.buffer.fill(val, this.bufferOffset, this.bufferOffset + length); | ||
this.bufferOffset += length; | ||
return this.pos += length; | ||
} else { | ||
buf = new Buffer(length); | ||
buf.fill(val); | ||
return this.writeBuffer(buf); | ||
} | ||
}; | ||
writeInt24LE(val) { | ||
if (val >= 0) { | ||
return this.writeUInt24LE(val); | ||
} else { | ||
return this.writeUInt24LE(val + 0xffffff + 1); | ||
} | ||
} | ||
EncodeStream.prototype.end = function() { | ||
this.flush(); | ||
return this.push(null); | ||
}; | ||
fill(val, length) { | ||
if (length < this.buffer.length) { | ||
this.ensure(length); | ||
this.buffer.fill(val, this.bufferOffset, this.bufferOffset + length); | ||
this.bufferOffset += length; | ||
return this.pos += length; | ||
} else { | ||
const buf = new Buffer(length); | ||
buf.fill(val); | ||
return this.writeBuffer(buf); | ||
} | ||
} | ||
return EncodeStream; | ||
end() { | ||
this.flush(); | ||
return this.push(null); | ||
} | ||
} | ||
})(stream.Readable); | ||
for (let key in Buffer.prototype) { | ||
if (key.slice(0, 5) === 'write') { | ||
const bytes = +DecodeStream.TYPES[key.replace(/write|[BL]E/g, '')]; | ||
EncodeStream.prototype[key] = function(value) { | ||
this.ensure(bytes); | ||
this.buffer[key](value, this.bufferOffset); | ||
this.bufferOffset += bytes; | ||
return this.pos += bytes; | ||
}; | ||
} | ||
} | ||
module.exports = EncodeStream; | ||
}).call(this); | ||
module.exports = EncodeStream; |
@@ -1,36 +0,25 @@ | ||
// Generated by CoffeeScript 1.7.1 | ||
(function() { | ||
var Enum; | ||
class Enum { | ||
constructor(type, options = []) { | ||
this.type = type; | ||
this.options = options; | ||
} | ||
decode(stream) { | ||
const index = this.type.decode(stream); | ||
return this.options[index] || index; | ||
} | ||
Enum = (function() { | ||
function Enum(type, options) { | ||
this.type = type; | ||
this.options = options != null ? options : []; | ||
size() { | ||
return this.type.size(); | ||
} | ||
encode(stream, val) { | ||
const index = this.options.indexOf(val); | ||
if (index === -1) { | ||
throw new Error(`Unknown option in enum: ${val}`); | ||
} | ||
Enum.prototype.decode = function(stream) { | ||
var index; | ||
index = this.type.decode(stream); | ||
return this.options[index] || index; | ||
}; | ||
return this.type.encode(stream, index); | ||
} | ||
} | ||
Enum.prototype.size = function() { | ||
return this.type.size(); | ||
}; | ||
Enum.prototype.encode = function(stream, val) { | ||
var index; | ||
index = this.options.indexOf(val); | ||
if (index === -1) { | ||
throw new Error("Unknown option in enum: " + val); | ||
} | ||
return this.type.encode(stream, index); | ||
}; | ||
return Enum; | ||
})(); | ||
module.exports = Enum; | ||
}).call(this); | ||
module.exports = Enum; |
@@ -1,100 +0,81 @@ | ||
// Generated by CoffeeScript 1.7.1 | ||
(function() { | ||
var ArrayT, LazyArray, LazyArrayT, NumberT, inspect, utils, | ||
__hasProp = {}.hasOwnProperty, | ||
__extends = function(child, parent) { for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; }; | ||
const ArrayT = require('./Array'); | ||
const {Number:NumberT} = require('./Number'); | ||
const utils = require('./utils'); | ||
const {inspect} = require('util'); | ||
ArrayT = require('./Array'); | ||
NumberT = require('./Number').Number; | ||
utils = require('./utils'); | ||
inspect = require('util').inspect; | ||
LazyArrayT = (function(_super) { | ||
__extends(LazyArrayT, _super); | ||
function LazyArrayT() { | ||
return LazyArrayT.__super__.constructor.apply(this, arguments); | ||
class LazyArrayT extends ArrayT { | ||
decode(stream, parent) { | ||
const { pos } = stream; | ||
const length = utils.resolveLength(this.length, stream, parent); | ||
if (this.length instanceof NumberT) { | ||
parent = { | ||
parent, | ||
_startOffset: pos, | ||
_currentOffset: 0, | ||
_length: length | ||
}; | ||
} | ||
const res = new LazyArray(this.type, length, stream, parent); | ||
stream.pos += length * this.type.size(null, parent); | ||
return res; | ||
} | ||
size(val, ctx) { | ||
if (val instanceof LazyArray) { | ||
val = val.toArray(); | ||
} | ||
return super.size(val, ctx); | ||
} | ||
encode(stream, val, ctx) { | ||
if (val instanceof LazyArray) { | ||
val = val.toArray(); | ||
} | ||
return super.encode(stream, val, ctx); | ||
} | ||
} | ||
LazyArrayT.prototype.decode = function(stream, parent) { | ||
var length, pos, res; | ||
pos = stream.pos; | ||
length = utils.resolveLength(this.length, stream, parent); | ||
if (this.length instanceof NumberT) { | ||
parent = { | ||
parent: parent, | ||
_startOffset: pos, | ||
_currentOffset: 0, | ||
_length: length | ||
}; | ||
} | ||
res = new LazyArray(this.type, length, stream, parent); | ||
stream.pos += length * this.type.size(null, parent); | ||
return res; | ||
}; | ||
LazyArrayT.prototype.size = function(val, ctx) { | ||
if (val instanceof LazyArray) { | ||
val = val.toArray(); | ||
} | ||
return LazyArrayT.__super__.size.call(this, val, ctx); | ||
}; | ||
LazyArrayT.prototype.encode = function(stream, val, ctx) { | ||
if (val instanceof LazyArray) { | ||
val = val.toArray(); | ||
} | ||
return LazyArrayT.__super__.encode.call(this, stream, val, ctx); | ||
}; | ||
return LazyArrayT; | ||
})(ArrayT); | ||
LazyArray = (function() { | ||
function LazyArray(type, length, stream, ctx) { | ||
this.type = type; | ||
this.length = length; | ||
this.stream = stream; | ||
this.ctx = ctx; | ||
this.base = this.stream.pos; | ||
this.items = []; | ||
class LazyArray { | ||
constructor(type, length, stream, ctx) { | ||
this.type = type; | ||
this.length = length; | ||
this.stream = stream; | ||
this.ctx = ctx; | ||
this.base = this.stream.pos; | ||
this.items = []; | ||
} | ||
get(index) { | ||
if ((index < 0) || (index >= this.length)) { | ||
return undefined; | ||
} | ||
if (this.items[index] == null) { | ||
const { pos } = this.stream; | ||
this.stream.pos = this.base + (this.type.size(null, this.ctx) * index); | ||
this.items[index] = this.type.decode(this.stream, this.ctx); | ||
this.stream.pos = pos; | ||
} | ||
return this.items[index]; | ||
} | ||
toArray() { | ||
const result = []; | ||
for (let i = 0, end = this.length; i < end; i++) { | ||
result.push(this.get(i)); | ||
} | ||
return result; | ||
} | ||
inspect() { | ||
return inspect(this.toArray()); | ||
} | ||
} | ||
LazyArray.prototype.get = function(index) { | ||
var pos; | ||
if (index < 0 || index >= this.length) { | ||
return void 0; | ||
} | ||
if (this.items[index] == null) { | ||
pos = this.stream.pos; | ||
this.stream.pos = this.base + this.type.size(null, this.ctx) * index; | ||
this.items[index] = this.type.decode(this.stream, this.ctx); | ||
this.stream.pos = pos; | ||
} | ||
return this.items[index]; | ||
}; | ||
LazyArray.prototype.toArray = function() { | ||
var i, _i, _ref, _results; | ||
_results = []; | ||
for (i = _i = 0, _ref = this.length; _i < _ref; i = _i += 1) { | ||
_results.push(this.get(i)); | ||
} | ||
return _results; | ||
}; | ||
LazyArray.prototype.inspect = function() { | ||
return inspect(this.toArray()); | ||
}; | ||
return LazyArray; | ||
})(); | ||
module.exports = LazyArrayT; | ||
}).call(this); | ||
module.exports = LazyArrayT; |
@@ -1,106 +0,65 @@ | ||
// Generated by CoffeeScript 1.7.1 | ||
(function() { | ||
var DecodeStream, Fixed, NumberT, | ||
__hasProp = {}.hasOwnProperty, | ||
__extends = function(child, parent) { for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; }; | ||
const DecodeStream = require('./DecodeStream'); | ||
DecodeStream = require('./DecodeStream'); | ||
NumberT = (function() { | ||
function NumberT(type, endian) { | ||
this.type = type; | ||
this.endian = endian != null ? endian : 'BE'; | ||
this.fn = this.type; | ||
if (this.type[this.type.length - 1] !== '8') { | ||
this.fn += this.endian; | ||
} | ||
class NumberT { | ||
constructor(type, endian = 'BE') { | ||
this.type = type; | ||
this.endian = endian; | ||
this.fn = this.type; | ||
if (this.type[this.type.length - 1] !== '8') { | ||
this.fn += this.endian; | ||
} | ||
} | ||
NumberT.prototype.size = function() { | ||
return DecodeStream.TYPES[this.type]; | ||
}; | ||
size() { | ||
return DecodeStream.TYPES[this.type]; | ||
} | ||
NumberT.prototype.decode = function(stream) { | ||
return stream['read' + this.fn](); | ||
}; | ||
decode(stream) { | ||
return stream[`read${this.fn}`](); | ||
} | ||
NumberT.prototype.encode = function(stream, val) { | ||
return stream['write' + this.fn](val); | ||
}; | ||
encode(stream, val) { | ||
return stream[`write${this.fn}`](val); | ||
} | ||
} | ||
return NumberT; | ||
exports.Number = NumberT; | ||
exports.uint8 = new NumberT('UInt8'); | ||
exports.uint16be = (exports.uint16 = new NumberT('UInt16', 'BE')); | ||
exports.uint16le = new NumberT('UInt16', 'LE'); | ||
exports.uint24be = (exports.uint24 = new NumberT('UInt24', 'BE')); | ||
exports.uint24le = new NumberT('UInt24', 'LE'); | ||
exports.uint32be = (exports.uint32 = new NumberT('UInt32', 'BE')); | ||
exports.uint32le = new NumberT('UInt32', 'LE'); | ||
exports.int8 = new NumberT('Int8'); | ||
exports.int16be = (exports.int16 = new NumberT('Int16', 'BE')); | ||
exports.int16le = new NumberT('Int16', 'LE'); | ||
exports.int24be = (exports.int24 = new NumberT('Int24', 'BE')); | ||
exports.int24le = new NumberT('Int24', 'LE'); | ||
exports.int32be = (exports.int32 = new NumberT('Int32', 'BE')); | ||
exports.int32le = new NumberT('Int32', 'LE'); | ||
exports.floatbe = (exports.float = new NumberT('Float', 'BE')); | ||
exports.floatle = new NumberT('Float', 'LE'); | ||
exports.doublebe = (exports.double = new NumberT('Double', 'BE')); | ||
exports.doublele = new NumberT('Double', 'LE'); | ||
})(); | ||
class Fixed extends NumberT { | ||
constructor(size, endian, fracBits = size >> 1) { | ||
super(`Int${size}`, endian); | ||
this._point = 1 << fracBits; | ||
} | ||
exports.Number = NumberT; | ||
decode(stream) { | ||
return super.decode(stream) / this._point; | ||
} | ||
exports.uint8 = new NumberT('UInt8'); | ||
encode(stream, val) { | ||
return super.encode(stream, (val * this._point) | 0); | ||
} | ||
} | ||
exports.uint16be = exports.uint16 = new NumberT('UInt16', 'BE'); | ||
exports.uint16le = new NumberT('UInt16', 'LE'); | ||
exports.uint24be = exports.uint24 = new NumberT('UInt24', 'BE'); | ||
exports.uint24le = new NumberT('UInt24', 'LE'); | ||
exports.uint32be = exports.uint32 = new NumberT('UInt32', 'BE'); | ||
exports.uint32le = new NumberT('UInt32', 'LE'); | ||
exports.int8 = new NumberT('Int8'); | ||
exports.int16be = exports.int16 = new NumberT('Int16', 'BE'); | ||
exports.int16le = new NumberT('Int16', 'LE'); | ||
exports.int24be = exports.int24 = new NumberT('Int24', 'BE'); | ||
exports.int24le = new NumberT('Int24', 'LE'); | ||
exports.int32be = exports.int32 = new NumberT('Int32', 'BE'); | ||
exports.int32le = new NumberT('Int32', 'LE'); | ||
exports.floatbe = exports.float = new NumberT('Float', 'BE'); | ||
exports.floatle = new NumberT('Float', 'LE'); | ||
exports.doublebe = exports.double = new NumberT('Double', 'BE'); | ||
exports.doublele = new NumberT('Double', 'LE'); | ||
Fixed = (function(_super) { | ||
__extends(Fixed, _super); | ||
function Fixed(size, endian, fracBits) { | ||
if (fracBits == null) { | ||
fracBits = size >> 1; | ||
} | ||
Fixed.__super__.constructor.call(this, "Int" + size, endian); | ||
this._point = 1 << fracBits; | ||
} | ||
Fixed.prototype.decode = function(stream) { | ||
return Fixed.__super__.decode.call(this, stream) / this._point; | ||
}; | ||
Fixed.prototype.encode = function(stream, val) { | ||
return Fixed.__super__.encode.call(this, stream, val * this._point | 0); | ||
}; | ||
return Fixed; | ||
})(NumberT); | ||
exports.Fixed = Fixed; | ||
exports.fixed16be = exports.fixed16 = new Fixed(16, 'BE'); | ||
exports.fixed16le = new Fixed(16, 'LE'); | ||
exports.fixed32be = exports.fixed32 = new Fixed(32, 'BE'); | ||
exports.fixed32le = new Fixed(32, 'LE'); | ||
}).call(this); | ||
exports.Fixed = Fixed; | ||
exports.fixed16be = (exports.fixed16 = new Fixed(16, 'BE')); | ||
exports.fixed16le = new Fixed(16, 'LE'); | ||
exports.fixed32be = (exports.fixed32 =new Fixed(32, 'BE')); | ||
exports.fixed32le = new Fixed(32, 'LE'); |
@@ -1,52 +0,43 @@ | ||
// Generated by CoffeeScript 1.7.1 | ||
(function() { | ||
var Optional; | ||
class Optional { | ||
constructor(type, condition = true) { | ||
this.type = type; | ||
this.condition = condition; | ||
} | ||
Optional = (function() { | ||
function Optional(type, condition) { | ||
this.type = type; | ||
this.condition = condition != null ? condition : true; | ||
decode(stream, parent) { | ||
let { condition } = this; | ||
if (typeof condition === 'function') { | ||
condition = condition.call(parent, parent); | ||
} | ||
Optional.prototype.decode = function(stream, parent) { | ||
var condition; | ||
condition = this.condition; | ||
if (typeof condition === 'function') { | ||
condition = condition.call(parent, parent); | ||
} | ||
if (condition) { | ||
return this.type.decode(stream, parent); | ||
} | ||
}; | ||
if (condition) { | ||
return this.type.decode(stream, parent); | ||
} | ||
} | ||
Optional.prototype.size = function(val, parent) { | ||
var condition; | ||
condition = this.condition; | ||
if (typeof condition === 'function') { | ||
condition = condition.call(parent, parent); | ||
} | ||
if (condition) { | ||
return this.type.size(val, parent); | ||
} else { | ||
return 0; | ||
} | ||
}; | ||
size(val, parent) { | ||
let { condition } = this; | ||
if (typeof condition === 'function') { | ||
condition = condition.call(parent, parent); | ||
} | ||
Optional.prototype.encode = function(stream, val, parent) { | ||
var condition; | ||
condition = this.condition; | ||
if (typeof condition === 'function') { | ||
condition = condition.call(parent, parent); | ||
} | ||
if (condition) { | ||
return this.type.encode(stream, val, parent); | ||
} | ||
}; | ||
if (condition) { | ||
return this.type.size(val, parent); | ||
} else { | ||
return 0; | ||
} | ||
} | ||
return Optional; | ||
encode(stream, val, parent) { | ||
let { condition } = this; | ||
if (typeof condition === 'function') { | ||
condition = condition.call(parent, parent); | ||
} | ||
})(); | ||
if (condition) { | ||
return this.type.encode(stream, val, parent); | ||
} | ||
} | ||
} | ||
module.exports = Optional; | ||
}).call(this); | ||
module.exports = Optional; |
@@ -1,176 +0,163 @@ | ||
// Generated by CoffeeScript 1.7.1 | ||
(function() { | ||
var Pointer, VoidPointer, utils; | ||
const utils = require('./utils'); | ||
utils = require('./utils'); | ||
class Pointer { | ||
constructor(offsetType, type, options = {}) { | ||
this.offsetType = offsetType; | ||
this.type = type; | ||
this.options = options; | ||
if (this.type === 'void') { this.type = null; } | ||
if (this.options.type == null) { this.options.type = 'local'; } | ||
if (this.options.allowNull == null) { this.options.allowNull = true; } | ||
if (this.options.nullValue == null) { this.options.nullValue = 0; } | ||
if (this.options.lazy == null) { this.options.lazy = false; } | ||
if (this.options.relativeTo) { | ||
this.relativeToGetter = new Function('ctx', `return ctx.${this.options.relativeTo}`); | ||
} | ||
} | ||
Pointer = (function() { | ||
function Pointer(offsetType, type, options) { | ||
var _base, _base1, _base2, _base3; | ||
this.offsetType = offsetType; | ||
this.type = type; | ||
this.options = options != null ? options : {}; | ||
if (this.type === 'void') { | ||
this.type = null; | ||
} | ||
if ((_base = this.options).type == null) { | ||
_base.type = 'local'; | ||
} | ||
if ((_base1 = this.options).allowNull == null) { | ||
_base1.allowNull = true; | ||
} | ||
if ((_base2 = this.options).nullValue == null) { | ||
_base2.nullValue = 0; | ||
} | ||
if ((_base3 = this.options).lazy == null) { | ||
_base3.lazy = false; | ||
} | ||
if (this.options.relativeTo) { | ||
this.relativeToGetter = new Function('ctx', "return ctx." + this.options.relativeTo); | ||
} | ||
decode(stream, ctx) { | ||
const offset = this.offsetType.decode(stream, ctx); | ||
// handle NULL pointers | ||
if ((offset === this.options.nullValue) && this.options.allowNull) { | ||
return null; | ||
} | ||
Pointer.prototype.decode = function(stream, ctx) { | ||
var c, decodeValue, offset, ptr, relative, val; | ||
offset = this.offsetType.decode(stream, ctx); | ||
if (offset === this.options.nullValue && this.options.allowNull) { | ||
return null; | ||
} | ||
relative = (function() { | ||
switch (this.options.type) { | ||
case 'local': | ||
return ctx._startOffset; | ||
case 'immediate': | ||
return stream.pos - this.offsetType.size(); | ||
case 'parent': | ||
return ctx.parent._startOffset; | ||
default: | ||
c = ctx; | ||
while (c.parent) { | ||
c = c.parent; | ||
} | ||
return c._startOffset || 0; | ||
let relative | ||
switch (this.options.type) { | ||
case 'local': relative = ctx._startOffset; break; | ||
case 'immediate': relative = stream.pos - this.offsetType.size(); break; | ||
case 'parent': relative = ctx.parent._startOffset; break; | ||
default: | ||
var c = ctx; | ||
while (c.parent) { | ||
c = c.parent; | ||
} | ||
}).call(this); | ||
if (this.options.relativeTo) { | ||
relative += this.relativeToGetter(ctx); | ||
relative = c._startOffset || 0; | ||
} | ||
if (this.options.relativeTo) { | ||
relative += this.relativeToGetter(ctx); | ||
} | ||
const ptr = offset + relative; | ||
if (this.type != null) { | ||
let val = null; | ||
const decodeValue = () => { | ||
if (val != null) { return val; } | ||
const { pos } = stream; | ||
stream.pos = ptr; | ||
val = this.type.decode(stream, ctx); | ||
stream.pos = pos; | ||
return val; | ||
}; | ||
// If this is a lazy pointer, define a getter to decode only when needed. | ||
// This obviously only works when the pointer is contained by a Struct. | ||
if (this.options.lazy) { | ||
return new utils.PropertyDescriptor({ | ||
get: decodeValue}); | ||
} | ||
ptr = offset + relative; | ||
if (this.type != null) { | ||
val = null; | ||
decodeValue = (function(_this) { | ||
return function() { | ||
var pos; | ||
if (val != null) { | ||
return val; | ||
} | ||
pos = stream.pos; | ||
stream.pos = ptr; | ||
val = _this.type.decode(stream, ctx); | ||
stream.pos = pos; | ||
return val; | ||
}; | ||
})(this); | ||
if (this.options.lazy) { | ||
return new utils.PropertyDescriptor({ | ||
get: decodeValue | ||
}); | ||
} | ||
return decodeValue(); | ||
} else { | ||
return ptr; | ||
} | ||
}; | ||
return decodeValue(); | ||
} else { | ||
return ptr; | ||
} | ||
} | ||
Pointer.prototype.size = function(val, ctx) { | ||
var parent, type; | ||
parent = ctx; | ||
switch (this.options.type) { | ||
case 'local': | ||
case 'immediate': | ||
break; | ||
case 'parent': | ||
size(val, ctx) { | ||
const parent = ctx; | ||
switch (this.options.type) { | ||
case 'local': case 'immediate': | ||
break; | ||
case 'parent': | ||
ctx = ctx.parent; | ||
break; | ||
default: // global | ||
while (ctx.parent) { | ||
ctx = ctx.parent; | ||
break; | ||
default: | ||
while (ctx.parent) { | ||
ctx = ctx.parent; | ||
} | ||
} | ||
type = this.type; | ||
if (type == null) { | ||
if (!(val instanceof VoidPointer)) { | ||
throw new Error("Must be a VoidPointer"); | ||
} | ||
type = val.type; | ||
val = val.value; | ||
} | ||
let { type } = this; | ||
if (type == null) { | ||
if (!(val instanceof VoidPointer)) { | ||
throw new Error("Must be a VoidPointer"); | ||
} | ||
if (val && ctx) { | ||
ctx.pointerSize += type.size(val, parent); | ||
} | ||
return this.offsetType.size(); | ||
}; | ||
Pointer.prototype.encode = function(stream, val, ctx) { | ||
var parent, relative, type; | ||
parent = ctx; | ||
if (val == null) { | ||
this.offsetType.encode(stream, this.options.nullValue); | ||
return; | ||
} | ||
switch (this.options.type) { | ||
case 'local': | ||
relative = ctx.startOffset; | ||
break; | ||
case 'immediate': | ||
relative = stream.pos + this.offsetType.size(val, parent); | ||
break; | ||
case 'parent': | ||
({ type } = val); | ||
val = val.value; | ||
} | ||
if (val && ctx) { | ||
ctx.pointerSize += type.size(val, parent); | ||
} | ||
return this.offsetType.size(); | ||
} | ||
encode(stream, val, ctx) { | ||
let relative; | ||
const parent = ctx; | ||
if ((val == null)) { | ||
this.offsetType.encode(stream, this.options.nullValue); | ||
return; | ||
} | ||
switch (this.options.type) { | ||
case 'local': | ||
relative = ctx.startOffset; | ||
break; | ||
case 'immediate': | ||
relative = stream.pos + this.offsetType.size(val, parent); | ||
break; | ||
case 'parent': | ||
ctx = ctx.parent; | ||
relative = ctx.startOffset; | ||
break; | ||
default: // global | ||
relative = 0; | ||
while (ctx.parent) { | ||
ctx = ctx.parent; | ||
relative = ctx.startOffset; | ||
break; | ||
default: | ||
relative = 0; | ||
while (ctx.parent) { | ||
ctx = ctx.parent; | ||
} | ||
} | ||
if (this.options.relativeTo) { | ||
relative += this.relativeToGetter(parent.val); | ||
} | ||
this.offsetType.encode(stream, ctx.pointerOffset - relative); | ||
type = this.type; | ||
if (type == null) { | ||
if (!(val instanceof VoidPointer)) { | ||
throw new Error("Must be a VoidPointer"); | ||
} | ||
type = val.type; | ||
val = val.value; | ||
} | ||
ctx.pointers.push({ | ||
type: type, | ||
val: val, | ||
parent: parent | ||
}); | ||
return ctx.pointerOffset += type.size(val, parent); | ||
}; | ||
} | ||
return Pointer; | ||
if (this.options.relativeTo) { | ||
relative += this.relativeToGetter(parent.val); | ||
} | ||
})(); | ||
this.offsetType.encode(stream, ctx.pointerOffset - relative); | ||
VoidPointer = (function() { | ||
function VoidPointer(type, value) { | ||
this.type = type; | ||
this.value = value; | ||
let { type } = this; | ||
if (type == null) { | ||
if (!(val instanceof VoidPointer)) { | ||
throw new Error("Must be a VoidPointer"); | ||
} | ||
({ type } = val); | ||
val = val.value; | ||
} | ||
return VoidPointer; | ||
ctx.pointers.push({ | ||
type, | ||
val, | ||
parent | ||
}); | ||
})(); | ||
return ctx.pointerOffset += type.size(val, parent); | ||
} | ||
} | ||
exports.Pointer = Pointer; | ||
// A pointer whose type is determined at decode time | ||
class VoidPointer { | ||
constructor(type, value) { | ||
this.type = type; | ||
this.value = value; | ||
} | ||
} | ||
exports.VoidPointer = VoidPointer; | ||
}).call(this); | ||
exports.Pointer = Pointer; | ||
exports.VoidPointer = VoidPointer; |
@@ -1,34 +0,23 @@ | ||
// Generated by CoffeeScript 1.7.1 | ||
(function() { | ||
var Reserved, utils; | ||
const utils = require('./utils'); | ||
utils = require('./utils'); | ||
class Reserved { | ||
constructor(type, count = 1) { | ||
this.type = type; | ||
this.count = count; | ||
} | ||
decode(stream, parent) { | ||
stream.pos += this.size(null, parent); | ||
return undefined; | ||
} | ||
Reserved = (function() { | ||
function Reserved(type, count) { | ||
this.type = type; | ||
this.count = count != null ? count : 1; | ||
} | ||
size(data, parent) { | ||
const count = utils.resolveLength(this.count, null, parent); | ||
return this.type.size() * count; | ||
} | ||
Reserved.prototype.decode = function(stream, parent) { | ||
stream.pos += this.size(null, parent); | ||
return void 0; | ||
}; | ||
encode(stream, val, parent) { | ||
return stream.fill(0, this.size(val, parent)); | ||
} | ||
} | ||
Reserved.prototype.size = function(data, parent) { | ||
var count; | ||
count = utils.resolveLength(this.count, null, parent); | ||
return this.type.size() * count; | ||
}; | ||
Reserved.prototype.encode = function(stream, val, parent) { | ||
return stream.fill(0, this.size(val, parent)); | ||
}; | ||
return Reserved; | ||
})(); | ||
module.exports = Reserved; | ||
}).call(this); | ||
module.exports = Reserved; |
@@ -1,82 +0,85 @@ | ||
// Generated by CoffeeScript 1.7.1 | ||
(function() { | ||
var NumberT, StringT, utils; | ||
const {Number:NumberT} = require('./Number'); | ||
const utils = require('./utils'); | ||
NumberT = require('./Number').Number; | ||
class StringT { | ||
constructor(length, encoding = 'ascii') { | ||
this.length = length; | ||
this.encoding = encoding; | ||
} | ||
utils = require('./utils'); | ||
decode(stream, parent) { | ||
let length, pos; | ||
if (this.length != null) { | ||
length = utils.resolveLength(this.length, stream, parent); | ||
} else { | ||
let buffer; | ||
({buffer, length, pos} = stream); | ||
StringT = (function() { | ||
function StringT(length, encoding) { | ||
this.length = length; | ||
this.encoding = encoding != null ? encoding : 'ascii'; | ||
while ((pos < length) && (buffer[pos] !== 0x00)) { | ||
++pos; | ||
} | ||
length = pos - stream.pos; | ||
} | ||
let { encoding } = this; | ||
if (typeof encoding === 'function') { | ||
encoding = encoding.call(parent, parent) || 'ascii'; | ||
} | ||
StringT.prototype.decode = function(stream, parent) { | ||
var buffer, encoding, length, pos, string; | ||
length = (function() { | ||
if (this.length != null) { | ||
return utils.resolveLength(this.length, stream, parent); | ||
} else { | ||
buffer = stream.buffer, length = stream.length, pos = stream.pos; | ||
while (pos < length && buffer[pos] !== 0x00) { | ||
++pos; | ||
} | ||
return pos - stream.pos; | ||
} | ||
}).call(this); | ||
encoding = this.encoding; | ||
if (typeof encoding === 'function') { | ||
encoding = encoding.call(parent, parent) || 'ascii'; | ||
} | ||
string = stream.readString(length, encoding); | ||
if ((this.length == null) && stream.pos < stream.length) { | ||
stream.pos++; | ||
} | ||
return string; | ||
}; | ||
const string = stream.readString(length, encoding); | ||
StringT.prototype.size = function(val, parent) { | ||
var encoding, size; | ||
if (!val) { | ||
return utils.resolveLength(this.length, null, parent); | ||
} | ||
encoding = this.encoding; | ||
if (typeof encoding === 'function') { | ||
encoding = encoding.call(parent != null ? parent.val : void 0, parent != null ? parent.val : void 0) || 'ascii'; | ||
} | ||
if (encoding === 'utf16be') { | ||
encoding = 'utf16le'; | ||
} | ||
size = Buffer.byteLength(val, encoding); | ||
if (this.length instanceof NumberT) { | ||
size += this.length.size(); | ||
} | ||
if (this.length == null) { | ||
size++; | ||
} | ||
return size; | ||
}; | ||
if ((this.length == null) && (stream.pos < stream.length)) { | ||
stream.pos++; | ||
} | ||
StringT.prototype.encode = function(stream, val, parent) { | ||
var encoding; | ||
encoding = this.encoding; | ||
if (typeof encoding === 'function') { | ||
encoding = encoding.call(parent != null ? parent.val : void 0, parent != null ? parent.val : void 0) || 'ascii'; | ||
} | ||
if (this.length instanceof NumberT) { | ||
this.length.encode(stream, Buffer.byteLength(val, encoding)); | ||
} | ||
stream.writeString(val, encoding); | ||
if (this.length == null) { | ||
return stream.writeUInt8(0x00); | ||
} | ||
}; | ||
return string; | ||
} | ||
size(val, parent) { | ||
// Use the defined value if no value was given | ||
if (!val) { | ||
return utils.resolveLength(this.length, null, parent); | ||
} | ||
let { encoding } = this; | ||
if (typeof encoding === 'function') { | ||
encoding = encoding.call(parent != null ? parent.val : undefined, parent != null ? parent.val : undefined) || 'ascii'; | ||
} | ||
return StringT; | ||
if (encoding === 'utf16be') { | ||
encoding = 'utf16le'; | ||
} | ||
})(); | ||
let size = Buffer.byteLength(val, encoding); | ||
if (this.length instanceof NumberT) { | ||
size += this.length.size(); | ||
} | ||
module.exports = StringT; | ||
if ((this.length == null)) { | ||
size++; | ||
} | ||
}).call(this); | ||
return size; | ||
} | ||
encode(stream, val, parent) { | ||
let { encoding } = this; | ||
if (typeof encoding === 'function') { | ||
encoding = encoding.call(parent != null ? parent.val : undefined, parent != null ? parent.val : undefined) || 'ascii'; | ||
} | ||
if (this.length instanceof NumberT) { | ||
this.length.encode(stream, Buffer.byteLength(val, encoding)); | ||
} | ||
stream.writeString(val, encoding); | ||
if ((this.length == null)) { | ||
return stream.writeUInt8(0x00); | ||
} | ||
} | ||
} | ||
module.exports = StringT; |
@@ -1,126 +0,111 @@ | ||
// Generated by CoffeeScript 1.7.1 | ||
(function() { | ||
var Struct, utils; | ||
const utils = require('./utils'); | ||
utils = require('./utils'); | ||
class Struct { | ||
constructor(fields = {}) { | ||
this.fields = fields; | ||
} | ||
Struct = (function() { | ||
function Struct(fields) { | ||
this.fields = fields != null ? fields : {}; | ||
decode(stream, parent, length = 0) { | ||
const res = this._setup(stream, parent, length); | ||
this._parseFields(stream, res, this.fields); | ||
if (this.process != null) { | ||
this.process.call(res, stream); | ||
} | ||
return res; | ||
} | ||
Struct.prototype.decode = function(stream, parent, length) { | ||
var res, _ref; | ||
if (length == null) { | ||
length = 0; | ||
} | ||
res = this._setup(stream, parent, length); | ||
this._parseFields(stream, res, this.fields); | ||
if ((_ref = this.process) != null) { | ||
_ref.call(res, stream); | ||
} | ||
return res; | ||
}; | ||
_setup(stream, parent, length) { | ||
const res = {}; | ||
Struct.prototype._setup = function(stream, parent, length) { | ||
var res; | ||
res = {}; | ||
Object.defineProperties(res, { | ||
parent: { | ||
value: parent | ||
}, | ||
_startOffset: { | ||
value: stream.pos | ||
}, | ||
_currentOffset: { | ||
value: 0, | ||
writable: true | ||
}, | ||
_length: { | ||
value: length | ||
} | ||
}); | ||
return res; | ||
}; | ||
// define hidden properties | ||
Object.defineProperties(res, { | ||
parent: { value: parent }, | ||
_startOffset: { value: stream.pos }, | ||
_currentOffset: { value: 0, writable: true }, | ||
_length: { value: length } | ||
}); | ||
Struct.prototype._parseFields = function(stream, res, fields) { | ||
var key, type, val; | ||
for (key in fields) { | ||
type = fields[key]; | ||
if (typeof type === 'function') { | ||
val = type.call(res, res); | ||
return res; | ||
} | ||
_parseFields(stream, res, fields) { | ||
for (let key in fields) { | ||
var val; | ||
const type = fields[key]; | ||
if (typeof type === 'function') { | ||
val = type.call(res, res); | ||
} else { | ||
val = type.decode(stream, res); | ||
} | ||
if (val !== undefined) { | ||
if (val instanceof utils.PropertyDescriptor) { | ||
Object.defineProperty(res, key, val); | ||
} else { | ||
val = type.decode(stream, res); | ||
res[key] = val; | ||
} | ||
if (val !== void 0) { | ||
if (val instanceof utils.PropertyDescriptor) { | ||
Object.defineProperty(res, key, val); | ||
} else { | ||
res[key] = val; | ||
} | ||
} | ||
res._currentOffset = stream.pos - res._startOffset; | ||
} | ||
res._currentOffset = stream.pos - res._startOffset; | ||
} | ||
} | ||
size(val, parent, includePointers) { | ||
if (val == null) { val = {}; } | ||
if (includePointers == null) { includePointers = true; } | ||
const ctx = { | ||
parent, | ||
val, | ||
pointerSize: 0 | ||
}; | ||
Struct.prototype.size = function(val, parent, includePointers) { | ||
var ctx, key, size, type, _ref; | ||
if (val == null) { | ||
val = {}; | ||
let size = 0; | ||
for (let key in this.fields) { | ||
const type = this.fields[key]; | ||
if (type.size != null) { | ||
size += type.size(val[key], ctx); | ||
} | ||
if (includePointers == null) { | ||
includePointers = true; | ||
} | ||
ctx = { | ||
parent: parent, | ||
val: val, | ||
pointerSize: 0 | ||
}; | ||
size = 0; | ||
_ref = this.fields; | ||
for (key in _ref) { | ||
type = _ref[key]; | ||
if (type.size != null) { | ||
size += type.size(val[key], ctx); | ||
} | ||
} | ||
if (includePointers) { | ||
size += ctx.pointerSize; | ||
} | ||
return size; | ||
} | ||
if (includePointers) { | ||
size += ctx.pointerSize; | ||
} | ||
return size; | ||
} | ||
encode(stream, val, parent) { | ||
let type; | ||
if (this.preEncode != null) { | ||
this.preEncode.call(val, stream); | ||
} | ||
const ctx = { | ||
pointers: [], | ||
startOffset: stream.pos, | ||
parent, | ||
val, | ||
pointerSize: 0 | ||
}; | ||
Struct.prototype.encode = function(stream, val, parent) { | ||
var ctx, i, key, ptr, type, _ref, _ref1; | ||
if ((_ref = this.preEncode) != null) { | ||
_ref.call(val, stream); | ||
ctx.pointerOffset = stream.pos + this.size(val, ctx, false); | ||
for (let key in this.fields) { | ||
type = this.fields[key]; | ||
if (type.encode != null) { | ||
type.encode(stream, val[key], ctx); | ||
} | ||
ctx = { | ||
pointers: [], | ||
startOffset: stream.pos, | ||
parent: parent, | ||
val: val, | ||
pointerSize: 0 | ||
}; | ||
ctx.pointerOffset = stream.pos + this.size(val, ctx, false); | ||
_ref1 = this.fields; | ||
for (key in _ref1) { | ||
type = _ref1[key]; | ||
if (type.encode != null) { | ||
type.encode(stream, val[key], ctx); | ||
} | ||
} | ||
i = 0; | ||
while (i < ctx.pointers.length) { | ||
ptr = ctx.pointers[i++]; | ||
ptr.type.encode(stream, ptr.val, ptr.parent); | ||
} | ||
}; | ||
} | ||
return Struct; | ||
let i = 0; | ||
while (i < ctx.pointers.length) { | ||
const ptr = ctx.pointers[i++]; | ||
ptr.type.encode(stream, ptr.val, ptr.parent); | ||
} | ||
})(); | ||
} | ||
} | ||
module.exports = Struct; | ||
}).call(this); | ||
module.exports = Struct; |
@@ -1,44 +0,37 @@ | ||
// Generated by CoffeeScript 1.7.1 | ||
(function() { | ||
var NumberT, PropertyDescriptor; | ||
const {Number:NumberT} = require('./Number'); | ||
NumberT = require('./Number').Number; | ||
exports.resolveLength = function(length, stream, parent) { | ||
let res; | ||
if (typeof length === 'number') { | ||
res = length; | ||
exports.resolveLength = function(length, stream, parent) { | ||
var res; | ||
if (typeof length === 'number') { | ||
res = length; | ||
} else if (typeof length === 'function') { | ||
res = length.call(parent, parent); | ||
} else if (parent && typeof length === 'string') { | ||
res = parent[length]; | ||
} else if (stream && length instanceof NumberT) { | ||
res = length.decode(stream); | ||
} | ||
if (isNaN(res)) { | ||
throw new Error('Not a fixed size'); | ||
} | ||
return res; | ||
}; | ||
} else if (typeof length === 'function') { | ||
res = length.call(parent, parent); | ||
PropertyDescriptor = (function() { | ||
function PropertyDescriptor(opts) { | ||
var key, val; | ||
if (opts == null) { | ||
opts = {}; | ||
} | ||
this.enumerable = true; | ||
this.configurable = true; | ||
for (key in opts) { | ||
val = opts[key]; | ||
this[key] = val; | ||
} | ||
} | ||
} else if (parent && (typeof length === 'string')) { | ||
res = parent[length]; | ||
return PropertyDescriptor; | ||
} else if (stream && length instanceof NumberT) { | ||
res = length.decode(stream); | ||
} | ||
})(); | ||
if (isNaN(res)) { | ||
throw new Error('Not a fixed size'); | ||
} | ||
return res; | ||
}; | ||
exports.PropertyDescriptor = PropertyDescriptor; | ||
class PropertyDescriptor { | ||
constructor(opts = {}) { | ||
this.enumerable = true; | ||
this.configurable = true; | ||
for (let key in opts) { | ||
const val = opts[key]; | ||
this[key] = val; | ||
} | ||
} | ||
} | ||
}).call(this); | ||
exports.PropertyDescriptor = PropertyDescriptor; |
@@ -1,81 +0,64 @@ | ||
// Generated by CoffeeScript 1.7.1 | ||
(function() { | ||
var Struct, VersionedStruct, | ||
__hasProp = {}.hasOwnProperty, | ||
__extends = function(child, parent) { for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; }; | ||
const Struct = require('./Struct'); | ||
Struct = require('./Struct'); | ||
class VersionedStruct extends Struct { | ||
constructor(type, versions = {}) { | ||
super(); | ||
this.type = type; | ||
this.versions = versions; | ||
if (typeof this.type === 'string') { | ||
this.versionGetter = new Function('parent', `return parent.${this.type}`); | ||
this.versionSetter = new Function('parent', 'version', `return parent.${this.type} = version`); | ||
} | ||
} | ||
VersionedStruct = (function(_super) { | ||
__extends(VersionedStruct, _super); | ||
decode(stream, parent, length = 0) { | ||
const res = this._setup(stream, parent, length); | ||
function VersionedStruct(type, versions) { | ||
this.type = type; | ||
this.versions = versions != null ? versions : {}; | ||
if (typeof this.type === 'string') { | ||
this.versionGetter = new Function('parent', "return parent." + this.type); | ||
this.versionSetter = new Function('parent', 'version', "return parent." + this.type + " = version"); | ||
} | ||
if (typeof this.type === 'string') { | ||
res.version = this.versionGetter(parent); | ||
} else { | ||
res.version = this.type.decode(stream); | ||
} | ||
VersionedStruct.prototype.decode = function(stream, parent, length) { | ||
var fields, res, _ref; | ||
if (length == null) { | ||
length = 0; | ||
} | ||
res = this._setup(stream, parent, length); | ||
if (typeof this.type === 'string') { | ||
res.version = this.versionGetter(parent); | ||
} else { | ||
res.version = this.type.decode(stream); | ||
} | ||
if (this.versions.header) { | ||
this._parseFields(stream, res, this.versions.header); | ||
} | ||
fields = this.versions[res.version]; | ||
if (fields == null) { | ||
throw new Error("Unknown version " + res.version); | ||
} | ||
if (fields instanceof VersionedStruct) { | ||
return fields.decode(stream, parent); | ||
} | ||
this._parseFields(stream, res, fields); | ||
if ((_ref = this.process) != null) { | ||
_ref.call(res, stream); | ||
} | ||
return res; | ||
if (this.versions.header) { | ||
this._parseFields(stream, res, this.versions.header); | ||
} | ||
const fields = this.versions[res.version]; | ||
if ((fields == null)) { | ||
throw new Error(`Unknown version ${res.version}`); | ||
} | ||
if (fields instanceof VersionedStruct) { | ||
return fields.decode(stream, parent); | ||
} | ||
this._parseFields(stream, res, fields); | ||
if (this.process != null) { | ||
this.process.call(res, stream); | ||
} | ||
return res; | ||
} | ||
size(val, parent, includePointers = true) { | ||
let key, type; | ||
if (!val) { | ||
throw new Error('Not a fixed size'); | ||
} | ||
const ctx = { | ||
parent, | ||
val, | ||
pointerSize: 0 | ||
}; | ||
VersionedStruct.prototype.size = function(val, parent, includePointers) { | ||
var ctx, fields, key, size, type, _ref; | ||
if (includePointers == null) { | ||
includePointers = true; | ||
} | ||
if (!val) { | ||
throw new Error('Not a fixed size'); | ||
} | ||
ctx = { | ||
parent: parent, | ||
val: val, | ||
pointerSize: 0 | ||
}; | ||
size = 0; | ||
if (typeof this.type !== 'string') { | ||
size += this.type.size(val.version, ctx); | ||
} | ||
if (this.versions.header) { | ||
_ref = this.versions.header; | ||
for (key in _ref) { | ||
type = _ref[key]; | ||
if (type.size != null) { | ||
size += type.size(val[key], ctx); | ||
} | ||
} | ||
} | ||
fields = this.versions[val.version]; | ||
if (fields == null) { | ||
throw new Error("Unknown version " + val.version); | ||
} | ||
for (key in fields) { | ||
type = fields[key]; | ||
let size = 0; | ||
if (typeof this.type !== 'string') { | ||
size += this.type.size(val.version, ctx); | ||
} | ||
if (this.versions.header) { | ||
for (key in this.versions.header) { | ||
type = this.versions.header[key]; | ||
if (type.size != null) { | ||
@@ -85,36 +68,46 @@ size += type.size(val[key], ctx); | ||
} | ||
if (includePointers) { | ||
size += ctx.pointerSize; | ||
} | ||
const fields = this.versions[val.version]; | ||
if ((fields == null)) { | ||
throw new Error(`Unknown version ${val.version}`); | ||
} | ||
for (key in fields) { | ||
type = fields[key]; | ||
if (type.size != null) { | ||
size += type.size(val[key], ctx); | ||
} | ||
return size; | ||
} | ||
if (includePointers) { | ||
size += ctx.pointerSize; | ||
} | ||
return size; | ||
} | ||
encode(stream, val, parent) { | ||
let key, type; | ||
if (this.preEncode != null) { | ||
this.preEncode.call(val, stream); | ||
} | ||
const ctx = { | ||
pointers: [], | ||
startOffset: stream.pos, | ||
parent, | ||
val, | ||
pointerSize: 0 | ||
}; | ||
VersionedStruct.prototype.encode = function(stream, val, parent) { | ||
var ctx, fields, i, key, ptr, type, _ref, _ref1; | ||
if ((_ref = this.preEncode) != null) { | ||
_ref.call(val, stream); | ||
} | ||
ctx = { | ||
pointers: [], | ||
startOffset: stream.pos, | ||
parent: parent, | ||
val: val, | ||
pointerSize: 0 | ||
}; | ||
ctx.pointerOffset = stream.pos + this.size(val, ctx, false); | ||
if (typeof this.type !== 'string') { | ||
this.type.encode(stream, val.version); | ||
} | ||
if (this.versions.header) { | ||
_ref1 = this.versions.header; | ||
for (key in _ref1) { | ||
type = _ref1[key]; | ||
if (type.encode != null) { | ||
type.encode(stream, val[key], ctx); | ||
} | ||
} | ||
} | ||
fields = this.versions[val.version]; | ||
for (key in fields) { | ||
type = fields[key]; | ||
ctx.pointerOffset = stream.pos + this.size(val, ctx, false); | ||
if (typeof this.type !== 'string') { | ||
this.type.encode(stream, val.version); | ||
} | ||
if (this.versions.header) { | ||
for (key in this.versions.header) { | ||
type = this.versions.header[key]; | ||
if (type.encode != null) { | ||
@@ -124,15 +117,21 @@ type.encode(stream, val[key], ctx); | ||
} | ||
i = 0; | ||
while (i < ctx.pointers.length) { | ||
ptr = ctx.pointers[i++]; | ||
ptr.type.encode(stream, ptr.val, ptr.parent); | ||
} | ||
const fields = this.versions[val.version]; | ||
for (key in fields) { | ||
type = fields[key]; | ||
if (type.encode != null) { | ||
type.encode(stream, val[key], ctx); | ||
} | ||
}; | ||
} | ||
return VersionedStruct; | ||
let i = 0; | ||
while (i < ctx.pointers.length) { | ||
const ptr = ctx.pointers[i++]; | ||
ptr.type.encode(stream, ptr.val, ptr.parent); | ||
} | ||
})(Struct); | ||
} | ||
} | ||
module.exports = VersionedStruct; | ||
}).call(this); | ||
module.exports = VersionedStruct; |
Sorry, the diff of this file is not supported yet
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
Uses eval
Supply chain riskPackage uses dynamic code execution (e.g., eval()), which is a dangerous practice. This can prevent the code from running in certain environments and increases the risk that the code may contain exploits or malicious behavior.
Found 1 instance in 1 package
Uses eval
Supply chain riskPackage uses dynamic code execution (e.g., eval()), which is a dangerous practice. This can prevent the code from running in certain environments and increases the risk that the code may contain exploits or malicious behavior.
Found 1 instance in 1 package
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
6
-25%3153
164.07%0
-100%112346
-12.93%36
-34.55%4
33.33%