diff --git a/lib/types/composite_type.js b/lib/types/composite_type.js index 11390f2..764d643 100644 --- a/lib/types/composite_type.js +++ b/lib/types/composite_type.js @@ -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; } diff --git a/test/unit/types/message_sections.test.js b/test/unit/types/message_sections.test.js index b8f1f49..9ce1b9a 100644 --- a/test/unit/types/message_sections.test.js +++ b/test/unit/types/message_sections.test.js @@ -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,