Skip to content

Commit

Permalink
Layout: replace API used to couple classes with layouts
Browse files Browse the repository at this point in the history
Eliminate the need to provide the destination object prototype when the
layout is defined.  Change the API so destination objects are created by
a function instead of cloning a prototype.  Rename the function that
associates layouts with constructors to be more descriptive of what it
does.
  • Loading branch information
pabigot committed Mar 6, 2016
1 parent 3d92115 commit 2dd8801
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -157,17 +157,17 @@ representing the union and the variants:
function Vu32(v) { this.u32 = v; }
util.inherits(Vu32, Union);
lo.bindConstructorLayout(Vu32,
Union._layout.addVariant('w'.charCodeAt(0), lo.u32(), 'u32'));
Union.layout_.addVariant('w'.charCodeAt(0), lo.u32(), 'u32'));

function Vs16(v) { this.s16 = v; }
util.inherits(Vs16, Union);
lo.bindConstructorLayout(Vs16,
Union._layout.addVariant('h'.charCodeAt(0), lo.seq(lo.s16(), 2), 's16'));
Union.layout_.addVariant('h'.charCodeAt(0), lo.seq(lo.s16(), 2), 's16'));

function Vf32(v) { this.f32 = v; }
util.inherits(Vf32, Union);
lo.bindConstructorLayout(Vf32,
Union._layout.addVariant('f'.charCodeAt(0), lo.f32(), 'f32'));
Union.layout_.addVariant('f'.charCodeAt(0), lo.f32(), 'f32'));

var v = Union.decode(Buffer('7778563412', 'hex'));
assert(v instanceof Vu32);
Expand All @@ -179,7 +179,7 @@ representing the union and the variants:
assert.equal(v.t, 0xa5);
assert.deepEqual(v.u8, [0xa5, 0xa5, 0xa5, 0xa5]);

var b = new Buffer(Union._layout.span);
var b = new Buffer(Union.layout_.span);
v = new Vf32(23.625);
v.encode(b);
assert.equal(Buffer('660000bd41', 'hex').compare(b), 0);
Expand Down

0 comments on commit 2dd8801

Please sign in to comment.