aboutsummaryrefslogtreecommitdiffhomepage
path: root/js/binary/encoder.js
diff options
context:
space:
mode:
Diffstat (limited to 'js/binary/encoder.js')
-rw-r--r--js/binary/encoder.js8
1 files changed, 5 insertions, 3 deletions
diff --git a/js/binary/encoder.js b/js/binary/encoder.js
index f25935f1..8e9f5bbc 100644
--- a/js/binary/encoder.js
+++ b/js/binary/encoder.js
@@ -390,11 +390,13 @@ jspb.BinaryEncoder.prototype.writeDouble = function(value) {
/**
- * Writes a boolean value to the buffer as a varint.
- * @param {boolean} value The value to write.
+ * Writes a boolean value to the buffer as a varint. We allow numbers as input
+ * because the JSPB code generator uses 0/1 instead of true/false to save space
+ * in the string representation of the proto.
+ * @param {boolean|number} value The value to write.
*/
jspb.BinaryEncoder.prototype.writeBool = function(value) {
- goog.asserts.assert(goog.isBoolean(value));
+ goog.asserts.assert(goog.isBoolean(value) || goog.isNumber(value));
this.buffer_.push(value ? 1 : 0);
};