From 6173da36164c5ea566da6dda52cc4af0f7bc63a6 Mon Sep 17 00:00:00 2001 From: "Peter A. Bigot" Date: Sun, 17 Dec 2017 03:47:50 -0600 Subject: [PATCH 1/5] passim: update for next development cycle --- CHANGELOG.md | 3 +++ package.json | 2 +- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 8e928e1..23d8f52 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,7 @@ # Change Log +## [Unreleased] + ## [1.0.0] - 2017-12-17 * Minimum Node version increased to 4.5 to support dependency @@ -115,6 +117,7 @@ * Initial release. +[Unreleased]: https://github.com/pabigot/buffer-layout/compare/v1.0.0...next [1.0.0]: https://github.com/pabigot/buffer-layout/compare/v0.13.0...v1.0.0 [0.13.0]: https://github.com/pabigot/buffer-layout/compare/v0.12.0...v0.13.0 [0.12.1]: https://github.com/pabigot/buffer-layout/compare/v0.12.0...v0.12.1 diff --git a/package.json b/package.json index 1383b8b..b3ffb86 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "buffer-layout", - "version": "1.0.0", + "version": "1.1.0-dev", "description": "Translation between JavaScript values and Buffers", "keywords": [ "Buffer", From e091ed026a43f3ee025c15f5fa7a79693d52a4ce Mon Sep 17 00:00:00 2001 From: "Peter A. Bigot" Date: Sat, 23 Dec 2017 05:55:04 -0600 Subject: [PATCH 2/5] Layout: prefer interpretation as property over msb in BitStructure BitStructure's constructor takes two parameters, with the second being a rarely-used option to order allocation from the most significant bit down. The developer forgets this, and passes a property name without a second argument, which results in no data. If the argument is type-compatible with property and no third argument is present, treat the argument as property rather than msb. Technically this is an API change, but I'm going to rule it minor because anybody who's affected will have been using it wrong. Closes #17. --- CHANGELOG.md | 5 +++++ lib/Layout.js | 14 +++++++++++--- test/LayoutTest.js | 17 +++++++++++++++++ 3 files changed, 33 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 23d8f52..cc9415d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,10 @@ ## [Unreleased] +## [1.1.0] - 2017-12-23 +* **API** Interpret string argument to BitStructure `msb` parameter as + a `property` parameter, resolving [issue #17][issue#17]. + ## [1.0.0] - 2017-12-17 * Minimum Node version increased to 4.5 to support dependency @@ -172,6 +176,7 @@ [issue#13]: https://github.com/pabigot/buffer-layout/issues/13 [issue#14]: https://github.com/pabigot/buffer-layout/issues/14 [issue#15]: https://github.com/pabigot/buffer-layout/issues/15 +[issue#17]: https://github.com/pabigot/buffer-layout/issues/17 [ci:travis]: https://travis-ci.org/pabigot/buffer-layout [ci:coveralls]: https://coveralls.io/github/pabigot/buffer-layout [node:issue#3992]: https://github.com/nodejs/node/issues/3992 diff --git a/lib/Layout.js b/lib/Layout.js index b66f206..0ed72bc 100644 --- a/lib/Layout.js +++ b/lib/Layout.js @@ -1920,9 +1920,12 @@ function fixBitwiseResult(v) { * {@link UInt|UInt} (or {@link UIntBE|UIntBE}) that is no more than 4 * bytes wide. * - * @param {bool} msb - `true` if the bit numbering starts at the most - * significant bit of the containing word; `false` (default) if it - * starts at the least significant bit of the containing word. + * @param {bool} [msb] - `true` if the bit numbering starts at the + * most significant bit of the containing word; `false` (default) if + * it starts at the least significant bit of the containing word. If + * the parameter at this position is a string and `property` is + * `undefined` the value of this argument will instead be used as the + * value of `property`. * * @param {string} [property] - initializer for {@link * Layout#property|property}. @@ -1936,6 +1939,11 @@ class BitStructure extends Layout { || (word instanceof UIntBE))) { throw new TypeError('word must be a UInt or UIntBE layout'); } + if (('string' === typeof msb) + && (undefined === property)) { + property = msb; + msb = undefined; + } if (4 < word.span) { throw new RangeError('word cannot exceed 32 bits'); } diff --git a/test/LayoutTest.js b/test/LayoutTest.js index 9cdde63..b7ab29e 100644 --- a/test/LayoutTest.js +++ b/test/LayoutTest.js @@ -1369,6 +1369,23 @@ suite('Layout', function() { assert.throws(function() {new lo.BitField(bs, 0);}, TypeError); assert.throws(function() {new lo.BitField(bs, 40);}, Error); }); + suite('ctor argument processing', function() { + it('should infer property when passed string', function() { + var bs = new lo.BitStructure(lo.u8(), 'flags'); + assert.strictEqual(bs.msb, false); + assert.strictEqual(bs.property, 'flags'); + }); + it('should respect msb without property', function() { + var bs = new lo.BitStructure(lo.u8(), true); + assert.strictEqual(bs.msb, true); + assert.strictEqual(bs.property, undefined); + }); + it('should accept msb with property', function() { + var bs = new lo.BitStructure(lo.u8(), 'flags', 'flags'); + assert.strictEqual(bs.msb, true); + assert.strictEqual(bs.property, 'flags'); + }); + }); // ctor argument processing test('invalid add', function() { assert.throws(function() { var bs = lo.bits(lo.u32()); From 48671a8e5c5059ab770bb467c0a84053a1862088 Mon Sep 17 00:00:00 2001 From: "Peter A. Bigot" Date: Sat, 6 Jan 2018 12:12:24 -0600 Subject: [PATCH 3/5] LayoutTest: convert to strict mode Closes #18. --- test/LayoutTest.js | 952 ++++++++++++++++++++++----------------------- 1 file changed, 475 insertions(+), 477 deletions(-) diff --git a/test/LayoutTest.js b/test/LayoutTest.js index b7ab29e..cb5afdd 100644 --- a/test/LayoutTest.js +++ b/test/LayoutTest.js @@ -1,14 +1,14 @@ -/* eslint-disable brace-style, max-statements-per-line, no-new, no-var */ +'use strict'; -var assert = require('assert'); -var util = require('util'); -var _ = require('lodash'); -var lo = require('../lib/Layout'); +const assert = require('assert'); +const util = require('util'); +const _ = require('lodash'); +const lo = require('../lib/Layout'); /* Some versions of Node have an undocumented in-place reverse. * That's not what we want. */ function reversedBuffer(b) { - var ba = Array.prototype.slice.call(b); + const ba = Array.prototype.slice.call(b); return Buffer.from(ba.reverse()); } @@ -28,12 +28,12 @@ function checkError(exc, expect, regex) { suite('Layout', function() { test('#reversedBuffer', function() { - var b = Buffer.from('0102030405', 'hex'); + const b = Buffer.from('0102030405', 'hex'); assert.equal(Buffer.from('0504030201', 'hex').compare(reversedBuffer(b)), 0); }); suite('Buffer', function() { test('issue 3992', function() { - var buf = Buffer.alloc(4); + const buf = Buffer.alloc(4); buf.writeIntLE(-0x120000, 0, 4); assert.deepEqual(buf.toJSON().data, [0x00, 0x00, 0xee, 0xff]); buf.writeIntBE(-0x120000, 0, 4); @@ -42,39 +42,39 @@ suite('Layout', function() { }); suite('Layout', function() { test('anonymous ctor', function() { - var d = new lo.Layout(8); + const d = new lo.Layout(8); assert(d instanceof lo.Layout); assert.equal(d.span, 8); assert.equal(d.getSpan(), d.span); assert.strictEqual(d.property, undefined); }); test('named ctor', function() { - var d = new lo.Layout(8, 'tag'); + const d = new lo.Layout(8, 'tag'); assert(d instanceof lo.Layout); assert.equal(d.span, 8); assert.equal(d.getSpan(), d.span); assert.equal(d.property, 'tag'); }); test('invalid ctor', function() { - assert.throws(function() {new lo.Layout();}, TypeError); - assert.throws(function() {new lo.Layout('3');}, TypeError); - assert.throws(function() {new lo.Layout('three');}, TypeError); + assert.throws(() => new lo.Layout(), TypeError); + assert.throws(() => new lo.Layout('3'), TypeError); + assert.throws(() => new lo.Layout('three'), TypeError); }); test('abstractness', function() { - var d = new lo.Layout(3); - var b = Buffer.alloc(3); - assert.throws(function() {d.decode(b);}); - assert.throws(function() {d.encode('sth', b);}); + const d = new lo.Layout(3); + const b = Buffer.alloc(3); + assert.throws(() => d.decode(b)); + assert.throws(() => d.encode('sth', b)); }); test('#getSpan', function() { assert.equal((new lo.Layout(3)).getSpan(), 3); - assert.throws(function() {(new lo.Layout(-1)).getSpan();}, RangeError); + assert.throws(() => (new lo.Layout(-1)).getSpan(), RangeError); }); }); suite('UInt', function() { test('u8', function() { - var d = lo.u8('t'); - var b = Buffer.alloc(1); + const d = lo.u8('t'); + const b = Buffer.alloc(1); assert(d instanceof lo.UInt); assert(d instanceof lo.Layout); assert.equal(d.span, 1); @@ -87,8 +87,8 @@ suite('Layout', function() { assert.equal(d.decode(b), 23); }); test('u16', function() { - var d = lo.u16('t'); - var b = Buffer.alloc(2); + const d = lo.u16('t'); + const b = Buffer.alloc(2); assert(d instanceof lo.UInt); assert(d instanceof lo.Layout); assert.equal(d.span, 2); @@ -101,15 +101,15 @@ suite('Layout', function() { assert.equal(d.decode(b), 0x1234); }); test('u24', function() { - var d = lo.u24('t'); - var b = Buffer.alloc(3); + const d = lo.u24('t'); + const b = Buffer.alloc(3); assert.equal(d.span, 3); assert.equal(0x563412, d.decode(Buffer.from('123456', 'hex'))); - assert.throws(function() {d.encode(0x1234567, b);}); + assert.throws(() => d.encode(0x1234567, b)); }); test('u48', function() { - var d = lo.u48('t'); - var b = Buffer.alloc(6); + const d = lo.u48('t'); + const b = Buffer.alloc(6); assert(d instanceof lo.UInt); assert(d instanceof lo.Layout); assert.equal(d.span, 6); @@ -122,21 +122,21 @@ suite('Layout', function() { assert.equal(d.decode(b), 0x123456789abc); }); test('offset', function() { - var b = Buffer.alloc(4); + const b = Buffer.alloc(4); b.fill(0xa5); - var d = lo.u16('t'); + const d = lo.u16('t'); d.encode(0x3412, b, 1); assert.equal(Buffer.from('A51234A5', 'hex').compare(b), 0); assert.equal(0xA534, d.decode(b, 2)); }); test('invalid ctor', function() { - assert.throws(function() {new lo.UInt(8);}, RangeError); + assert.throws(() => new lo.UInt(8), RangeError); }); }); suite('UIntBE', function() { test('u16be', function() { - var d = lo.u16be('t'); - var b = Buffer.alloc(2); + const d = lo.u16be('t'); + const b = Buffer.alloc(2); assert(d instanceof lo.UIntBE); assert(d instanceof lo.Layout); assert.equal(d.span, 2); @@ -148,32 +148,32 @@ suite('Layout', function() { assert.equal(d.decode(b), 0x1234); }); test('u24be', function() { - var d = lo.u24be('t'); - var b = Buffer.alloc(3); + const d = lo.u24be('t'); + const b = Buffer.alloc(3); assert.equal(d.span, 3); assert.equal(0x123456, d.decode(Buffer.from('123456', 'hex'))); - assert.throws(function() {d.encode(0x1234567, b);}); - assert.throws(function() {d.encode(-1, b);}); + assert.throws(() => d.encode(0x1234567, b)); + assert.throws(() => d.encode(-1, b)); }); test('u32be', function() { - var d = lo.u32be('t'); - var b = Buffer.alloc(4); + const d = lo.u32be('t'); + const b = Buffer.alloc(4); assert.equal(d.span, 4); assert.equal(0x12345678, d.decode(Buffer.from('12345678', 'hex'))); - assert.throws(function() {d.encode(0x123456789, b);}); - assert.throws(function() {d.encode(-1, b);}); + assert.throws(() => d.encode(0x123456789, b)); + assert.throws(() => d.encode(-1, b)); }); test('u40be', function() { - var d = lo.u40be('t'); - var b = Buffer.alloc(5); + const d = lo.u40be('t'); + const b = Buffer.alloc(5); assert.equal(d.span, 5); assert.equal(0x123456789a, d.decode(Buffer.from('123456789a', 'hex'))); - assert.throws(function() {d.encode(0x123456789ab, b);}); - assert.throws(function() {d.encode(-1, b);}); + assert.throws(() => d.encode(0x123456789ab, b)); + assert.throws(() => d.encode(-1, b)); }); test('u48be', function() { - var d = lo.u48be('t'); - var b = Buffer.alloc(6); + const d = lo.u48be('t'); + const b = Buffer.alloc(6); assert(d instanceof lo.UIntBE); assert(d instanceof lo.Layout); assert.equal(d.span, 6); @@ -185,21 +185,21 @@ suite('Layout', function() { assert.equal(d.decode(b), 0x123456789abc); }); test('offset', function() { - var b = Buffer.alloc(4); + const b = Buffer.alloc(4); b.fill(0xa5); - var d = lo.u16be('t'); + const d = lo.u16be('t'); d.encode(0x1234, b, 1); assert.equal(Buffer.from('A51234A5', 'hex').compare(b), 0); assert.equal(0x34A5, d.decode(b, 2)); }); test('invalid ctor', function() { - assert.throws(function() {new lo.UIntBE(8);}, RangeError); + assert.throws(() => new lo.UIntBE(8), RangeError); }); }); suite('Int', function() { test('s8', function() { - var d = lo.s8('t'); - var b = Buffer.alloc(1); + const d = lo.s8('t'); + const b = Buffer.alloc(1); assert(d instanceof lo.Int); assert(d instanceof lo.Layout); assert.equal(d.span, 1); @@ -214,8 +214,8 @@ suite('Layout', function() { assert.equal(d.decode(b), -97); }); test('s16', function() { - var d = lo.s16('t'); - var b = Buffer.alloc(2); + const d = lo.s16('t'); + const b = Buffer.alloc(2); assert(d instanceof lo.Int); assert(d instanceof lo.Layout); assert.equal(d.span, 2); @@ -233,28 +233,28 @@ suite('Layout', function() { assert.equal(lo.u16be().decode(b), 0xc7cf); }); test('s24', function() { - var d = lo.s24('t'); - var b = Buffer.alloc(3); + const d = lo.s24('t'); + const b = Buffer.alloc(3); assert.equal(d.span, 3); assert.equal(0x563412, d.decode(Buffer.from('123456', 'hex'))); assert.equal(-1, d.decode(Buffer.from('FFFFFF', 'hex'))); assert.equal(-0x800000, d.decode(Buffer.from('000080', 'hex'))); - assert.throws(function() {d.encode(0x800000, b);}); - assert.throws(function() {d.encode(-0x800001, b);}); + assert.throws(() => d.encode(0x800000, b)); + assert.throws(() => d.encode(-0x800001, b)); }); test('s40', function() { - var d = lo.s40('t'); - var b = Buffer.alloc(5); + const d = lo.s40('t'); + const b = Buffer.alloc(5); assert.equal(d.span, 5); assert.equal(0x123456789a, d.decode(Buffer.from('9a78563412', 'hex'))); assert.equal(-1, d.decode(Buffer.from('FFFFFFFFFF', 'hex'))); assert.equal(-0x8000000000, d.decode(Buffer.from('0000000080', 'hex'))); - assert.throws(function() {d.encode(0x8000000000, b);}); - assert.throws(function() {d.encode(-0x8000000001, b);}); + assert.throws(() => d.encode(0x8000000000, b)); + assert.throws(() => d.encode(-0x8000000001, b)); }); test('s48', function() { - var d = lo.s48('t'); - var b = Buffer.alloc(6); + const d = lo.s48('t'); + const b = Buffer.alloc(6); assert(d instanceof lo.Int); assert(d instanceof lo.Layout); assert.equal(d.span, 6); @@ -272,13 +272,13 @@ suite('Layout', function() { assert.equal(lo.u48be().decode(b), 0x8720f279b78f); }); test('invalid ctor', function() { - assert.throws(function() {new lo.Int(8);}, RangeError); + assert.throws(() => new lo.Int(8), RangeError); }); }); suite('IntBE', function() { test('s16be', function() { - var d = lo.s16be('t'); - var b = Buffer.alloc(2); + const d = lo.s16be('t'); + const b = Buffer.alloc(2); assert(d instanceof lo.IntBE); assert(d instanceof lo.Layout); assert.equal(d.span, 2); @@ -296,38 +296,38 @@ suite('Layout', function() { assert.equal(lo.u16().decode(b), 0xc7cf); }); test('s24be', function() { - var d = lo.s24be('t'); - var b = Buffer.alloc(3); + const d = lo.s24be('t'); + const b = Buffer.alloc(3); assert.equal(d.span, 3); assert.equal(0x123456, d.decode(Buffer.from('123456', 'hex'))); assert.equal(-1, d.decode(Buffer.from('FFFFFF', 'hex'))); assert.equal(-0x800000, d.decode(Buffer.from('800000', 'hex'))); - assert.throws(function() {d.encode(0x800000, b);}); - assert.throws(function() {d.encode(-0x800001, b);}); + assert.throws(() => d.encode(0x800000, b)); + assert.throws(() => d.encode(-0x800001, b)); }); test('s32be', function() { - var d = lo.s32be('t'); - var b = Buffer.alloc(4); + const d = lo.s32be('t'); + const b = Buffer.alloc(4); assert.equal(d.span, 4); assert.equal(0x12345678, d.decode(Buffer.from('12345678', 'hex'))); assert.equal(-1, d.decode(Buffer.from('FFFFFFFF', 'hex'))); assert.equal(-0x80000000, d.decode(Buffer.from('80000000', 'hex'))); - assert.throws(function() {d.encode(0x80000000, b);}); - assert.throws(function() {d.encode(-0x80000001, b);}); + assert.throws(() => d.encode(0x80000000, b)); + assert.throws(() => d.encode(-0x80000001, b)); }); test('s40be', function() { - var d = lo.s40be('t'); - var b = Buffer.alloc(5); + const d = lo.s40be('t'); + const b = Buffer.alloc(5); assert.equal(d.span, 5); assert.equal(0x123456789a, d.decode(Buffer.from('123456789a', 'hex'))); assert.equal(-1, d.decode(Buffer.from('FFFFFFFFFF', 'hex'))); assert.equal(-0x8000000000, d.decode(Buffer.from('8000000000', 'hex'))); - assert.throws(function() {d.encode(0x8000000000, b);}); - assert.throws(function() {d.encode(-0x8000000001, b);}); + assert.throws(() => d.encode(0x8000000000, b)); + assert.throws(() => d.encode(-0x8000000001, b)); }); test('s48be', function() { - var d = lo.s48be('t'); - var b = Buffer.alloc(6); + const d = lo.s48be('t'); + const b = Buffer.alloc(6); assert(d instanceof lo.IntBE); assert(d instanceof lo.Layout); assert.equal(d.span, 6); @@ -345,22 +345,22 @@ suite('Layout', function() { assert.equal(lo.u48().decode(b), 0x8720f279b78f); }); test('invalid ctor', function() { - assert.throws(function() {new lo.IntBE(8, 'u64');}, RangeError); + assert.throws(() => new lo.IntBE(8, 'u64'), RangeError); }); }); test('RoundedUInt64', function() { - var be = lo.nu64be('be'); - var le = lo.nu64('le'); + const be = lo.nu64be('be'); + const le = lo.nu64('le'); assert.equal(be.span, 8); assert.equal(le.span, 8); assert.equal(be.property, 'be'); assert.equal(le.property, 'le'); - var b = Buffer.from('0000003b2a2a873b', 'hex'); - var rb = reversedBuffer(b); - var v = 254110500667; - var ev = v; - var eb = Buffer.alloc(be.span); + let b = Buffer.from('0000003b2a2a873b', 'hex'); + let rb = reversedBuffer(b); + let v = 254110500667; + let ev = v; + const eb = Buffer.alloc(be.span); assert.equal(be.decode(b), ev); assert.equal(le.decode(rb), ev); assert.equal(be.encode(v, eb), 8); @@ -419,18 +419,18 @@ suite('Layout', function() { assert.equal(1, be.decode(b, 1)); }); test('RoundedInt64', function() { - var be = lo.ns64be('be'); - var le = lo.ns64('le'); + const be = lo.ns64be('be'); + const le = lo.ns64('le'); assert.equal(be.span, 8); assert.equal(le.span, 8); assert.equal(be.property, 'be'); assert.equal(le.property, 'le'); - var b = Buffer.from('ffffffff89abcdf0', 'hex'); - var rb = reversedBuffer(b); - var v = -1985229328; - var ev = v; - var eb = Buffer.alloc(be.span); + let b = Buffer.from('ffffffff89abcdf0', 'hex'); + let rb = reversedBuffer(b); + let v = -1985229328; + let ev = v; + const eb = Buffer.alloc(be.span); assert.equal(be.decode(b), ev); assert.equal(le.decode(rb), ev); assert.equal(be.encode(v, eb), 8); @@ -492,11 +492,11 @@ suite('Layout', function() { assert.equal(le.decode(Buffer.from('0000008001000000', 'hex')), 6442450944); }); test('Float', function() { - var be = lo.f32be('eff'); - var le = lo.f32('ffe'); - var f = 123456.125; - var fe = 3.174030951333261e-29; - var b = Buffer.alloc(4); + const be = lo.f32be('eff'); + const le = lo.f32('ffe'); + const f = 123456.125; + const fe = 3.174030951333261e-29; + let b = Buffer.alloc(4); assert(be instanceof lo.FloatBE); assert(be instanceof lo.Layout); assert.equal(be.span, 4); @@ -528,11 +528,11 @@ suite('Layout', function() { assert.equal(f, be.decode(b, 1)); }); test('Double', function() { - var be = lo.f64be('dee'); - var le = lo.f64('eed'); - var f = 123456789.125e+10; - var fe = 3.4283031083405533e-77; - var b = Buffer.alloc(8); + const be = lo.f64be('dee'); + const le = lo.f64('eed'); + const f = 123456789.125e+10; + const fe = 3.4283031083405533e-77; + let b = Buffer.alloc(8); assert(be instanceof lo.DoubleBE); assert(be instanceof lo.Layout); assert.equal(be.span, 8); @@ -564,20 +564,18 @@ suite('Layout', function() { }); suite('Sequence', function() { test('invalid ctor', function() { - assert.throws(function() {new lo.Sequence();}, TypeError); - assert.throws(function() {new lo.Sequence(lo.u8());}, TypeError); - assert.throws(function() {new lo.Sequence(lo.u8(), - '5 is not an integer');}, + assert.throws(() => new lo.Sequence(), TypeError); + assert.throws(() => new lo.Sequence(lo.u8()), TypeError); + assert.throws(() => new lo.Sequence(lo.u8(), '5 is not an integer'), TypeError); - assert.throws(function() {new lo.Sequence(lo.u8(), lo.u8());}, + assert.throws(() => new lo.Sequence(lo.u8(), lo.u8()), TypeError); - assert.throws(function() {new lo.Sequence(lo.u8(), - lo.offset(lo.f32()));}, + assert.throws(() => new lo.Sequence(lo.u8(), lo.offset(lo.f32())), TypeError); }); test('basics', function() { - var seq = new lo.Sequence(lo.u8(), 4, 'id'); - var b = Buffer.alloc(4); + const seq = new lo.Sequence(lo.u8(), 4, 'id'); + const b = Buffer.alloc(4); assert(seq instanceof lo.Sequence); assert(seq instanceof lo.Layout); assert(seq.elementLayout instanceof lo.UInt); @@ -593,17 +591,17 @@ suite('Layout', function() { assert.deepEqual(seq.decode(b), [1, 5, 6, 4]); }); test('in struct', function() { - var seq = lo.seq(lo.u8(), 4, 'id'); - var str = lo.struct([seq]); - var d = str.decode(Buffer.from('01020304', 'hex')); + const seq = lo.seq(lo.u8(), 4, 'id'); + const str = lo.struct([seq]); + const d = str.decode(Buffer.from('01020304', 'hex')); assert.deepEqual(d, {id: [1, 2, 3, 4]}); }); test('struct elts', function() { - var st = new lo.Structure([lo.u8('u8'), + const st = new lo.Structure([lo.u8('u8'), lo.s32('s32')]); - var seq = new lo.Sequence(st, 3); - var tv = [{u8: 1, s32: 1e4}, {u8: 0, s32: 0}, {u8: 3, s32: -324}]; - var b = Buffer.alloc(15); + const seq = new lo.Sequence(st, 3); + const tv = [{u8: 1, s32: 1e4}, {u8: 0, s32: 0}, {u8: 3, s32: -324}]; + const b = Buffer.alloc(15); assert.equal(st.span, 5); assert.equal(seq.count, 3); assert.strictEqual(seq.elementLayout, st); @@ -617,48 +615,48 @@ suite('Layout', function() { assert.equal(Buffer.from('0110270000027856341203bcfeffff', 'hex').compare(b), 0); }); - test('var count', function() { - var clo = lo.u8('n'); - var seq = lo.seq(lo.u8(), lo.offset(clo, -1), 'a'); - var st = lo.struct([clo, seq]); - var b = Buffer.from('03010203', 'hex'); - var obj = st.decode(b); + test('const count', function() { + const clo = lo.u8('n'); + const seq = lo.seq(lo.u8(), lo.offset(clo, -1), 'a'); + const st = lo.struct([clo, seq]); + let b = Buffer.from('03010203', 'hex'); + let obj = st.decode(b); assert.equal(obj.n, 3); assert.deepEqual(obj.a, [1, 2, 3]); b = Buffer.alloc(10); obj = {n: 3, a: [5, 6, 7, 8, 9]}; assert.equal(st.encode(obj, b), 6); - var span = st.getSpan(b); + const span = st.getSpan(b); assert.equal(span, 6); assert.equal(Buffer.from('050506070809', 'hex').compare(b.slice(0, span)), 0); }); // For variable span alone see CString in seq - test('var count+span', function() { - var clo = lo.u8('n'); - var seq = lo.seq(lo.cstr(), lo.offset(clo, -1), 'a'); - var st = lo.struct([clo, seq]); - var b = Buffer.from('036100620063646500', 'hex'); - var obj = st.decode(b); + test('const count+span', function() { + const clo = lo.u8('n'); + const seq = lo.seq(lo.cstr(), lo.offset(clo, -1), 'a'); + const st = lo.struct([clo, seq]); + let b = Buffer.from('036100620063646500', 'hex'); + let obj = st.decode(b); assert.equal(obj.n, 3); assert.deepEqual(obj.a, ['a', 'b', 'cde']); b = Buffer.alloc(10); obj = {n: 6, a: ['one', 'two']}; assert.equal(st.encode(obj, b), clo.span + 8); - var span = st.getSpan(b); + const span = st.getSpan(b); assert.equal(span, 9); assert.equal(Buffer.from('026f6e650074776f00', 'hex') .compare(b.slice(0, span)), 0); }); test('zero-count', function() { - var seq = lo.seq(lo.u8(), 0); - var b = Buffer.from('', 'hex'); + const seq = lo.seq(lo.u8(), 0); + const b = Buffer.from('', 'hex'); assert.equal(seq.span, 0); assert.deepEqual(seq.decode(b), []); }); test('greedy', function() { - var seq = lo.seq(lo.u16(), lo.greedy(2), 'a'); - var b = Buffer.from('ABCDE'); - var db = Buffer.alloc(6); + const seq = lo.seq(lo.u16(), lo.greedy(2), 'a'); + const b = Buffer.from('ABCDE'); + const db = Buffer.alloc(6); assert.equal(seq.getSpan(b), 4); assert.deepEqual(seq.decode(b), [0x4241, 0x4443]); db.fill('-'.charAt(0)); @@ -670,24 +668,24 @@ suite('Layout', function() { }); suite('Structure', function() { test('invalid ctor', function() { - assert.throws(function() {new lo.Structure();}, TypeError); - assert.throws(function() {new lo.Structure('stuff');}, TypeError); - assert.throws(function() {new lo.Structure(['stuff']);}, TypeError); + assert.throws(() => new lo.Structure(), TypeError); + assert.throws(() => new lo.Structure('stuff'), TypeError); + assert.throws(() => new lo.Structure(['stuff']), TypeError); // no unnamed variable-length fields - assert.throws(function() {new lo.Structure([lo.cstr()]);}, Error); + assert.throws(() => new lo.Structure([lo.cstr()]), Error); }); test('basics', function() { - var st = new lo.Structure([lo.u8('u8'), + const st = new lo.Structure([lo.u8('u8'), lo.u16('u16'), lo.s16be('s16be')]); - var b = Buffer.alloc(5); + const b = Buffer.alloc(5); assert(st instanceof lo.Structure); assert(st instanceof lo.Layout); assert.equal(st.span, 5); assert.equal(st.getSpan(), st.span); assert.strictEqual(st.property, undefined); b.fill(0); - var obj = st.decode(b); + let obj = st.decode(b); assert.deepEqual(obj, {u8: 0, u16: 0, s16be: 0}); obj = {u8: 21, u16: 0x1234, s16be: -5432}; assert.equal(st.encode(obj, b), st.span); @@ -695,13 +693,13 @@ suite('Layout', function() { assert.deepEqual(st.decode(b), obj); }); test('padding', function() { - var st = new lo.Structure([lo.u16('u16'), + const st = new lo.Structure([lo.u16('u16'), lo.u8(), lo.s16be('s16be')]); - var b = Buffer.alloc(5); + const b = Buffer.alloc(5); assert.equal(st.span, 5); b.fill(0); - var obj = st.decode(b); + let obj = st.decode(b); assert.deepEqual(obj, {u16: 0, s16be: 0}); b.fill(0xFF); obj = {u16: 0x1234, s16be: -5432}; @@ -710,13 +708,13 @@ suite('Layout', function() { assert.deepEqual(st.decode(b), obj); }); test('missing', function() { - var st = new lo.Structure([lo.u16('u16'), + const st = new lo.Structure([lo.u16('u16'), lo.u8('u8'), lo.s16be('s16be')]); - var b = Buffer.alloc(5); + const b = Buffer.alloc(5); assert.equal(st.span, 5); b.fill(0); - var obj = st.decode(b); + let obj = st.decode(b); assert.deepEqual(obj, {u16: 0, u8: 0, s16be: 0}); b.fill(0xa5); obj = {u16: 0x1234, s16be: -5432}; @@ -725,28 +723,28 @@ suite('Layout', function() { assert.deepEqual(st.decode(b), _.extend(obj, {u8: 0xa5})); }); test('update', function() { - var st = new lo.Structure([lo.u8('u8'), + const st = new lo.Structure([lo.u8('u8'), lo.u16('u16'), lo.s16be('s16be')]); - var b = Buffer.from('153412eac8', 'hex'); - var rc = st.decode(b, 0); + const b = Buffer.from('153412eac8', 'hex'); + const rc = st.decode(b, 0); assert.deepEqual(rc, {u8: 21, u16: 0x1234, s16be: -5432}); }); test('nested', function() { - var st = new lo.Structure([lo.u8('u8'), + const st = new lo.Structure([lo.u8('u8'), lo.u16('u16'), lo.s16be('s16be')], 'st'); - var cst = new lo.Structure([lo.u32('u32'), + const cst = new lo.Structure([lo.u32('u32'), st, lo.s24('s24')]); - var obj = {u32: 0x12345678, + const obj = {u32: 0x12345678, st: { u8: 23, u16: 65432, s16be: -12345, }, s24: -123456}; - var b = Buffer.alloc(12); + const b = Buffer.alloc(12); assert.equal(st.span, 5); assert.equal(st.property, 'st'); assert.equal(cst.span, 12); @@ -755,33 +753,33 @@ suite('Layout', function() { assert.deepEqual(cst.decode(b), obj); }); test('empty', function() { - var st = lo.struct([], 'st'); - var b = Buffer.from('', 'hex'); + const st = lo.struct([], 'st'); + const b = Buffer.from('', 'hex'); assert.equal(st.span, 0); assert.deepEqual(st.decode(b), {}); }); test('offset-variant', function() { - var st = lo.struct([lo.cstr('s')], 'st'); + const st = lo.struct([lo.cstr('s')], 'st'); assert(0 > st.span); - var b = Buffer.alloc(5); + const b = Buffer.alloc(5); b.fill(0xa5); - var obj = {s: 'ab'}; + const obj = {s: 'ab'}; st.encode(obj, b, 1); assert.equal(Buffer.from('a5616200a5', 'hex').compare(b), 0); assert.equal(3, st.getSpan(b, 1)); assert.deepEqual(st.decode(b, 1), obj); }); test('empty encode fixed span', function() { - var slo = lo.struct([lo.u8('a'), lo.u8('b')]); + const slo = lo.struct([lo.u8('a'), lo.u8('b')]); assert.equal(slo.span, 2); - var b = Buffer.alloc(10); + const b = Buffer.alloc(10); assert.equal(slo.encode({}, b), slo.span); assert.equal(slo.encode({}, b, 1), slo.span); }); test('empty encode variable span', function() { - var slo = lo.struct([lo.u8('a'), lo.cstr('s')]); + const slo = lo.struct([lo.u8('a'), lo.cstr('s')]); assert.equal(slo.span, -1); - var b = Buffer.alloc(10); + const b = Buffer.alloc(10); assert.equal(slo.encode({}, b), 1); assert.equal(slo.encode({}, b, 5), 1); assert.equal(slo.encode({a: 5}, b), 1); @@ -791,23 +789,23 @@ suite('Layout', function() { }); suite('replicate', function() { test('uint', function() { - var src = lo.u32('hi'); - var dst = src.replicate('lo'); + const src = lo.u32('hi'); + const dst = src.replicate('lo'); assert(dst instanceof src.constructor); assert.equal(dst.span, src.span); assert.equal(dst.property, 'lo'); }); test('struct', function() { - var src = new lo.Structure([lo.u8('a'), lo.s32('b')], 'hi'); - var dst = src.replicate('lo'); + const src = new lo.Structure([lo.u8('a'), lo.s32('b')], 'hi'); + const dst = src.replicate('lo'); assert(dst instanceof src.constructor); assert.equal(dst.span, src.span); assert.strictEqual(dst.fields, src.fields); assert.equal(dst.property, 'lo'); }); test('sequence', function() { - var src = new lo.Sequence(lo.u16(), 20, 'hi'); - var dst = src.replicate('lo'); + const src = new lo.Sequence(lo.u16(), 20, 'hi'); + const dst = src.replicate('lo'); assert(dst instanceof src.constructor); assert.equal(dst.span, src.span); assert.equal(dst.count, src.count); @@ -815,25 +813,25 @@ suite('Layout', function() { assert.equal(dst.property, 'lo'); }); test('add', function() { - var src = lo.u32(); - var dst = src.replicate('p'); + const src = lo.u32(); + const dst = src.replicate('p'); assert(dst instanceof src.constructor); assert.strictEqual(src.property, undefined); assert.equal(dst.property, 'p'); }); test('remove', function() { - var src = lo.u32('p'); - var dst = src.replicate(); + const src = lo.u32('p'); + const dst = src.replicate(); assert(dst instanceof src.constructor); assert.equal(src.property, 'p'); assert.strictEqual(dst.property, undefined); }); test('layoutFor', function() { - var u8 = lo.u8('u8'); - var s32 = lo.s32('s32'); - var cstr = lo.cstr('cstr'); - var u16 = lo.u16('u16'); - var d = lo.struct([u8, s32, cstr, u16], 's'); + const u8 = lo.u8('u8'); + const s32 = lo.s32('s32'); + const cstr = lo.cstr('cstr'); + const u16 = lo.u16('u16'); + const d = lo.struct([u8, s32, cstr, u16], 's'); assert.throws(() => d.layoutFor(), err => ('property must be string' === err.message)); assert.strictEqual(d.layoutFor('u8'), u8); @@ -841,18 +839,18 @@ suite('Layout', function() { assert.strictEqual(d.layoutFor('other'), undefined); }); test('nameWithProperty', function() { - var s32 = lo.s32('s32'); - var u16 = lo.u16('u16'); - var d = lo.struct([s32, lo.u16(), u16], 's'); + const s32 = lo.s32('s32'); + const u16 = lo.u16('u16'); + const d = lo.struct([s32, lo.u16(), u16], 's'); assert.equal(lo.nameWithProperty('struct', d), 'struct[s]'); assert.equal(lo.nameWithProperty('pfx', d.fields[1]), 'pfx'); }); test('offsetOf', function() { - var u8 = lo.u8('u8'); - var s32 = lo.s32('s32'); - var cstr = lo.cstr('cstr'); - var u16 = lo.u16('u16'); - var d = lo.struct([u8, s32, cstr, u16], 's'); + const u8 = lo.u8('u8'); + const s32 = lo.s32('s32'); + const cstr = lo.cstr('cstr'); + const u16 = lo.u16('u16'); + const d = lo.struct([u8, s32, cstr, u16], 's'); assert.throws(() => d.offsetOf(), err => ('property must be string' === err.message)); assert.strictEqual(d.offsetOf('u8'), 0); @@ -864,23 +862,23 @@ suite('Layout', function() { }); suite('VariantLayout', function() { test('invalid ctor', function() { - var un = new lo.Union(lo.u8(), lo.u32()); - assert.throws(function() {new lo.VariantLayout();}, TypeError); - assert.throws(function() {new lo.VariantLayout('other');}, TypeError); - assert.throws(function() {new lo.VariantLayout(un);}, TypeError); - assert.throws(function() {new lo.VariantLayout(un, 1.2);}, TypeError); - assert.throws(function() {new lo.VariantLayout(un, 'str');}, TypeError); - assert.throws(function() {new lo.VariantLayout(un, 1);}, TypeError); - assert.throws(function() {new lo.VariantLayout(un, 1, 'other');}, + const un = new lo.Union(lo.u8(), lo.u32()); + assert.throws(() => new lo.VariantLayout(), TypeError); + assert.throws(() => new lo.VariantLayout('other'), TypeError); + assert.throws(() => new lo.VariantLayout(un), TypeError); + assert.throws(() => new lo.VariantLayout(un, 1.2), TypeError); + assert.throws(() => new lo.VariantLayout(un, 'str'), TypeError); + assert.throws(() => new lo.VariantLayout(un, 1), TypeError); + assert.throws(() => new lo.VariantLayout(un, 1, 'other'), TypeError); - assert.throws(function() {new lo.VariantLayout(un, 1, lo.f64());}, + assert.throws(() => new lo.VariantLayout(un, 1, lo.f64()), Error); - assert.throws(function() {new lo.VariantLayout(un, 1, lo.f32());}, + assert.throws(() => new lo.VariantLayout(un, 1, lo.f32()), TypeError); }); test('ctor', function() { - var un = new lo.Union(lo.u8(), lo.u32()); - var d = new lo.VariantLayout(un, 1, lo.f32(), 'd'); + const un = new lo.Union(lo.u8(), lo.u32()); + const d = new lo.VariantLayout(un, 1, lo.f32(), 'd'); assert(d instanceof lo.VariantLayout); assert(d instanceof lo.Layout); assert.strictEqual(d.union, un); @@ -889,52 +887,52 @@ suite('Layout', function() { assert.equal(d.property, 'd'); }); test('span', function() { - var un = new lo.Union(lo.u8(), lo.u32()); - var d = new lo.VariantLayout(un, 1, lo.cstr(), 's'); - var b = Buffer.alloc(12); + const un = new lo.Union(lo.u8(), lo.u32()); + const d = new lo.VariantLayout(un, 1, lo.cstr(), 's'); + const b = Buffer.alloc(12); assert.equal(d.encode({s: 'hi!'}, b), 5); assert.equal(un.getSpan(b), 5); assert.equal(Buffer.from('0168692100', 'hex').compare(b.slice(0, 5)), 0); // This one overruns the Buffer - assert.throws(function() {d.encode({s: 'far too long'}, b);}, + assert.throws(() => d.encode({s: 'far too long'}, b), RangeError); // This one fits in the buffer but overruns the union - assert.throws(function() {d.encode({s: 'too long'}, b);}, Error); + assert.throws(() => d.encode({s: 'too long'}, b), Error); }); }); suite('ExternalLayout', function() { test('ctor', function() { - var el = new lo.ExternalLayout(-1, 'prop'); + const el = new lo.ExternalLayout(-1, 'prop'); assert(el instanceof lo.ExternalLayout); assert(el instanceof lo.Layout); assert.equal(el.property, 'prop'); - assert.throws(function() {el.isCount();}, Error); + assert.throws(() => el.isCount(), Error); }); }); suite('GreedyCount', function() { test('ctor', function() { - var el = lo.greedy(); + const el = lo.greedy(); assert(el instanceof lo.GreedyCount); assert(el instanceof lo.ExternalLayout); assert.equal(el.elementSpan, 1); assert.strictEqual(el.property, undefined); - var nel = lo.greedy(5, 'name'); + const nel = lo.greedy(5, 'name'); assert(nel instanceof lo.GreedyCount); assert(nel instanceof lo.ExternalLayout); assert.equal(nel.elementSpan, 5); assert.equal(nel.property, 'name'); - assert.throws(function() {lo.greedy('hi');}, TypeError); - assert.throws(function() {lo.greedy(0);}, TypeError); + assert.throws(() => lo.greedy('hi'), TypeError); + assert.throws(() => lo.greedy(0), TypeError); }); test('#decode', function() { - var el = lo.greedy(); - var b = Buffer.alloc(10); + const el = lo.greedy(); + const b = Buffer.alloc(10); assert.equal(el.decode(b), b.length); assert.equal(el.decode(b, 3), b.length - 3); - var nel = lo.greedy(3); + const nel = lo.greedy(3); assert.equal(nel.decode(b), 3); assert.equal(nel.decode(b, 1), 3); assert.equal(nel.decode(b, 2), 2); @@ -942,13 +940,13 @@ suite('Layout', function() { }); suite('OffsetLayout', function() { test('ctor', function() { - var u8 = lo.u8(); - var l0 = new lo.OffsetLayout(u8); + const u8 = lo.u8(); + const l0 = new lo.OffsetLayout(u8); assert(l0 instanceof lo.OffsetLayout); assert(l0 instanceof lo.ExternalLayout); - var nl = new lo.OffsetLayout(u8, -3, 'nl'); - var dl = new lo.OffsetLayout(lo.u8('ol'), 5); - var al = new lo.OffsetLayout(u8, 21); + const nl = new lo.OffsetLayout(u8, -3, 'nl'); + const dl = new lo.OffsetLayout(lo.u8('ol'), 5); + const al = new lo.OffsetLayout(u8, 21); assert.strictEqual(l0.layout, u8); assert.equal(l0.offset, 0); assert.strictEqual(l0.property, undefined); @@ -962,65 +960,65 @@ suite('Layout', function() { assert.strictEqual(al.property, undefined); }); test('codec', function() { - var u8 = lo.u8(); - var bl = lo.offset(u8, -1, 'bl'); - var al = lo.offset(u8, 1, 'al'); - var b = Buffer.from('0001020304050607', 'hex'); + const u8 = lo.u8(); + const bl = lo.offset(u8, -1, 'bl'); + const al = lo.offset(u8, 1, 'al'); + const b = Buffer.from('0001020304050607', 'hex'); assert.equal(u8.decode(b), 0); assert.equal(al.decode(b), 1); - assert.throws(function() {bl.decode(b);}, RangeError); + assert.throws(() => bl.decode(b), RangeError); assert.equal(u8.decode(b, 4), 4); assert.equal(al.decode(b, 4), 5); assert.equal(bl.decode(b, 4), 3); assert.equal(u8.encode(0x80, b), 1); assert.equal(al.encode(0x91, b), 1); - assert.throws(function() {bl.encode(0x70, b);}, RangeError); + assert.throws(() => bl.encode(0x70, b), RangeError); assert.equal(u8.encode(0x84, b, 4), 1); assert.equal(al.encode(0x94, b, 4), 1); assert.equal(bl.encode(0x74, b, 4), 1); assert.equal(Buffer.from('8091027484940607', 'hex').compare(b), 0); }); test('invalid ctor', function() { - assert.throws(function() {new lo.OffsetLayout('hi');}, TypeError); - assert.throws(function() {new lo.OffsetLayout(lo.u8(), 'hi');}, + assert.throws(() => new lo.OffsetLayout('hi'), TypeError); + assert.throws(() => new lo.OffsetLayout(lo.u8(), 'hi'), TypeError); }); }); suite('UnionDiscriminator', function() { test('abstract', function() { - var ud = new lo.UnionDiscriminator('p'); + const ud = new lo.UnionDiscriminator('p'); assert.equal(ud.property, 'p'); - assert.throws(function() {ud.decode(Buffer.from('00', 'hex'));}, Error); - assert.throws(function() {ud.encode(0, Buffer.alloc(1));}, Error); + assert.throws(() => ud.decode(Buffer.from('00', 'hex')), Error); + assert.throws(() => ud.encode(0, Buffer.alloc(1)), Error); }); }); suite('UnionLayoutDiscriminator', function() { test('invalid ctor', function() { - assert.throws(function() {new lo.UnionLayoutDiscriminator('hi');}, + assert.throws(() => new lo.UnionLayoutDiscriminator('hi'), TypeError); - assert.throws(function() {lo.unionLayoutDiscriminator('hi');}, + assert.throws(() => lo.unionLayoutDiscriminator('hi'), TypeError); - assert.throws(function() {new lo.UnionLayoutDiscriminator(lo.f32());}, + assert.throws(() => new lo.UnionLayoutDiscriminator(lo.f32()), TypeError); - assert.throws(function() { + assert.throws(() => { new lo.UnionLayoutDiscriminator(lo.u8(), 'hi'); }, TypeError); }); }); suite('Union', function() { test('invalid ctor', function() { - assert.throws(function() {new lo.Union();}, TypeError); - assert.throws(function() {new lo.Union('other');}, TypeError); - assert.throws(function() {new lo.Union(lo.f32());}, TypeError); - assert.throws(function() {new lo.Union(lo.u8(), 'other');}, TypeError); - assert.throws(function() {new lo.Union(lo.u8(), lo.cstr());}, Error); + assert.throws(() => new lo.Union(), TypeError); + assert.throws(() => new lo.Union('other'), TypeError); + assert.throws(() => new lo.Union(lo.f32()), TypeError); + assert.throws(() => new lo.Union(lo.u8(), 'other'), TypeError); + assert.throws(() => new lo.Union(lo.u8(), lo.cstr()), Error); }); test('basics', function() { - var dlo = lo.u8(); - var vlo = new lo.Sequence(lo.u8(), 8); - var un = new lo.Union(dlo, vlo); - var clo = un.defaultLayout; - var b = Buffer.alloc(9); + const dlo = lo.u8(); + const vlo = new lo.Sequence(lo.u8(), 8); + const un = new lo.Union(dlo, vlo); + const clo = un.defaultLayout; + const b = Buffer.alloc(9); assert(un instanceof lo.Union); assert(un instanceof lo.Layout); assert.equal(un.span, 9); @@ -1036,7 +1034,7 @@ suite('Layout', function() { assert.equal(dlo.span + vlo.span, un.span); assert.strictEqual(un.property, undefined); b.fill(0); - var o = un.decode(b); + const o = un.decode(b); assert.equal(o.variant, 0); assert.deepEqual(o.content, [0, 0, 0, 0, 0, 0, 0, 0]); o.variant = 5; @@ -1046,15 +1044,15 @@ suite('Layout', function() { assert.equal(Buffer.from('050000000300000007', 'hex').compare(b), 0); }); test('variants', function() { - var dlo = lo.u8('v'); - var vlo = new lo.Sequence(lo.u8(), 4, 'c'); - var un = new lo.Union(dlo, vlo); - var b = Buffer.alloc(5); + const dlo = lo.u8('v'); + const vlo = new lo.Sequence(lo.u8(), 4, 'c'); + const un = new lo.Union(dlo, vlo); + const b = Buffer.alloc(5); assert.strictEqual(un.getVariant(1), undefined); b.fill(0); assert.deepEqual(un.decode(b), {v: 0, c: [0, 0, 0, 0]}); - var lo1 = lo.u32(); - var v1 = un.addVariant(1, lo1, 'v1'); + const lo1 = lo.u32(); + const v1 = un.addVariant(1, lo1, 'v1'); assert(v1 instanceof lo.VariantLayout); assert.equal(v1.variant, 1); assert.strictEqual(v1.layout, lo1); @@ -1062,33 +1060,33 @@ suite('Layout', function() { assert.strictEqual(un.getVariant(b), v1); assert.deepEqual(v1.decode(b), {v1: 0x01010101}); assert.deepEqual(un.decode(b), {v1: 0x01010101}); - var lo2 = lo.f32(); - var v2 = un.addVariant(2, lo2, 'v2'); + const lo2 = lo.f32(); + const v2 = un.addVariant(2, lo2, 'v2'); assert.equal(un.discriminator.encode(v2.variant, b), dlo.span); assert.strictEqual(un.getVariant(b), v2); assert.deepEqual(v2.decode(b), {v2: 2.3694278276172396e-38}); assert.deepEqual(un.decode(b), {v2: 2.3694278276172396e-38}); - var lo3 = new lo.Structure([lo.u8('a'), lo.u8('b'), lo.u16('c')]); - var v3 = un.addVariant(3, lo3, 'v3'); + const lo3 = new lo.Structure([lo.u8('a'), lo.u8('b'), lo.u16('c')]); + const v3 = un.addVariant(3, lo3, 'v3'); assert.equal(un.discriminator.encode(v3.variant, b), dlo.span); assert.strictEqual(un.getVariant(b), v3); assert.deepEqual(v3.decode(b), {v3: {a: 1, b: 1, c: 257}}); assert.deepEqual(un.decode(b), {v3: {a: 1, b: 1, c: 257}}); assert.equal(un.discriminator.encode(v2.variant, b), dlo.span); assert.equal(Buffer.from('0201010101', 'hex').compare(b), 0); - var obj = {v3: {a: 5, b: 6, c: 1540}}; + const obj = {v3: {a: 5, b: 6, c: 1540}}; assert.equal(lo3.encode(obj.v3, b), lo3.span); assert.equal(v3.encode(obj, b), un.span); assert.notEqual(un.span, vlo.span + lo3.span); assert.deepEqual(un.decode(b), obj); assert.equal(Buffer.from('0305060406', 'hex').compare(b), 0); - assert.throws(function() {v2.encode(obj, b);}, TypeError); - assert.throws(function() {v2.decode(b);}, Error); + assert.throws(() => v2.encode(obj, b), TypeError); + assert.throws(() => v2.decode(b), Error); }); test('custom default', function() { - var dlo = lo.u8('number'); - var vlo = new lo.Sequence(lo.u8(), 8, 'payload'); - var un = new lo.Union(dlo, vlo); + const dlo = lo.u8('number'); + const vlo = new lo.Sequence(lo.u8(), 8, 'payload'); + const un = new lo.Union(dlo, vlo); assert(un instanceof lo.Union); assert(un instanceof lo.Layout); assert(un.usesPrefixDiscriminator); @@ -1100,14 +1098,14 @@ suite('Layout', function() { assert.equal(un.defaultLayout.property, 'payload'); }); test('inStruct', function() { - var dlo = lo.u8('uid'); - var vlo = new lo.Sequence(lo.u8(), 3, 'payload'); - var un = new lo.Union(dlo, vlo, 'u'); - var st = new lo.Structure([lo.u16('u16'), + const dlo = lo.u8('uid'); + const vlo = new lo.Sequence(lo.u8(), 3, 'payload'); + const un = new lo.Union(dlo, vlo, 'u'); + const st = new lo.Structure([lo.u16('u16'), un, lo.s16('s16')]); - var b = Buffer.from('0001020304050607', 'hex'); - var obj = st.decode(b); + const b = Buffer.from('0001020304050607', 'hex'); + const obj = st.decode(b); assert.equal(obj.u16, 0x0100); assert.equal(obj.u.uid, 2); assert.deepEqual(obj.u.payload, [3, 4, 5]); @@ -1115,33 +1113,33 @@ suite('Layout', function() { obj.u16 = 0x5432; obj.s16 = -3; obj.u.payload[1] = 23; - var b2 = Buffer.alloc(st.span); + const b2 = Buffer.alloc(st.span); assert.equal(st.encode(obj, b2), st.span); assert.equal(Buffer.from('325402031705fdff', 'hex').compare(b2), 0); }); test('issue#6', function() { - var dlo = lo.u8('number'); - var vlo = new lo.Sequence(lo.u8(), 8, 'payload'); - var un = new lo.Union(dlo, vlo); - var b = Buffer.from('000102030405060708', 'hex'); - var obj = un.decode(b); + const dlo = lo.u8('number'); + const vlo = new lo.Sequence(lo.u8(), 8, 'payload'); + const un = new lo.Union(dlo, vlo); + const b = Buffer.from('000102030405060708', 'hex'); + const obj = un.decode(b); assert.equal(obj.number, 0); assert.deepEqual(obj.payload, [1, 2, 3, 4, 5, 6, 7, 8]); - var b2 = Buffer.alloc(un.span); + const b2 = Buffer.alloc(un.span); assert.equal(un.encode(obj, b2), dlo.span + vlo.span); assert.equal(b2.toString('hex'), b.toString('hex')); - var obj2 = {variant: obj.number, + const obj2 = {variant: obj.number, content: obj.payload}; - assert.throws(function() {un.encode(obj2, b2);}); + assert.throws(() => un.encode(obj2, b2)); }); test('issue#7.internal.anon', function() { - var dlo = lo.u8(); - var plo = new lo.Sequence(lo.u8(), 8, 'payload'); - var vlo = new lo.Structure([plo, dlo]); - var un = new lo.Union(lo.offset(dlo, plo.span), vlo); - var clo = un.defaultLayout; - var b = Buffer.from('000102030405060708', 'hex'); - var obj = un.decode(b); + const dlo = lo.u8(); + const plo = new lo.Sequence(lo.u8(), 8, 'payload'); + const vlo = new lo.Structure([plo, dlo]); + const un = new lo.Union(lo.offset(dlo, plo.span), vlo); + const clo = un.defaultLayout; + const b = Buffer.from('000102030405060708', 'hex'); + const obj = un.decode(b); assert(!un.usesPrefixDiscriminator); assert(un.discriminator instanceof lo.UnionLayoutDiscriminator); assert.equal(un.discriminator.property, 'variant'); @@ -1153,14 +1151,14 @@ suite('Layout', function() { assert.equal(obj.variant, 8); }); test('issue#7.internal.named', function() { - var dlo = lo.u8(); - var plo = new lo.Sequence(lo.u8(), 8, 'payload'); - var vlo = new lo.Structure([plo, dlo]); - var ud = new lo.UnionLayoutDiscriminator(lo.offset(dlo, plo.span), 'tag'); - var un = new lo.Union(ud, vlo); - var clo = un.defaultLayout; - var b = Buffer.from('000102030405060708', 'hex'); - var obj = un.decode(b); + const dlo = lo.u8(); + const plo = new lo.Sequence(lo.u8(), 8, 'payload'); + const vlo = new lo.Structure([plo, dlo]); + const ud = new lo.UnionLayoutDiscriminator(lo.offset(dlo, plo.span), 'tag'); + const un = new lo.Union(ud, vlo); + const clo = un.defaultLayout; + const b = Buffer.from('000102030405060708', 'hex'); + const obj = un.decode(b); assert(!un.usesPrefixDiscriminator); assert(un.discriminator instanceof lo.UnionLayoutDiscriminator); assert.equal(un.discriminator.property, 'tag'); @@ -1173,13 +1171,13 @@ suite('Layout', function() { assert.equal(9, un.getSpan(b)); }); test('issue#7.internal.named2', function() { - var dlo = lo.u8('vid'); - var plo = new lo.Sequence(lo.u8(), 8, 'payload'); - var vlo = new lo.Structure([plo, dlo]); - var un = new lo.Union(lo.offset(dlo, plo.span), vlo); - var clo = un.defaultLayout; - var b = Buffer.from('000102030405060708', 'hex'); - var obj = un.decode(b); + const dlo = lo.u8('vid'); + const plo = new lo.Sequence(lo.u8(), 8, 'payload'); + const vlo = new lo.Structure([plo, dlo]); + const un = new lo.Union(lo.offset(dlo, plo.span), vlo); + const clo = un.defaultLayout; + const b = Buffer.from('000102030405060708', 'hex'); + const obj = un.decode(b); assert(!un.usesPrefixDiscriminator); assert(un.discriminator instanceof lo.UnionLayoutDiscriminator); assert.equal(un.discriminator.property, 'vid'); @@ -1191,20 +1189,20 @@ suite('Layout', function() { assert.equal(obj.vid, 8); }); test('issue#7.external', function() { - var dlo = lo.u8('vid'); - var ud = new lo.UnionLayoutDiscriminator(lo.offset(dlo, -3), 'uid'); - var un = new lo.Union(ud, lo.u32('u32'), 'u'); - var st = new lo.Structure([dlo, lo.u16('u16'), un, lo.s16('s16')]); + const dlo = lo.u8('vid'); + const ud = new lo.UnionLayoutDiscriminator(lo.offset(dlo, -3), 'uid'); + const un = new lo.Union(ud, lo.u32('u32'), 'u'); + const st = new lo.Structure([dlo, lo.u16('u16'), un, lo.s16('s16')]); assert.equal(un.span, 4); assert.equal(st.span, 9); - var b = Buffer.from('000102030405060708', 'hex'); - var obj = st.decode(b); + const b = Buffer.from('000102030405060708', 'hex'); + let obj = st.decode(b); assert.equal(obj.vid, 0); assert.equal(obj.u16, 0x201); assert.equal(obj.s16, 0x807); assert.equal(obj.u.uid, 0); assert.equal(obj.u.u32, 0x06050403); - var b2 = Buffer.alloc(st.span); + const b2 = Buffer.alloc(st.span); assert.equal(st.encode(obj, b2), st.span); assert.equal(b2.compare(b), 0); @@ -1215,26 +1213,26 @@ suite('Layout', function() { assert.equal(obj.s16, 0x807); assert.equal(obj.u.v0, 0x06050403); - var flo = lo.f32('f32'); + const flo = lo.f32('f32'); un.addVariant(1, flo, 'vf'); - var fb = Buffer.from('01234500805a429876', 'hex'); - var fobj = st.decode(fb); + const fb = Buffer.from('01234500805a429876', 'hex'); + const fobj = st.decode(fb); assert.equal(fobj.vid, 1); assert.equal(fobj.u16, 0x4523); assert.equal(fobj.s16, 0x7698); assert.equal(fobj.u.vf, 54.625); }); test('from src', function() { - var un = new lo.Union(lo.u8('v'), lo.u32('u32')); - var v1 = un.addVariant(1, lo.f32(), 'f32'); - var v2 = un.addVariant(2, lo.seq(lo.u8(), 4), 'u8.4'); - var v3 = un.addVariant(3, lo.cstr(), 'str'); - var b = Buffer.alloc(un.span); + const un = new lo.Union(lo.u8('v'), lo.u32('u32')); + const v1 = un.addVariant(1, lo.f32(), 'f32'); + const v2 = un.addVariant(2, lo.seq(lo.u8(), 4), 'u8.4'); + const v3 = un.addVariant(3, lo.cstr(), 'str'); + const b = Buffer.alloc(un.span); assert.equal(un.span, 5); - var src = {v: 5, u32: 0x12345678}; - var vlo = un.getSourceVariant(src); + let src = {v: 5, u32: 0x12345678}; + let vlo = un.getSourceVariant(src); assert.strictEqual(vlo, undefined); assert.equal(un.encode(src, b), un.span); assert.equal(Buffer.from('0578563412', 'hex').compare(b), 0); @@ -1255,7 +1253,7 @@ suite('Layout', function() { assert.equal(un.encode(src, b), un.span); assert.equal(Buffer.from('0201020304', 'hex').compare(b), 0); - assert.throws(function() {un.getSourceVariant({other: 3});}, Error); + assert.throws(() => un.getSourceVariant({other: 3}), Error); src = {str: 'hi'}; vlo = un.getSourceVariant(src); assert.strictEqual(vlo, v3); @@ -1268,29 +1266,29 @@ suite('Layout', function() { assert.equal(vlo.getSpan(b), un.span); }); test('customize src', function() { - var un = lo.union(lo.u8('v'), lo.u32('u32')); - var csrc; + const un = lo.union(lo.u8('v'), lo.u32('u32')); + let csrc; un.configGetSourceVariant(function(src) { csrc = src; // eslint-disable-next-line no-invalid-this return this.defaultGetSourceVariant(src); }); - var src = {v: 3, u32: 29}; - var vlo = un.getSourceVariant(src); + const src = {v: 3, u32: 29}; + const vlo = un.getSourceVariant(src); assert.strictEqual(src, csrc); assert.strictEqual(vlo, undefined); }); test('variable span', function() { - var un = lo.union(lo.u8('v')); - var v1 = un.addVariant(1, lo.u32(), 'u32'); - var v2 = un.addVariant(2, lo.f64(), 'f64'); - var v3 = un.addVariant(3, lo.cstr(), 'str'); - var b = Buffer.alloc(16); + const un = lo.union(lo.u8('v')); + const v1 = un.addVariant(1, lo.u32(), 'u32'); + const v2 = un.addVariant(2, lo.f64(), 'f64'); + const v3 = un.addVariant(3, lo.cstr(), 'str'); + const b = Buffer.alloc(16); assert(0 > un.span); b.fill(0xFF); - assert.throws(function() {un.decode(b);}, Error); - var obj = {u32: 0x12345678}; + assert.throws(() => un.decode(b), Error); + let obj = {u32: 0x12345678}; assert.equal(un.encode(obj, b), 1 + 4); assert.equal(v1.getSpan(b), 5); assert.equal(un.getSpan(b), 5); @@ -1317,7 +1315,7 @@ suite('Layout', function() { assert.deepEqual(un.decode(b), obj); b[0] = 5; - assert.throws(function() {un.getSpan(b);}, Error); + assert.throws(() => un.getSpan(b), Error); b.fill(0xa5); assert.equal(un.encode(obj, b, 1), 1 + 3 + 1); @@ -1328,15 +1326,15 @@ suite('Layout', function() { assert.deepEqual(un.decode(b, 1), obj); }); test('variable-external', function() { - var dlo = lo.u8('v'); - var ud = lo.unionLayoutDiscriminator(lo.offset(dlo, -1)); - var un = lo.union(ud, null, 'u'); + const dlo = lo.u8('v'); + const ud = lo.unionLayoutDiscriminator(lo.offset(dlo, -1)); + const un = lo.union(ud, null, 'u'); assert(0 > un.span); assert(!un.usesPrefixDiscriminator); - var st = lo.struct([dlo, un], 'st'); - var v1 = un.addVariant(1, lo.cstr(), 's'); - var obj = {v: v1.variant, u: {s: 'hi'}}; - var b = Buffer.alloc(6); + const st = lo.struct([dlo, un], 'st'); + const v1 = un.addVariant(1, lo.cstr(), 's'); + const obj = {v: v1.variant, u: {s: 'hi'}}; + const b = Buffer.alloc(6); b.fill(0xa5); st.encode(obj, b, 1); assert.equal(Buffer.from('a501686900a5', 'hex').compare(b), 0); @@ -1345,12 +1343,12 @@ suite('Layout', function() { }); test('fromArray', function() { assert.strictEqual(lo.u8().fromArray([1]), undefined); - var st = new lo.Structure([lo.u8('a'), lo.u8('b'), lo.u16('c')]); + const st = new lo.Structure([lo.u8('a'), lo.u8('b'), lo.u16('c')]); assert.deepEqual(st.fromArray([1, 2, 3]), {a: 1, b: 2, c: 3}); assert.deepEqual(st.fromArray([1, 2]), {a: 1, b: 2}); - var un = new lo.Union(lo.u8('v'), lo.u32('c')); + const un = new lo.Union(lo.u8('v'), lo.u32('c')); assert.strictEqual(un.fromArray([1, 2, 3]), undefined); - var v1 = un.addVariant(1, st, 'v1'); + const v1 = un.addVariant(1, st, 'v1'); un.addVariant(2, lo.f32(), 'v2'); assert(v1 instanceof lo.VariantLayout); assert.deepEqual(un.getVariant(1).fromArray([1, 2, 3]), {a: 1, b: 2, c: 3}); @@ -1358,63 +1356,63 @@ suite('Layout', function() { }); suite('BitStructure', function() { test('invalid ctor', function() { - assert.throws(function() {new lo.BitStructure();}, TypeError); - assert.throws(function() {new lo.BitStructure(lo.f32());}, TypeError); - assert.throws(function() {new lo.BitStructure(lo.s32());}, TypeError); - assert.throws(function() {new lo.BitStructure(lo.u40());}, Error); + assert.throws(() => new lo.BitStructure(), TypeError); + assert.throws(() => new lo.BitStructure(lo.f32()), TypeError); + assert.throws(() => new lo.BitStructure(lo.s32()), TypeError); + assert.throws(() => new lo.BitStructure(lo.u40()), Error); - var bs = new lo.BitStructure(lo.u32()); - assert.throws(function() {new lo.BitField(lo.u32(), 8);}, TypeError); - assert.throws(function() {new lo.BitField(bs, 'hi');}, TypeError); - assert.throws(function() {new lo.BitField(bs, 0);}, TypeError); - assert.throws(function() {new lo.BitField(bs, 40);}, Error); + const bs = new lo.BitStructure(lo.u32()); + assert.throws(() => new lo.BitField(lo.u32(), 8), TypeError); + assert.throws(() => new lo.BitField(bs, 'hi'), TypeError); + assert.throws(() => new lo.BitField(bs, 0), TypeError); + assert.throws(() => new lo.BitField(bs, 40), Error); }); suite('ctor argument processing', function() { it('should infer property when passed string', function() { - var bs = new lo.BitStructure(lo.u8(), 'flags'); + const bs = new lo.BitStructure(lo.u8(), 'flags'); assert.strictEqual(bs.msb, false); assert.strictEqual(bs.property, 'flags'); }); it('should respect msb without property', function() { - var bs = new lo.BitStructure(lo.u8(), true); + const bs = new lo.BitStructure(lo.u8(), true); assert.strictEqual(bs.msb, true); assert.strictEqual(bs.property, undefined); }); it('should accept msb with property', function() { - var bs = new lo.BitStructure(lo.u8(), 'flags', 'flags'); + const bs = new lo.BitStructure(lo.u8(), 'flags', 'flags'); assert.strictEqual(bs.msb, true); assert.strictEqual(bs.property, 'flags'); }); }); // ctor argument processing test('invalid add', function() { - assert.throws(function() { - var bs = lo.bits(lo.u32()); + assert.throws(() => { + const bs = lo.bits(lo.u32()); bs.addField(30); bs.addField(3); }, Error); - assert.throws(function() { - var bs = lo.bits(lo.u8()); + assert.throws(() => { + const bs = lo.bits(lo.u8()); bs.addField(2); bs.addField(7); }, Error); - assert.throws(function() { - var bs = lo.bits(lo.u8()); + assert.throws(() => { + const bs = lo.bits(lo.u8()); bs.addField(0); }, Error); - assert.throws(function() { - var bs = lo.bits(lo.u8()); + assert.throws(() => { + const bs = lo.bits(lo.u8()); bs.addField(6); bs.addField(-2); }, Error); }); test('size', function() { - var bs = new lo.BitStructure(lo.u16()); - var bf10 = bs.addField(10, 'ten'); - var bf6 = bs.addField(6, 'six'); - var b = Buffer.alloc(bs.span); + const bs = new lo.BitStructure(lo.u16()); + const bf10 = bs.addField(10, 'ten'); + const bf6 = bs.addField(6, 'six'); + let b = Buffer.alloc(bs.span); assert.equal((1 << 10) - 1, 1023); assert.equal((1 << 6) - 1, 63); - var obj = bs.decode(Buffer.from('ffff', 'hex')); + const obj = bs.decode(Buffer.from('ffff', 'hex')); assert.equal(obj.ten, (1 << 10) - 1); assert.equal(obj.six, (1 << 6) - 1); assert.equal(bs.encode(obj, b), 2); @@ -1424,8 +1422,8 @@ suite('Layout', function() { bf10.encode((1 << 10) - 1); bf6.encode((1 << 6) - 1); assert.equal(bs._packedGetValue(), 0xFFFF); - assert.throws(function() {bf6.encode('hi', b);}, Error); - assert.throws(function() {bf6.encode(1 << 6, b);}, Error); + assert.throws(() => bf6.encode('hi', b), Error); + assert.throws(() => bf6.encode(1 << 6, b), Error); b = Buffer.alloc(2 + bs.span); b.fill(0xa5); @@ -1434,16 +1432,16 @@ suite('Layout', function() { assert.deepEqual(bs.decode(b, 1), obj); }); test('basic LSB', function() { - var pbl = lo.u32(); - var bs = new lo.BitStructure(pbl); + const pbl = lo.u32(); + const bs = new lo.BitStructure(pbl); assert(bs instanceof lo.Layout); assert.strictEqual(bs.word, pbl); assert(!bs.msb); assert(bs.fields instanceof Array); assert.equal(bs.fields.length, 0); - var bf1 = bs.addField(1, 'a'); - var bf2 = bs.addField(2, 'b'); + const bf1 = bs.addField(1, 'a'); + const bf2 = bs.addField(2, 'b'); assert.equal(bs.fields.length, 2); assert(bf1 instanceof lo.BitField); @@ -1462,24 +1460,24 @@ suite('Layout', function() { assert.equal(bf2.valueMask, 0x03); assert.equal(bf2.wordMask, 0x06); - assert.throws(function() {bs.addField(30);}); + assert.throws(() => bs.addField(30)); bs.addField(29, 'x'); - var bf3 = bs.fields[2]; + const bf3 = bs.fields[2]; assert.equal(bf3.bits, 29); assert.equal(bf3.start, 3); assert.equal(bf3.wordMask, 0xFFFFFFF8); }); test('basic MSB', function() { - var pbl = lo.u32(); - var bs = new lo.BitStructure(pbl, true); + const pbl = lo.u32(); + const bs = new lo.BitStructure(pbl, true); assert(bs instanceof lo.Layout); assert.strictEqual(bs.word, pbl); assert(bs.msb); assert(bs.fields instanceof Array); assert.equal(bs.fields.length, 0); - var bf1 = bs.addField(1, 'a'); - var bf2 = bs.addField(2, 'b'); + const bf1 = bs.addField(1, 'a'); + const bf2 = bs.addField(2, 'b'); assert.equal(bs.fields.length, 2); assert(bf1 instanceof lo.BitField); @@ -1500,32 +1498,32 @@ suite('Layout', function() { assert.equal(bf2.valueMask, 0x3); assert.equal(bf2.wordMask, 0x60000000); - assert.throws(function() {bs.addField(30);}); + assert.throws(() => bs.addField(30)); bs.addField(29, 'x'); - var bf3 = bs.fields[2]; + const bf3 = bs.fields[2]; assert.equal(bf3.bits, 29); assert.equal(bf3.start, 0); assert.equal(bf3.wordMask, 0x1FFFFFFF); }); test('lsb 32-bit field', function() { - var bs = new lo.BitStructure(lo.u32()); - var bf = bs.addField(32, 'x'); + const bs = new lo.BitStructure(lo.u32()); + const bf = bs.addField(32, 'x'); assert.equal(bf.bits, 32); assert.equal(bf.start, 0); assert.equal(bf.valueMask, 0xFFFFFFFF); assert.equal(bf.wordMask, 0xFFFFFFFF); }); test('msb 32-bit field', function() { - var bs = new lo.BitStructure(lo.u32(), true); - var bf = bs.addField(32, 'x'); + const bs = new lo.BitStructure(lo.u32(), true); + const bf = bs.addField(32, 'x'); assert.equal(bf.bits, 32); assert.equal(bf.start, 0); assert.equal(bf.valueMask, 0xFFFFFFFF); assert.equal(bf.wordMask, 0xFFFFFFFF); }); test('lsb coding', function() { - var bs = new lo.BitStructure(lo.u32()); - var b = Buffer.alloc(bs.span); + const bs = new lo.BitStructure(lo.u32()); + const b = Buffer.alloc(bs.span); bs.addField(1, 'a1'); bs.addField(4, 'b4'); bs.addField(11, 'c11'); @@ -1540,8 +1538,8 @@ suite('Layout', function() { assert.equal(Buffer.from('329e518a', 'hex').compare(b), 0); }); test('msb coding', function() { - var bs = new lo.BitStructure(lo.u32(), true); - var b = Buffer.alloc(bs.span); + const bs = new lo.BitStructure(lo.u32(), true); + const b = Buffer.alloc(bs.span); bs.addField(1, 'a1'); bs.addField(4, 'b4'); bs.addField(11, 'c11'); @@ -1556,10 +1554,10 @@ suite('Layout', function() { assert.equal(Buffer.from('518af14c', 'hex').compare(b), 0); }); test('fieldFor', function() { - var d = new lo.BitStructure(lo.u32(), true); - var b = d.addBoolean('b'); + const d = new lo.BitStructure(lo.u32(), true); + const b = d.addBoolean('b'); d.addField(4, 'b4'); - var c11 = d.addField(11, 'c11'); + const c11 = d.addField(11, 'c11'); d.addField(16, 'd16'); assert.throws(() => d.fieldFor(), err => ('property must be string' === err.message)); @@ -1568,9 +1566,9 @@ suite('Layout', function() { assert.strictEqual(d.fieldFor('other'), undefined); }); test('gap coding', function() { - var lsb = new lo.BitStructure(lo.u24()); - var msb = new lo.BitStructure(lo.u24(), true); - var b = Buffer.alloc(lsb.span); + const lsb = new lo.BitStructure(lo.u24()); + const msb = new lo.BitStructure(lo.u24(), true); + const b = Buffer.alloc(lsb.span); lsb.addField(7, 'a5'); lsb.addField(8); lsb.addField(9, 'b6'); @@ -1578,8 +1576,8 @@ suite('Layout', function() { msb.addField(8); msb.addField(9, 'b6'); b.fill(0xA5); - var lb = lsb.decode(b); - var mb = msb.decode(b); + const lb = lsb.decode(b); + const mb = msb.decode(b); assert.deepEqual(lb, {a5: 0x25, b6: 0x14b}); assert.deepEqual(mb, {a5: 0x52, b6: 0x1a5}); b.fill(0x69); @@ -1590,12 +1588,12 @@ suite('Layout', function() { assert.equal(Buffer.from('a569a5', 'hex').compare(b), 0); }); test('boolean', function() { - var bs = lo.bits(lo.u8()); + const bs = lo.bits(lo.u8()); bs.addField(1, 'v'); bs.addBoolean('b'); - var b = Buffer.alloc(bs.span); + const b = Buffer.alloc(bs.span); b[0] = 0x3; - var obj = bs.decode(b); + const obj = bs.decode(b); assert.strictEqual(1, obj.v); assert.notStrictEqual(1, obj.b); assert.strictEqual(true, obj.b); @@ -1610,32 +1608,32 @@ suite('Layout', function() { assert.equal(b[0], 0); bs.encode({}, b); assert.equal(b[0], 0); - assert.throws(function() {bs.encode({v: false}, b);}, - function(err) {return checkError(err, TypeError, /BitField.encode\[v\] value must be integer/);}); - assert.throws(function() {bs.encode({v: 1.2}, b);}, - function(err) {return checkError(err, TypeError, /BitField.encode\[v\] value must be integer/);}); - assert.throws(function() {bs.encode({b: 1.2}, b);}, - function(err) {return checkError(err, TypeError, /BitField.encode\[b\] value must be integer/);}); + assert.throws(() => bs.encode({v: false}, b), + err => checkError(err, TypeError, /BitField.encode\[v\] value must be integer/)); + assert.throws(() => bs.encode({v: 1.2}, b), + err => checkError(err, TypeError, /BitField.encode\[v\] value must be integer/)); + assert.throws(() => bs.encode({b: 1.2}, b), + err => checkError(err, TypeError, /BitField.encode\[b\] value must be integer/)); }); }); suite('Blob', function() { test('invalid ctor', function() { - assert.throws(function() {new lo.Blob();}, TypeError); - assert.throws(function() {new lo.Blob(lo.u8());}, TypeError); - assert.throws(function() {new lo.Blob(lo.offset(lo.f32()));}, + assert.throws(() => new lo.Blob(), TypeError); + assert.throws(() => new lo.Blob(lo.u8()), TypeError); + assert.throws(() => new lo.Blob(lo.offset(lo.f32())), TypeError); }); test('ctor', function() { - var bl = new lo.Blob(3, 'bl'); + const bl = new lo.Blob(3, 'bl'); assert(bl instanceof lo.Blob); assert(bl instanceof lo.Layout); assert.equal(bl.span, 3); assert.equal(bl.property, 'bl'); }); test('basics', function() { - var bl = new lo.Blob(3, 'bl'); - var b = Buffer.from('0102030405', 'hex'); - var bv = bl.decode(b); + const bl = new lo.Blob(3, 'bl'); + const b = Buffer.from('0102030405', 'hex'); + let bv = bl.decode(b); assert(bv instanceof Buffer); assert.equal(bv.length, bl.span); assert.equal(Buffer.from('010203', 'hex').compare(bv), 0); @@ -1644,32 +1642,32 @@ suite('Layout', function() { assert.equal(Buffer.from('030405', 'hex').compare(bv), 0); assert.equal(bl.encode(Buffer.from('112233', 'hex'), b, 1), 3); assert.equal(Buffer.from('0111223305', 'hex').compare(b), 0); - assert.throws(function() {bl.encode('ABC', b);}, Error); - assert.throws(function() {bl.encode(Buffer.from('0102', 'hex'), b);}, + assert.throws(() => bl.encode('ABC', b), Error); + assert.throws(() => bl.encode(Buffer.from('0102', 'hex'), b), Error); }); - test('var length', function() { - var llo = lo.u8('l'); - var blo = lo.blob(lo.offset(llo, -1), 'b'); - var st = lo.struct([llo, blo]); - var b = Buffer.alloc(10); + test('const length', function() { + const llo = lo.u8('l'); + const blo = lo.blob(lo.offset(llo, -1), 'b'); + const st = lo.struct([llo, blo]); + const b = Buffer.alloc(10); assert(0 > st.span); assert.strictEqual(blo.length.layout, llo); assert.equal(st.encode({b: Buffer.from('03040506', 'hex')}, b), llo.span + 4); - var span = st.getSpan(b); + const span = st.getSpan(b); assert.equal(span, 5); assert.equal(Buffer.from('0403040506', 'hex').compare(b.slice(0, span)), 0); - var obj = st.decode(b); + const obj = st.decode(b); assert.equal(obj.l, 4); assert.equal(obj.b.toString('hex'), '03040506'); - assert.throws(function() { + assert.throws(() => { st.encode({b: Buffer.alloc(b.length)}, b, 1); }, RangeError); }); test('greedy', function() { - var blo = lo.blob(lo.greedy(), 'b'); - var b = Buffer.from('ABCDx'); + const blo = lo.blob(lo.greedy(), 'b'); + const b = Buffer.from('ABCDx'); assert.equal(Buffer.from('ABCDx').compare(blo.decode(b)), 0); assert.equal(Buffer.from('Dx').compare(blo.decode(b, 3)), 0); b.fill(0); @@ -1679,19 +1677,19 @@ suite('Layout', function() { }); suite('issue#8', function() { test('named', function() { - var ver = lo.u8('ver'); - var hdr = new lo.Structure([lo.u8('id'), + const ver = lo.u8('ver'); + const hdr = new lo.Structure([lo.u8('id'), lo.u8('ver')], 'hdr'); - var pld = new lo.Union(lo.offset(ver, -ver.span), + const pld = new lo.Union(lo.offset(ver, -ver.span), new lo.Blob(8, 'blob'), 'u'); - var pkt = new lo.Structure([hdr, pld], 's'); - var expectedBlob = Buffer.from('1011121314151617', 'hex'); - var b = Buffer.from('01021011121314151617', 'hex'); + const pkt = new lo.Structure([hdr, pld], 's'); + const expectedBlob = Buffer.from('1011121314151617', 'hex'); + const b = Buffer.from('01021011121314151617', 'hex'); assert.deepEqual(hdr.decode(b), {id: 1, ver: 2}); - var du = pld.decode(b, 2); + const du = pld.decode(b, 2); assert.equal(du.ver, 2); assert.equal(expectedBlob.compare(du.blob), 0); - var dp = pkt.decode(b); + let dp = pkt.decode(b); assert.deepEqual(dp.hdr, {id: 1, ver: 2}); assert.equal(dp.u.ver, 2); assert.equal(expectedBlob.compare(dp.u.blob), 0); @@ -1704,19 +1702,19 @@ suite('Layout', function() { u: {v3: [0x13121110, 0x17161514]}}); }); test('anon', function() { - var ver = lo.u8('ver'); - var hdr = new lo.Structure([lo.u8('id'), + const ver = lo.u8('ver'); + const hdr = new lo.Structure([lo.u8('id'), lo.u8('ver')]); - var pld = new lo.Union(lo.offset(ver, -ver.span), + const pld = new lo.Union(lo.offset(ver, -ver.span), new lo.Blob(8, 'blob')); - var expectedBlob = Buffer.from('1011121314151617', 'hex'); - var b = Buffer.from('01021011121314151617', 'hex'); + const expectedBlob = Buffer.from('1011121314151617', 'hex'); + const b = Buffer.from('01021011121314151617', 'hex'); assert.deepEqual(hdr.decode(b), {id: 1, ver: 2}); - var du = pld.decode(b, 2); + const du = pld.decode(b, 2); assert.equal(du.ver, 2); assert.equal(expectedBlob.compare(du.blob), 0); /* This is what I want, but can't get. */ - // var dp = pkt.decode(b); + // const dp = pkt.decode(b); // assert.equal(dp.id, 1); // assert.equal(dp.ver, 2); // assert.equal(expectedBlob.compare(dp.blob), 0); @@ -1730,10 +1728,10 @@ suite('Layout', function() { }); suite('factories', function() { test('anon', function() { - var ver = lo.u8('ver'); - var hdr = lo.struct([lo.u8('id'), + const ver = lo.u8('ver'); + const hdr = lo.struct([lo.u8('id'), lo.u8('ver')]); - var pld = lo.union(lo.offset(ver, -ver.span), lo.blob(8, 'blob')); + const pld = lo.union(lo.offset(ver, -ver.span), lo.blob(8, 'blob')); assert(hdr instanceof lo.Structure); assert(pld instanceof lo.Union); assert(pld.defaultLayout instanceof lo.Blob); @@ -1742,27 +1740,27 @@ suite('Layout', function() { }); suite('CString', function() { test('ctor', function() { - var cst = lo.cstr(); + const cst = lo.cstr(); assert(0 > cst.span); }); test('#getSpan', function() { - var cst = new lo.CString(); - assert.throws(function() {cst.getSpan();}, TypeError); + const cst = new lo.CString(); + assert.throws(() => cst.getSpan(), TypeError); assert.equal(cst.getSpan(Buffer.from('00', 'hex')), 1); assert.equal(cst.getSpan(Buffer.from('4100', 'hex')), 2); assert.equal(cst.getSpan(Buffer.from('4100', 'hex'), 1), 1); assert.equal(cst.getSpan(Buffer.from('4142', 'hex')), 3); }); test('#decode', function() { - var cst = new lo.CString(); + const cst = new lo.CString(); assert.equal(cst.decode(Buffer.from('00', 'hex')), ''); assert.equal(cst.decode(Buffer.from('4100', 'hex')), 'A'); assert.equal(cst.decode(Buffer.from('4100', 'hex'), 1), ''); assert.equal(cst.decode(Buffer.from('4142', 'hex')), 'AB'); }); test('#encode', function() { - var cst = new lo.CString(); - var b = Buffer.alloc(4); + const cst = new lo.CString(); + const b = Buffer.alloc(4); b.fill(0xFF); assert.equal(Buffer.from('A', 'utf8').length, 1); assert.equal(cst.encode('', b), 1); @@ -1773,13 +1771,13 @@ suite('Layout', function() { assert.equal(Buffer.from('414200ff', 'hex').compare(b), 0); assert.equal(cst.encode(5, b), 1 + 1); assert.equal(Buffer.from('350000ff', 'hex').compare(b), 0); - assert.throws(function() {cst.encode('too long', b);}, RangeError); + assert.throws(() => cst.encode('too long', b), RangeError); }); test('in struct', function() { - var st = lo.struct([lo.cstr('k'), + const st = lo.struct([lo.cstr('k'), lo.cstr('v')]); - var b = Buffer.from('6100323300', 'hex'); - assert.throws(function() {st.getSpan();}, RangeError); + const b = Buffer.from('6100323300', 'hex'); + assert.throws(() => st.getSpan(), RangeError); assert.equal(st.fields[0].getSpan(b), 2); assert.equal(st.fields[1].getSpan(b, 2), 3); assert.equal(st.getSpan(b), 5); @@ -1788,8 +1786,8 @@ suite('Layout', function() { assert.equal(st.encode({k: 'a', v: 23}, b), (1 + 1) + (2 + 1)); }); test('in seq', function() { - var seq = lo.seq(lo.cstr(), 3); - var b = Buffer.from('61006263003500', 'hex'); + const seq = lo.seq(lo.cstr(), 3); + const b = Buffer.from('61006263003500', 'hex'); assert.deepEqual(seq.decode(b), ['a', 'bc', '5']); assert.equal(seq.encode(['hi', 'u', 'c'], b), (1 + 1) + (2 + 1) + (1 + 1)); assert.equal(Buffer.from('68690075006300', 'hex').compare(b), 0); @@ -1797,16 +1795,16 @@ suite('Layout', function() { }); suite('Constant', function() { test('ctor', function() { - var c = new lo.Constant('value', 'p'); + const c = new lo.Constant('value', 'p'); assert.equal(c.value, 'value'); assert.equal(c.property, 'p'); assert.equal(c.span, 0); }); test('basics', function() { - var b = Buffer.from('', 'hex'); + const b = Buffer.from('', 'hex'); assert.strictEqual(lo.const(true).decode(b), true); assert.strictEqual(lo.const(undefined).decode(b), undefined); - var obj = {a: 23}; + const obj = {a: 23}; assert.strictEqual(lo.const(obj).decode(b), obj); /* No return value to check, but this shouldn't throw an * exception (which it would if it tried to mutate the @@ -1818,23 +1816,23 @@ suite('Layout', function() { suite('objectConstructor', function() { test('invalid ctor', function() { function Class() {} - assert.throws(function() {lo.bindConstructorLayout(4);}, TypeError); - assert.throws(function() {lo.bindConstructorLayout(Class);}, TypeError); - assert.throws(function() {lo.bindConstructorLayout(Class, 4);}, TypeError); - var clo = lo.struct([lo.u8('u8')]); + assert.throws(() => lo.bindConstructorLayout(4), TypeError); + assert.throws(() => lo.bindConstructorLayout(Class), TypeError); + assert.throws(() => lo.bindConstructorLayout(Class, 4), TypeError); + const clo = lo.struct([lo.u8('u8')]); lo.bindConstructorLayout(Class, clo); assert(Class.hasOwnProperty('layout_')); assert(clo.hasOwnProperty('boundConstructor_')); - assert.throws(function() {lo.bindConstructorLayout(Class, clo);}, Error); + assert.throws(() => lo.bindConstructorLayout(Class, clo), Error); function Class2() {} - assert.throws(function() {lo.bindConstructorLayout(Class2, clo);}, Error); + assert.throws(() => lo.bindConstructorLayout(Class2, clo), Error); }); test('struct', function() { function Sample(temp_dCel, humidity_ppt) { this.temp_dCel = temp_dCel; this.humidity_ppt = humidity_ppt; } - var slo = lo.struct([lo.s32('temp_dCel'), + const slo = lo.struct([lo.s32('temp_dCel'), lo.u32('humidity_ppt')], 'sample'); lo.bindConstructorLayout(Sample, slo); @@ -1846,29 +1844,29 @@ suite('Layout', function() { assert(!Sample.propertyIsEnumerable('decode')); /* Verify that synthesized encode/decode may be extended. */ - var called; - var synthesizedEncode = Sample.prototype.encode; + let called; + const synthesizedEncode = Sample.prototype.encode; assert('function' === typeof synthesizedEncode); Sample.prototype.encode = function(src, b, offset) { called = true; return synthesizedEncode.bind(this)(src, b, offset); }; - var synthesizedDecode = Sample.decode; + const synthesizedDecode = Sample.decode; assert('function' === typeof synthesizedDecode); Sample.decode = function(b, offset) { called = true; return synthesizedDecode(b, offset); }; - var p = new Sample(223, 672); + const p = new Sample(223, 672); assert(p instanceof Sample); assert.equal(p.temp_dCel, 223); assert.equal(p.humidity_ppt, 672); - var po = Object.create(Sample.prototype); + let po = Object.create(Sample.prototype); assert(po instanceof Sample); - var b = Buffer.alloc(8); + const b = Buffer.alloc(8); assert(!called); p.encode(b); assert(called); @@ -1892,13 +1890,13 @@ suite('Layout', function() { lo.bindConstructorLayout(Header, lo.bits(lo.u8())); Header.layout_.addField(2, 'ver'); Header.layout_.addField(2, 'pwr'); - var b = Buffer.from('07', 'hex'); - var hdr = Header.decode(b); + const b = Buffer.from('07', 'hex'); + const hdr = Header.decode(b); assert(hdr instanceof Header); assert.equal(hdr.ver, 3); assert.equal(hdr.pwr, 1); assert.equal(hdr.power(), 'lo'); - var nb = Buffer.alloc(1); + const nb = Buffer.alloc(1); nb.fill(0); assert.equal(1, hdr.encode(nb)); assert.equal(b.compare(nb), 0); @@ -1927,12 +1925,12 @@ suite('Layout', function() { this.struct = v; } util.inherits(VStruct, Union); - var str = lo.struct([lo.u32('u32'), lo.u16('u16'), lo.s16('s16')]); + const str = lo.struct([lo.u32('u32'), lo.u16('u16'), lo.s16('s16')]); lo.bindConstructorLayout(Struct, str); lo.bindConstructorLayout(VStruct, Union.layout_.addVariant(3, str, 'struct')); - var b = Buffer.alloc(Union.layout_.span); + let b = Buffer.alloc(Union.layout_.span); b.fill(0); - var u = Union.decode(b); + let u = Union.decode(b); assert(u instanceof Union); assert.equal(u.var, 0); b[0] = 1; From 363cdedce1213c7a1784310a343444b8bc412aab Mon Sep 17 00:00:00 2001 From: "Peter A. Bigot" Date: Sat, 6 Jan 2018 12:44:02 -0600 Subject: [PATCH 4/5] Structure: add constructor parameter and property enabling short-buffer decoding When specifically requested structures given a short buffer that ends at a field boundary will be acceptable, leaving the subsequent fields undefined. Note that unlike other layout constructors the additional argument appears after rather than before property. This is mostly for compatibility reasons, but as justification the new argument affects behavior rather than content interpretation (as msb in BitStructure does), so we'll establish policy on that basis. Closes #19. --- CHANGELOG.md | 4 +++- lib/Layout.js | 27 +++++++++++++++++++++++++-- test/LayoutTest.js | 44 ++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 72 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index cc9415d..d16da8c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,7 +2,8 @@ ## [Unreleased] -## [1.1.0] - 2017-12-23 +* **API** Add a third parameter to Structure specifying it should decode + short buffers as prefixes, resolving [issue #19][issue#19]. * **API** Interpret string argument to BitStructure `msb` parameter as a `property` parameter, resolving [issue #17][issue#17]. @@ -177,6 +178,7 @@ [issue#14]: https://github.com/pabigot/buffer-layout/issues/14 [issue#15]: https://github.com/pabigot/buffer-layout/issues/15 [issue#17]: https://github.com/pabigot/buffer-layout/issues/17 +[issue#19]: https://github.com/pabigot/buffer-layout/issues/19 [ci:travis]: https://travis-ci.org/pabigot/buffer-layout [ci:coveralls]: https://coveralls.io/github/pabigot/buffer-layout [node:issue#3992]: https://github.com/nodejs/node/issues/3992 diff --git a/lib/Layout.js b/lib/Layout.js index 0ed72bc..b308bfa 100644 --- a/lib/Layout.js +++ b/lib/Layout.js @@ -1166,6 +1166,9 @@ class Sequence extends Layout { * @param {string} [property] - initializer for {@link * Layout#property|property}. * + * @param {Boolean} [decodePrefixes] - initializer for {@link + * Structure#decodePrefixes|property}. + * * @throws {Error} - if `fields` contains an unnamed variable-length * layout. * @@ -1173,11 +1176,16 @@ class Sequence extends Layout { * @augments {Layout} */ class Structure extends Layout { - constructor(fields, property) { + constructor(fields, property, decodePrefixes) { if (!(Array.isArray(fields) && fields.reduce((acc, v) => acc && (v instanceof Layout), true))) { throw new TypeError('fields must be array of Layout instances'); } + if (('boolean' === typeof property) + && (undefined === decodePrefixes)) { + decodePrefixes = property; + property = undefined; + } /* Verify absence of unnamed variable-length fields. */ for (const fd of fields) { @@ -1205,6 +1213,17 @@ class Structure extends Layout { * * @type {Layout[]} */ this.fields = fields; + + /** Control behavior of {@link Layout#decode|decode()} given short + * buffers. + * + * In some situations a structure many be extended with additional + * fields over time, with older installations providing only a + * prefix of the full structure. If this property is `true` + * decoding will accept those buffers and leave subsequent fields + * undefined, as long as the buffer ends at a field boundary. + * Defaults to `false`. */ + this.decodePrefixes = !!decodePrefixes; } /** @override */ @@ -1239,6 +1258,10 @@ class Structure extends Layout { dest[fd.property] = fd.decode(b, offset); } offset += fd.getSpan(b, offset); + if (this.decodePrefixes + && (b.length === offset)) { + break; + } } return dest; } @@ -2565,7 +2588,7 @@ exports.f64 = (property => new Double(property)); exports.f64be = (property => new DoubleBE(property)); /** Factory for {@link Structure|Structure} values. */ -exports.struct = ((fields, property) => new Structure(fields, property)); +exports.struct = ((fields, property, decodePrefixes) => new Structure(fields, property, decodePrefixes)); /** Factory for {@link BitStructure|BitStructure} values. */ exports.bits = ((word, msb, property) => new BitStructure(word, msb, property)); diff --git a/test/LayoutTest.js b/test/LayoutTest.js index cb5afdd..b959522 100644 --- a/test/LayoutTest.js +++ b/test/LayoutTest.js @@ -786,6 +786,50 @@ suite('Layout', function() { assert.equal(slo.encode({a: 5, s: 'hi'}, b), 4); assert.equal(slo.encode({a: 5, s: 'hi'}, b, 5), 4); }); + suite('prefix decoding', function() { + const fields = [ + lo.u32('u32'), + lo.u16('u16'), + lo.u8('u8'), + ]; + const b = Buffer.from('01020304111221', 'hex'); + test('rejects partial by default', function() { + const slo = lo.struct(fields); + assert.strictEqual(slo.decodePrefixes, false); + assert.deepEqual(slo.decode(b), { + u32: 0x04030201, + u16: 0x1211, + u8: 0x21, + }); + assert.throws(() => slo.decode(b.slice(0, 4)), RangeError); + }); + test('accepts full fields if enabled', function() { + const slo = lo.struct(fields, true); + assert.strictEqual(slo.decodePrefixes, true); + assert.deepEqual(slo.decode(b), { + u32: 0x04030201, + u16: 0x1211, + u8: 0x21, + }); + assert.deepEqual(slo.decode(b.slice(0, 4)), { + u32: 0x04030201, + }); + assert.deepEqual(slo.decode(b.slice(0, 6)), { + u32: 0x04030201, + u16: 0x1211, + }); + assert.throws(() => slo.decode(b.slice(0, 3)), RangeError); + }); + test('preserved by replicate', function() { + const property = 'name'; + const slo = lo.struct(fields, property, true); + assert.strictEqual(slo.property, property); + assert.strictEqual(slo.decodePrefixes, true); + const slo2 = slo.replicate('other'); + assert.strictEqual(slo2.property, 'other'); + assert.strictEqual(slo2.decodePrefixes, true); + }); + }); }); suite('replicate', function() { test('uint', function() { From 6403ce9c0aa4fe1810c745a0e6b4f8f4237b5012 Mon Sep 17 00:00:00 2001 From: "Peter A. Bigot" Date: Sat, 6 Jan 2018 13:03:47 -0600 Subject: [PATCH 5/5] passim: update for 1.1.0 release --- CHANGELOG.md | 4 ++-- LICENSE | 2 +- lib/Layout.js | 2 +- package.json | 4 ++-- 4 files changed, 6 insertions(+), 6 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index d16da8c..94d83c0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,6 @@ # Change Log -## [Unreleased] +## [1.1.0] - 2018-01-06 * **API** Add a third parameter to Structure specifying it should decode short buffers as prefixes, resolving [issue #19][issue#19]. @@ -122,7 +122,7 @@ * Initial release. -[Unreleased]: https://github.com/pabigot/buffer-layout/compare/v1.0.0...next +[1.1.0]: https://github.com/pabigot/buffer-layout/compare/v1.0.0...v1.1.0 [1.0.0]: https://github.com/pabigot/buffer-layout/compare/v0.13.0...v1.0.0 [0.13.0]: https://github.com/pabigot/buffer-layout/compare/v0.12.0...v0.13.0 [0.12.1]: https://github.com/pabigot/buffer-layout/compare/v0.12.0...v0.12.1 diff --git a/LICENSE b/LICENSE index d3e8286..74f2fd4 100644 --- a/LICENSE +++ b/LICENSE @@ -1,6 +1,6 @@ The MIT License (MIT) -Copyright (c) 2015 Peter A. Bigot +Copyright (c) 2015-2018 Peter A. Bigot Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal diff --git a/lib/Layout.js b/lib/Layout.js index b308bfa..907f883 100644 --- a/lib/Layout.js +++ b/lib/Layout.js @@ -1,6 +1,6 @@ /* The MIT License (MIT) * - * Copyright 2015-2017 Peter A. Bigot + * Copyright 2015-2018 Peter A. Bigot * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal diff --git a/package.json b/package.json index b3ffb86..3f01448 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "buffer-layout", - "version": "1.1.0-dev", + "version": "1.1.0", "description": "Translation between JavaScript values and Buffers", "keywords": [ "Buffer", @@ -18,7 +18,7 @@ "author": "Peter A. Bigot ", "main": "./lib/Layout.js", "devDependencies": { - "coveralls": "~3.0.0", + "coveralls": "^3.0.0", "eslint": "~4.13.1", "eslint-config-google": "~0.9.1", "eslint-plugin-pabigot": "~1.1.0",