Skip to content

Commit

Permalink
Converter: Fix empty 'bytes' field decoding, now using Buffer where a…
Browse files Browse the repository at this point in the history
…pplicable (#1020)
  • Loading branch information
assaf-xm authored and dcodeIO committed Apr 30, 2018
1 parent 812b38d commit a927a66
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions src/converter.js
Original file line number Diff line number Diff line change
Expand Up @@ -244,9 +244,15 @@ converter.toObject = function toObject(mtype) {
("d%s=o.longs===String?n.toString():o.longs===Number?n.toNumber():n", prop)
("}else")
("d%s=o.longs===String?%j:%i", prop, field.typeDefault.toString(), field.typeDefault.toNumber());
else if (field.bytes) gen
("d%s=o.bytes===String?%j:%s", prop, String.fromCharCode.apply(String, field.typeDefault), "[" + Array.prototype.slice.call(field.typeDefault).join(",") + "]");
else gen
else if (field.bytes) {
var arrayDefault = "[" + Array.prototype.slice.call(field.typeDefault).join(",") + "]";
gen
("if(o.bytes===String)d%s=%j", prop, String.fromCharCode.apply(String, field.typeDefault))
("else{")
("d%s=%s", prop, arrayDefault)
("if(o.bytes!==Array)d%s=util.newBuffer(d%s)", prop, prop)
("}")
} else gen
("d%s=%j", prop, field.typeDefault); // also messages (=null)
} gen
("}");
Expand Down

0 comments on commit a927a66

Please sign in to comment.