Skip to content

Commit 5286385

Browse files
committed
more robust solution to type checking for section bodies
1 parent 49d9e8a commit 5286385

File tree

1 file changed

+12
-8
lines changed

1 file changed

+12
-8
lines changed

lib/message.js

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,16 @@ Section.prototype.described = function (item) {
8181
return types.described(types.wrap_ulong(this.typecode), types.wrap(item || this.content));
8282
};
8383

84+
Section.prototype.collect_sections = function (sections) {
85+
if (this.multiple) {
86+
for (var i = 0; i < this.content.length; i++) {
87+
sections.push(this.described(this.content[i]));
88+
}
89+
} else {
90+
sections.push(this.described());
91+
}
92+
};
93+
8494
define_composite_section({
8595
name:'header',
8696
code:0x70,
@@ -136,14 +146,8 @@ define_map_section({name:'footer', code:0x78});
136146

137147

138148
function wrap_body (sections, msg) {
139-
if (msg.body && msg.body.constructor === Section) {
140-
if (msg.body.multiple) {
141-
msg.body.content.forEach(function (s) {
142-
sections.push(msg.body.described(s));
143-
});
144-
} else {
145-
sections.push(msg.body.described());
146-
}
149+
if (msg.body && msg.body.collect_sections) {
150+
msg.body.collect_sections(sections);
147151
} else {
148152
sections.push(types.described(types.wrap_ulong(0x77), types.wrap(msg.body)));
149153
}

0 commit comments

Comments
 (0)