Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix the issue with int64 value type in a map #2006

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions src/decoder.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,13 @@ function decoder(mtype) {
("k=%j", types.defaults[field.keyType]);
else gen
("k=null");

if (types.defaults[type] !== undefined) gen
("value=%j", types.defaults[type]);
if (types.defaults[type] !== undefined) {
if (types.isLongType(type)) {
gen("value= $util.Long ? $util.Long.fromValue(0) : 0");
} else {
gen("value=%j", types.defaults[type]);
}
}
else gen
("value=null");

Expand Down
11 changes: 11 additions & 0 deletions src/types.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,17 @@ var s = [
"bytes" // 14
];

/**
* Determine whether a data type requires $utils.Long
* @param {string} type value types
* @returns {boolean} Result
*/
function isLongType(type) {
return ["int64", "uint64", "sint64", "fixed64", "sfixed64"].indexOf(type) !== -1;
}

types.isLongType = isLongType;

function bake(values, offset) {
var i = 0, o = {};
offset |= 0;
Expand Down