diff options
author | Adam Cozzette <acozzette@gmail.com> | 2018-06-25 15:52:29 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-06-25 15:52:29 -0700 |
commit | d6f346b4d55ae5112934297593ec1c56c3d178a5 (patch) | |
tree | 021b5476160e465a20ef7d4ae4c0524351667233 /js/map.js | |
parent | 3d603f481ed142d0be5e8e4dd6d1cb4457a51405 (diff) | |
parent | 82d3d7d250645322f8a7343188e5ae6246a76414 (diff) |
Merge pull request #4827 from acozzette/merge-3-6-x
Merge 3.6.x branch into master
Diffstat (limited to 'js/map.js')
-rw-r--r-- | js/map.js | 15 |
1 files changed, 11 insertions, 4 deletions
@@ -443,7 +443,8 @@ jspb.Map.prototype.serializeBinary = function( /** * Read one key/value message from the given BinaryReader. Compatible as the * `reader` callback parameter to jspb.BinaryReader.readMessage, to be called - * when a key/value pair submessage is encountered. + * when a key/value pair submessage is encountered. If the Key is undefined, + * we should default it to 0. * @template K, V * @param {!jspb.Map} map * @param {!jspb.BinaryReader} reader @@ -457,12 +458,17 @@ jspb.Map.prototype.serializeBinary = function( * readMessage, in which case the second callback arg form is used. * * @param {?function(V,!jspb.BinaryReader)=} opt_valueReaderCallback - * The BinaryReader parsing callback for type V, if V is a message type. + * The BinaryReader parsing callback for type V, if V is a message type + * + * @param {K=} opt_defaultKey + * The default value for the type of map keys. Accepting map + * entries with unset keys is required for maps to be backwards compatible + * with the repeated message representation described here: goo.gl/zuoLAC * */ jspb.Map.deserializeBinary = function(map, reader, keyReaderFn, valueReaderFn, - opt_valueReaderCallback) { - var key = undefined; + opt_valueReaderCallback, opt_defaultKey) { + var key = opt_defaultKey; var value = undefined; while (reader.nextField()) { @@ -470,6 +476,7 @@ jspb.Map.deserializeBinary = function(map, reader, keyReaderFn, valueReaderFn, break; } var field = reader.getFieldNumber(); + if (field == 1) { // Key. key = keyReaderFn.call(reader); |