Skip to content

Commit

Permalink
minor correction to default value generation; add comments
Browse files Browse the repository at this point in the history
  • Loading branch information
jtbandes committed Aug 29, 2023
1 parent 902b0fe commit 8f7ec32
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/converter.js
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,7 @@ converter.toObject = function toObject(mtype) {
("d%s=o.enums===String?%j:%j", prop, field.resolvedType.valuesById[field.typeDefault], field.typeDefault);
else if (field.long) gen
("if(typeof BigInt!==\"undefined\"&&o.longs===BigInt){")
("d%s=BigInt(%s)", prop, field.typeDefault.toString())
("d%s=BigInt(%j)", prop, field.typeDefault.toString())
("}else if(util.Long){")
("var n=new util.Long(%i,%i,%j)", field.typeDefault.low, field.typeDefault.high, field.typeDefault.unsigned)
("d%s=o.longs===String?n.toString():o.longs===Number?n.toNumber():n", prop)
Expand Down
2 changes: 2 additions & 0 deletions tests/api_converters.js
Original file line number Diff line number Diff line change
Expand Up @@ -106,13 +106,15 @@ tape.test("converters", function(test) {
var buf = protobuf.util.newBuffer(3);
buf[0] = buf[1] = buf[2] = 49; // "111"
var msg = Message.create({
// This number was chosen to be > 2^63 and < 2^64
uint64Val: protobuf.util.Long.fromString("11000000000000000001", true),
uint64Repeated: [2, 3],
bytesVal: buf,
bytesRepeated: [buf, buf],
enumVal: 2,
enumRepeated: [1, 100, 2],
int64Map: {
// These numbers were chosen to be < Number.MIN_SAFE_INTEGER
a: protobuf.util.Long.fromString("-200000000000000001"),
b: protobuf.util.Long.fromString("-300000000000000001")
}
Expand Down

0 comments on commit 8f7ec32

Please sign in to comment.