From ae3066260a1a9e3e007161a78c60fdd7198ff79e Mon Sep 17 00:00:00 2001 From: "chenbo.boye" Date: Wed, 26 Jun 2024 19:32:06 +0800 Subject: [PATCH] Fix the issue with int64 value type in a map --- src/decoder.js | 10 +++++++--- src/types.js | 11 +++++++++++ 2 files changed, 18 insertions(+), 3 deletions(-) diff --git a/src/decoder.js b/src/decoder.js index f55451f25..56db6da63 100644 --- a/src/decoder.js +++ b/src/decoder.js @@ -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"); diff --git a/src/types.js b/src/types.js index 5fda19a69..11074d063 100644 --- a/src/types.js +++ b/src/types.js @@ -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;