aboutsummaryrefslogtreecommitdiff
path: root/js/binary/reader.js
diff options
context:
space:
mode:
Diffstat (limited to 'js/binary/reader.js')
-rw-r--r--js/binary/reader.js142
1 files changed, 117 insertions, 25 deletions
diff --git a/js/binary/reader.js b/js/binary/reader.js
index 15f90432..2dc3eb70 100644
--- a/js/binary/reader.js
+++ b/js/binary/reader.js
@@ -97,7 +97,7 @@ jspb.BinaryReader = function(opt_bytes, opt_start, opt_length) {
/**
* User-defined reader callbacks.
- * @private {Object.<string, function(!jspb.BinaryReader):*>}
+ * @private {Object<string, function(!jspb.BinaryReader):*>}
*/
this.readCallbacks_ = null;
};
@@ -105,7 +105,7 @@ jspb.BinaryReader = function(opt_bytes, opt_start, opt_length) {
/**
* Global pool of BinaryReader instances.
- * @private {!Array.<!jspb.BinaryReader>}
+ * @private {!Array<!jspb.BinaryReader>}
*/
jspb.BinaryReader.instanceCache_ = [];
@@ -744,6 +744,20 @@ jspb.BinaryReader.prototype.readSint64 = function() {
/**
+ * Reads a signed zigzag-encoded 64-bit integer field from the binary stream,
+ * or throws an error if the next field in the stream is not of the correct
+ * wire type.
+ *
+ * @return {string} The value of the signed 64-bit integer field as a decimal string.
+ */
+jspb.BinaryReader.prototype.readSint64String = function() {
+ goog.asserts.assert(
+ this.nextWireType_ == jspb.BinaryConstants.WireType.VARINT);
+ return this.decoder_.readZigzagVarint64String();
+};
+
+
+/**
* Reads an unsigned 32-bit fixed-length integer fiield from the binary stream,
* or throws an error if the next field in the stream is not of the correct
* wire type.
@@ -772,11 +786,28 @@ jspb.BinaryReader.prototype.readFixed64 = function() {
/**
+ * Reads a signed 64-bit integer field from the binary stream as a string, or
+ * throws an error if the next field in the stream is not of the correct wire
+ * type.
+ *
+ * Returns the value as a string.
+ *
+ * @return {string} The value of the unsigned 64-bit integer field as a decimal
+ * string.
+ */
+jspb.BinaryReader.prototype.readFixed64String = function() {
+ goog.asserts.assert(
+ this.nextWireType_ == jspb.BinaryConstants.WireType.FIXED64);
+ return this.decoder_.readUint64String();
+};
+
+
+/**
* Reads a signed 32-bit fixed-length integer fiield from the binary stream, or
* throws an error if the next field in the stream is not of the correct wire
* type.
*
- * @return {number} The value of the double field.
+ * @return {number} The value of the signed 32-bit integer field.
*/
jspb.BinaryReader.prototype.readSfixed32 = function() {
goog.asserts.assert(
@@ -786,11 +817,26 @@ jspb.BinaryReader.prototype.readSfixed32 = function() {
/**
+ * Reads a signed 32-bit fixed-length integer fiield from the binary stream, or
+ * throws an error if the next field in the stream is not of the correct wire
+ * type.
+ *
+ * @return {string} The value of the signed 32-bit integer field as a decimal
+ * string.
+ */
+jspb.BinaryReader.prototype.readSfixed32String = function() {
+ goog.asserts.assert(
+ this.nextWireType_ == jspb.BinaryConstants.WireType.FIXED32);
+ return this.decoder_.readInt32().toString();
+};
+
+
+/**
* Reads a signed 64-bit fixed-length integer fiield from the binary stream, or
* throws an error if the next field in the stream is not of the correct wire
* type.
*
- * @return {number} The value of the float field.
+ * @return {number} The value of the sfixed64 field.
*/
jspb.BinaryReader.prototype.readSfixed64 = function() {
goog.asserts.assert(
@@ -800,6 +846,22 @@ jspb.BinaryReader.prototype.readSfixed64 = function() {
/**
+ * Reads a signed 64-bit fixed-length integer fiield from the binary stream, or
+ * throws an error if the next field in the stream is not of the correct wire
+ * type.
+ *
+ * Returns the value as a string.
+ *
+ * @return {string} The value of the sfixed64 field as a decimal string.
+ */
+jspb.BinaryReader.prototype.readSfixed64String = function() {
+ goog.asserts.assert(
+ this.nextWireType_ == jspb.BinaryConstants.WireType.FIXED64);
+ return this.decoder_.readInt64String();
+};
+
+
+/**
* Reads a 32-bit floating-point field from the binary stream, or throws an
* error if the next field in the stream is not of the correct wire type.
*
@@ -909,7 +971,7 @@ jspb.BinaryReader.prototype.readFixedHash64 = function() {
/**
* Reads a packed scalar field using the supplied raw reader function.
- * @param {function()} decodeMethod
+ * @param {function(this:jspb.BinaryDecoder)} decodeMethod
* @return {!Array}
* @private
*/
@@ -930,7 +992,7 @@ jspb.BinaryReader.prototype.readPackedField_ = function(decodeMethod) {
/**
* Reads a packed int32 field, which consists of a length header and a list of
* signed varints.
- * @return {!Array.<number>}
+ * @return {!Array<number>}
*/
jspb.BinaryReader.prototype.readPackedInt32 = function() {
return this.readPackedField_(this.decoder_.readSignedVarint32);
@@ -940,7 +1002,7 @@ jspb.BinaryReader.prototype.readPackedInt32 = function() {
/**
* Reads a packed int32 field, which consists of a length header and a list of
* signed varints. Returns a list of strings.
- * @return {!Array.<string>}
+ * @return {!Array<string>}
*/
jspb.BinaryReader.prototype.readPackedInt32String = function() {
return this.readPackedField_(this.decoder_.readSignedVarint32String);
@@ -950,7 +1012,7 @@ jspb.BinaryReader.prototype.readPackedInt32String = function() {
/**
* Reads a packed int64 field, which consists of a length header and a list of
* signed varints.
- * @return {!Array.<number>}
+ * @return {!Array<number>}
*/
jspb.BinaryReader.prototype.readPackedInt64 = function() {
return this.readPackedField_(this.decoder_.readSignedVarint64);
@@ -960,7 +1022,7 @@ jspb.BinaryReader.prototype.readPackedInt64 = function() {
/**
* Reads a packed int64 field, which consists of a length header and a list of
* signed varints. Returns a list of strings.
- * @return {!Array.<string>}
+ * @return {!Array<string>}
*/
jspb.BinaryReader.prototype.readPackedInt64String = function() {
return this.readPackedField_(this.decoder_.readSignedVarint64String);
@@ -970,7 +1032,7 @@ jspb.BinaryReader.prototype.readPackedInt64String = function() {
/**
* Reads a packed uint32 field, which consists of a length header and a list of
* unsigned varints.
- * @return {!Array.<number>}
+ * @return {!Array<number>}
*/
jspb.BinaryReader.prototype.readPackedUint32 = function() {
return this.readPackedField_(this.decoder_.readUnsignedVarint32);
@@ -980,7 +1042,7 @@ jspb.BinaryReader.prototype.readPackedUint32 = function() {
/**
* Reads a packed uint32 field, which consists of a length header and a list of
* unsigned varints. Returns a list of strings.
- * @return {!Array.<string>}
+ * @return {!Array<string>}
*/
jspb.BinaryReader.prototype.readPackedUint32String = function() {
return this.readPackedField_(this.decoder_.readUnsignedVarint32String);
@@ -990,7 +1052,7 @@ jspb.BinaryReader.prototype.readPackedUint32String = function() {
/**
* Reads a packed uint64 field, which consists of a length header and a list of
* unsigned varints.
- * @return {!Array.<number>}
+ * @return {!Array<number>}
*/
jspb.BinaryReader.prototype.readPackedUint64 = function() {
return this.readPackedField_(this.decoder_.readUnsignedVarint64);
@@ -1000,7 +1062,7 @@ jspb.BinaryReader.prototype.readPackedUint64 = function() {
/**
* Reads a packed uint64 field, which consists of a length header and a list of
* unsigned varints. Returns a list of strings.
- * @return {!Array.<string>}
+ * @return {!Array<string>}
*/
jspb.BinaryReader.prototype.readPackedUint64String = function() {
return this.readPackedField_(this.decoder_.readUnsignedVarint64String);
@@ -1010,7 +1072,7 @@ jspb.BinaryReader.prototype.readPackedUint64String = function() {
/**
* Reads a packed sint32 field, which consists of a length header and a list of
* zigzag varints.
- * @return {!Array.<number>}
+ * @return {!Array<number>}
*/
jspb.BinaryReader.prototype.readPackedSint32 = function() {
return this.readPackedField_(this.decoder_.readZigzagVarint32);
@@ -1020,7 +1082,7 @@ jspb.BinaryReader.prototype.readPackedSint32 = function() {
/**
* Reads a packed sint64 field, which consists of a length header and a list of
* zigzag varints.
- * @return {!Array.<number>}
+ * @return {!Array<number>}
*/
jspb.BinaryReader.prototype.readPackedSint64 = function() {
return this.readPackedField_(this.decoder_.readZigzagVarint64);
@@ -1028,9 +1090,19 @@ jspb.BinaryReader.prototype.readPackedSint64 = function() {
/**
+ * Reads a packed sint64 field, which consists of a length header and a list of
+ * zigzag varints. Returns a list of strings.
+ * @return {!Array<string>}
+ */
+jspb.BinaryReader.prototype.readPackedSint64String = function() {
+ return this.readPackedField_(this.decoder_.readZigzagVarint64String);
+};
+
+
+/**
* Reads a packed fixed32 field, which consists of a length header and a list
* of unsigned 32-bit ints.
- * @return {!Array.<number>}
+ * @return {!Array<number>}
*/
jspb.BinaryReader.prototype.readPackedFixed32 = function() {
return this.readPackedField_(this.decoder_.readUint32);
@@ -1040,7 +1112,7 @@ jspb.BinaryReader.prototype.readPackedFixed32 = function() {
/**
* Reads a packed fixed64 field, which consists of a length header and a list
* of unsigned 64-bit ints.
- * @return {!Array.<number>}
+ * @return {!Array<number>}
*/
jspb.BinaryReader.prototype.readPackedFixed64 = function() {
return this.readPackedField_(this.decoder_.readUint64);
@@ -1048,9 +1120,19 @@ jspb.BinaryReader.prototype.readPackedFixed64 = function() {
/**
+ * Reads a packed fixed64 field, which consists of a length header and a list
+ * of unsigned 64-bit ints. Returns a list of strings.
+ * @return {!Array<number>}
+ */
+jspb.BinaryReader.prototype.readPackedFixed64String = function() {
+ return this.readPackedField_(this.decoder_.readUint64String);
+};
+
+
+/**
* Reads a packed sfixed32 field, which consists of a length header and a list
* of 32-bit ints.
- * @return {!Array.<number>}
+ * @return {!Array<number>}
*/
jspb.BinaryReader.prototype.readPackedSfixed32 = function() {
return this.readPackedField_(this.decoder_.readInt32);
@@ -1060,7 +1142,7 @@ jspb.BinaryReader.prototype.readPackedSfixed32 = function() {
/**
* Reads a packed sfixed64 field, which consists of a length header and a list
* of 64-bit ints.
- * @return {!Array.<number>}
+ * @return {!Array<number>}
*/
jspb.BinaryReader.prototype.readPackedSfixed64 = function() {
return this.readPackedField_(this.decoder_.readInt64);
@@ -1068,9 +1150,19 @@ jspb.BinaryReader.prototype.readPackedSfixed64 = function() {
/**
+ * Reads a packed sfixed64 field, which consists of a length header and a list
+ * of 64-bit ints. Returns a list of strings.
+ * @return {!Array<string>}
+ */
+jspb.BinaryReader.prototype.readPackedSfixed64String = function() {
+ return this.readPackedField_(this.decoder_.readInt64String);
+};
+
+
+/**
* Reads a packed float field, which consists of a length header and a list of
* floats.
- * @return {!Array.<number>}
+ * @return {!Array<number>}
*/
jspb.BinaryReader.prototype.readPackedFloat = function() {
return this.readPackedField_(this.decoder_.readFloat);
@@ -1080,7 +1172,7 @@ jspb.BinaryReader.prototype.readPackedFloat = function() {
/**
* Reads a packed double field, which consists of a length header and a list of
* doubles.
- * @return {!Array.<number>}
+ * @return {!Array<number>}
*/
jspb.BinaryReader.prototype.readPackedDouble = function() {
return this.readPackedField_(this.decoder_.readDouble);
@@ -1090,7 +1182,7 @@ jspb.BinaryReader.prototype.readPackedDouble = function() {
/**
* Reads a packed bool field, which consists of a length header and a list of
* unsigned varints.
- * @return {!Array.<boolean>}
+ * @return {!Array<boolean>}
*/
jspb.BinaryReader.prototype.readPackedBool = function() {
return this.readPackedField_(this.decoder_.readBool);
@@ -1100,7 +1192,7 @@ jspb.BinaryReader.prototype.readPackedBool = function() {
/**
* Reads a packed enum field, which consists of a length header and a list of
* unsigned varints.
- * @return {!Array.<number>}
+ * @return {!Array<number>}
*/
jspb.BinaryReader.prototype.readPackedEnum = function() {
return this.readPackedField_(this.decoder_.readEnum);
@@ -1110,7 +1202,7 @@ jspb.BinaryReader.prototype.readPackedEnum = function() {
/**
* Reads a packed varint hash64 field, which consists of a length header and a
* list of varint hash64s.
- * @return {!Array.<string>}
+ * @return {!Array<string>}
*/
jspb.BinaryReader.prototype.readPackedVarintHash64 = function() {
return this.readPackedField_(this.decoder_.readVarintHash64);
@@ -1120,7 +1212,7 @@ jspb.BinaryReader.prototype.readPackedVarintHash64 = function() {
/**
* Reads a packed fixed hash64 field, which consists of a length header and a
* list of fixed hash64s.
- * @return {!Array.<string>}
+ * @return {!Array<string>}
*/
jspb.BinaryReader.prototype.readPackedFixedHash64 = function() {
return this.readPackedField_(this.decoder_.readFixedHash64);