Skip to content
This repository was archived by the owner on Jan 13, 2025. It is now read-only.

Commit 79fbb0c

Browse files
committed
merge for 1.2.0 release
2 parents 253d8dd + 547d00b commit 79fbb0c

File tree

7 files changed

+508
-186
lines changed

7 files changed

+508
-186
lines changed

CHANGELOG.md

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,14 @@
11
# Change Log
22

3+
## [1.2.0] - 2018-03-14
4+
5+
* **API** Add [UTF8][doc:UTF8] to encode UTF strings in a possibly
6+
bounded buffer, resolving [issue #21][issue#21].
7+
* **API** Allow the layout parameter of
8+
a [VariantLayout][doc:VariantLayout] to be omitted in cases where no
9+
data beyond the discriminator is required,
10+
resolving [issue #20][issue#20].
11+
312
## [1.1.0] - 2018-01-06
413

514
* **API** Add a third parameter to Structure specifying it should decode
@@ -122,6 +131,7 @@
122131

123132
* Initial release.
124133

134+
[1.2.0]: https://github.com/pabigot/buffer-layout/compare/v1.1.0...v1.2.0
125135
[1.1.0]: https://github.com/pabigot/buffer-layout/compare/v1.0.0...v1.1.0
126136
[1.0.0]: https://github.com/pabigot/buffer-layout/compare/v0.13.0...v1.0.0
127137
[0.13.0]: https://github.com/pabigot/buffer-layout/compare/v0.12.0...v0.13.0
@@ -154,14 +164,16 @@
154164
[doc:NearInt64]: http://pabigot.github.io/buffer-layout/module-Layout-NearInt64.html
155165
[doc:OffsetLayout]: http://pabigot.github.io/buffer-layout/module-Layout-OffsetLayout.html
156166
[doc:patchIssue3992]: http://pabigot.github.io/buffer-layout/module-patchIssue3992.html
157-
[doc:Union]: http://pabigot.github.io/buffer-layout/module-Layout-Union.html
158-
[doc:Union.getSourceVariant]: http://pabigot.github.io/buffer-layout/module-Layout-Union.html#getSourceVariant
159-
[doc:UnionDiscriminator]: http://pabigot.github.io/buffer-layout/module-Layout-UnionDiscriminator.html
160167
[doc:Sequence]: http://pabigot.github.io/buffer-layout/module-Layout-Sequence.html
161168
[doc:Sequence.count]: http://pabigot.github.io/buffer-layout/module-Layout-Sequence.html#count
162169
[doc:Structure]: http://pabigot.github.io/buffer-layout/module-Layout-Structure.html
163170
[doc:Structure.layoutFor]: http://pabigot.github.io/buffer-layout/module-Layout-Structure.html#layoutFor
164171
[doc:Structure.offsetOf]: http://pabigot.github.io/buffer-layout/module-Layout-Structure.html#offsetOf
172+
[doc:Union]: http://pabigot.github.io/buffer-layout/module-Layout-Union.html
173+
[doc:Union.getSourceVariant]: http://pabigot.github.io/buffer-layout/module-Layout-Union.html#getSourceVariant
174+
[doc:UnionDiscriminator]: http://pabigot.github.io/buffer-layout/module-Layout-UnionDiscriminator.html
175+
[doc:UTF8]: http://pabigot.github.io/buffer-layout/module-Layout-UTF8.html
176+
[doc:VariantLayout]: http://pabigot.github.io/buffer-layout/module-Layout-VariantLayout.html
165177
[issue#1]: https://github.com/pabigot/buffer-layout/issues/1
166178
[issue#2]: https://github.com/pabigot/buffer-layout/issues/2
167179
[issue#3]: https://github.com/pabigot/buffer-layout/issues/3
@@ -179,6 +191,8 @@
179191
[issue#15]: https://github.com/pabigot/buffer-layout/issues/15
180192
[issue#17]: https://github.com/pabigot/buffer-layout/issues/17
181193
[issue#19]: https://github.com/pabigot/buffer-layout/issues/19
194+
[issue#20]: https://github.com/pabigot/buffer-layout/issues/20
195+
[issue#21]: https://github.com/pabigot/buffer-layout/issues/21
182196
[ci:travis]: https://travis-ci.org/pabigot/buffer-layout
183197
[ci:coveralls]: https://coveralls.io/github/pabigot/buffer-layout
184198
[node:issue#3992]: https://github.com/nodejs/node/issues/3992

README.md

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,10 +132,14 @@ The buffer-layout way:
132132

133133
const t = lo.u8('t');
134134
const un = lo.union(t, lo.seq(lo.u8(), 4, 'u8'));
135+
const nul = un.addVariant('n'.charCodeAt(0), 'nul');
135136
const u32 = un.addVariant('w'.charCodeAt(0), lo.u32(), 'u32');
136137
const s16 = un.addVariant('h'.charCodeAt(0), lo.seq(lo.s16(), 2), 's16');
137138
const f32 = un.addVariant('f'.charCodeAt(0), lo.f32(), 'f32');
138139
const b = Buffer.alloc(un.span);
140+
assert.deepEqual(un.decode(b), {t: 0, u8: [0, 0, 0, 0]});
141+
assert.deepEqual(un.decode(Buffer.from('6e01020304', 'hex')),
142+
{nul: true});
139143
assert.deepEqual(un.decode(Buffer.from('7778563412', 'hex')),
140144
{u32: 0x12345678});
141145
assert.deepEqual(un.decode(Buffer.from('660000bd41', 'hex')),
@@ -156,6 +160,11 @@ representing the union and the variants:
156160
lo.bindConstructorLayout(Union,
157161
lo.union(lo.u8('t'), lo.seq(lo.u8(), 4, 'u8')));
158162

163+
function Vn() {}
164+
util.inherits(Vn, Union);
165+
lo.bindConstructorLayout(Vn,
166+
Union.layout_.addVariant('n'.charCodeAt(0), 'nul'));
167+
159168
function Vu32(v) { this.u32 = v; }
160169
util.inherits(Vu32, Union);
161170
lo.bindConstructorLayout(Vu32,
@@ -186,6 +195,14 @@ representing the union and the variants:
186195
v.encode(b);
187196
assert.equal(Buffer.from('660000bd41', 'hex').compare(b), 0);
188197

198+
b.fill(0xFF);
199+
v = new Vn();
200+
v.encode(b);
201+
assert.equal(Buffer.from('6effffffff', 'hex').compare(b), 0);
202+
203+
Note that one variant (`'n'`) carries no data, leaving the remainder of
204+
the buffer unchanged when stored.
205+
189206
See
190207
[Layout.makeDestinationObject()](http://pabigot.github.io/buffer-layout/module-Layout-Layout.html#makeDestinationObject)
191208
and

jsdoc/custom/local.js

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,20 @@ function buildRE(prefix, tag) {
3030
exports.handlers = {
3131
jsdocCommentFound: function(e) {
3232
if (thisModule) for (var local in registry) {
33-
var sv = '$1'+thisModule+'~'+'$2';
34-
e.comment = e.comment.replace(buildRE('{', local), sv);
35-
e.comment = e.comment.replace(buildRE('{@link\\s*\\*?\\s*', local), sv);
33+
/* Handle {@link local} => {@link module~local|local} (across EOL) */
34+
var re = new RegExp('({@link\\s*\\*?\\s*)\\b(' + local + '\\b[^|}]*)}', 'g');
35+
e.comment = e.comment.replace(re,
36+
'$1' + thisModule + '~$2\|$2}');
37+
38+
/* Handle {local} => {thisModule~local}. Brace reference
39+
* doesn't support providing alternative text. */
40+
e.comment = e.comment.replace(buildRE('{', local),
41+
'$1' + thisModule + '~$2');
42+
43+
/* Handle `@cmd local` => `@cmd thisModule~local` for
44+
* certain commands (across EOL) */
45+
e.comment = e.comment.replace(buildRE('@(event|link|memberof|name)\\s*\\*?\\s*', local),
46+
'$1' + thisModule + '~$3');
3647
}
3748
},
3849

0 commit comments

Comments
 (0)