Skip to content

Commit 9e56e60

Browse files
committed
minor correction to default value generation; add comments
1 parent 95b6c03 commit 9e56e60

File tree

2 files changed

+3
-1
lines changed

2 files changed

+3
-1
lines changed

src/converter.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -250,7 +250,7 @@ converter.toObject = function toObject(mtype) {
250250
("d%s=o.enums===String?%j:%j", prop, field.resolvedType.valuesById[field.typeDefault], field.typeDefault);
251251
else if (field.long) gen
252252
("if(typeof BigInt!==\"undefined\"&&o.longs===BigInt){")
253-
("d%s=BigInt(%s)", prop, field.typeDefault.toString())
253+
("d%s=BigInt(%j)", prop, field.typeDefault.toString())
254254
("}else if(util.Long){")
255255
("var n=new util.Long(%i,%i,%j)", field.typeDefault.low, field.typeDefault.high, field.typeDefault.unsigned)
256256
("d%s=o.longs===String?n.toString():o.longs===Number?n.toNumber():n", prop)

tests/api_converters.js

+2
Original file line numberDiff line numberDiff line change
@@ -106,13 +106,15 @@ tape.test("converters", function(test) {
106106
var buf = protobuf.util.newBuffer(3);
107107
buf[0] = buf[1] = buf[2] = 49; // "111"
108108
var msg = Message.create({
109+
// This number was chosen to be > 2^63 and < 2^64
109110
uint64Val: protobuf.util.Long.fromString("11000000000000000001", true),
110111
uint64Repeated: [2, 3],
111112
bytesVal: buf,
112113
bytesRepeated: [buf, buf],
113114
enumVal: 2,
114115
enumRepeated: [1, 100, 2],
115116
int64Map: {
117+
// These numbers were chosen to be < Number.MIN_SAFE_INTEGER
116118
a: protobuf.util.Long.fromString("-200000000000000001"),
117119
b: protobuf.util.Long.fromString("-300000000000000001")
118120
}

0 commit comments

Comments
 (0)