Skip to content

Commit

Permalink
fix(encoding): defaults for composite types should use type def
Browse files Browse the repository at this point in the history
There was a small error when wrapping a default value for a defined
type, in that the field type was passed to `wrapField` instead of
the entire field definition, which resulted in the value defaulting
to heuristic encoding.
  • Loading branch information
mbroadst committed Aug 11, 2016
1 parent f8ce0f1 commit 8e76ae5
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/types/composite_type.js
Expand Up @@ -19,7 +19,7 @@ function wrapField(field, value) {
if (value instanceof ForcedType) return value;
if (value === undefined || value === null) {
if (field.mandatory) throw new Error('missing mandatory field: ' + field.name);
if (field.hasOwnProperty('default')) return wrapField(field.type, field.default);
if (field.hasOwnProperty('default')) return wrapField(field, field.default);
return null;
}

Expand Down
17 changes: 17 additions & 0 deletions test/unit/types/message_sections.test.js
Expand Up @@ -32,6 +32,23 @@ describe('Header', function() {
expect(expected).to.eql(actual.get());
});

it('should encode default value for priority as ubyte', function() {
var message = { header: { durable: true } };
var expected = tu.buildBuffer([
0x00, 0x53, 0x70,
0xc0, 0x07, 0x05,
0x41,
0x50, 0x04,
0x40,
0x42,
0x43
]);

var actual = new Builder();
m.encodeMessage(message, actual);
expect(expected).to.eql(actual.get());
});

it('should decode the section', function() {
var buffer = tu.newBuffer([
0x00, 0x53, 0x70,
Expand Down

0 comments on commit 8e76ae5

Please sign in to comment.