Skip to content

Commit a927a66

Browse files
assaf-xmdcodeIO
authored andcommitted
Converter: Fix empty 'bytes' field decoding, now using Buffer where applicable (#1020)
1 parent 812b38d commit a927a66

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

src/converter.js

+9-3
Original file line numberDiff line numberDiff line change
@@ -244,9 +244,15 @@ converter.toObject = function toObject(mtype) {
244244
("d%s=o.longs===String?n.toString():o.longs===Number?n.toNumber():n", prop)
245245
("}else")
246246
("d%s=o.longs===String?%j:%i", prop, field.typeDefault.toString(), field.typeDefault.toNumber());
247-
else if (field.bytes) gen
248-
("d%s=o.bytes===String?%j:%s", prop, String.fromCharCode.apply(String, field.typeDefault), "[" + Array.prototype.slice.call(field.typeDefault).join(",") + "]");
249-
else gen
247+
else if (field.bytes) {
248+
var arrayDefault = "[" + Array.prototype.slice.call(field.typeDefault).join(",") + "]";
249+
gen
250+
("if(o.bytes===String)d%s=%j", prop, String.fromCharCode.apply(String, field.typeDefault))
251+
("else{")
252+
("d%s=%s", prop, arrayDefault)
253+
("if(o.bytes!==Array)d%s=util.newBuffer(d%s)", prop, prop)
254+
("}")
255+
} else gen
250256
("d%s=%j", prop, field.typeDefault); // also messages (=null)
251257
} gen
252258
("}");

0 commit comments

Comments
 (0)