diff options
author | Adam Cozzette <acozzette@gmail.com> | 2016-11-23 11:26:31 -0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2016-11-23 11:26:31 -0800 |
commit | 39f9b43219bc5718b659ed72a2130a7b2ce66108 (patch) | |
tree | e48fe16afc2e1d868408e9453fff521d6ddcd4ae /js/binary/decoder.js | |
parent | c9504715634948c9f8f306330449f296d926b74e (diff) | |
parent | 65479cb7b1f99ab957da68abce17feb68a9e1cf0 (diff) | |
download | protobuf-39f9b43219bc5718b659ed72a2130a7b2ce66108.tar.gz protobuf-39f9b43219bc5718b659ed72a2130a7b2ce66108.tar.bz2 protobuf-39f9b43219bc5718b659ed72a2130a7b2ce66108.zip |
Merge pull request #2403 from google/down-integrate-with-msvc-fix
Integrated internal changes from Google
Diffstat (limited to 'js/binary/decoder.js')
-rw-r--r-- | js/binary/decoder.js | 46 |
1 files changed, 46 insertions, 0 deletions
diff --git a/js/binary/decoder.js b/js/binary/decoder.js index 040cf715..36828a73 100644 --- a/js/binary/decoder.js +++ b/js/binary/decoder.js @@ -733,6 +733,24 @@ jspb.BinaryDecoder.prototype.readZigzagVarint64 = function() { /** + * Reads a signed, zigzag-encoded 64-bit varint from the binary stream and + * returns its valud as a string. + * + * Zigzag encoding is a modification of varint encoding that reduces the + * storage overhead for small negative integers - for more details on the + * format, see https://developers.google.com/protocol-buffers/docs/encoding + * + * @return {string} The decoded signed, zigzag-encoded 64-bit varint as a + * string. + */ +jspb.BinaryDecoder.prototype.readZigzagVarint64String = function() { + // TODO(haberman): write lossless 64-bit zig-zag math. + var value = this.readZigzagVarint64(); + return value.toString(); +}; + + +/** * Reads a raw unsigned 8-bit integer from the binary stream. * * @return {number} The unsigned 8-bit integer read from the binary stream. @@ -791,6 +809,20 @@ jspb.BinaryDecoder.prototype.readUint64 = function() { /** + * Reads a raw unsigned 64-bit integer from the binary stream. Note that since + * Javascript represents all numbers as double-precision floats, there will be + * precision lost if the absolute value of the integer is larger than 2^53. + * + * @return {string} The unsigned 64-bit integer read from the binary stream. + */ +jspb.BinaryDecoder.prototype.readUint64String = function() { + var bitsLow = this.readUint32(); + var bitsHigh = this.readUint32(); + return jspb.utils.joinUnsignedDecimalString(bitsLow, bitsHigh); +}; + + +/** * Reads a raw signed 8-bit integer from the binary stream. * * @return {number} The signed 8-bit integer read from the binary stream. @@ -849,6 +881,20 @@ jspb.BinaryDecoder.prototype.readInt64 = function() { /** + * Reads a raw signed 64-bit integer from the binary stream and returns it as a + * string. + * + * @return {string} The signed 64-bit integer read from the binary stream. + * Precision will be lost if the integer exceeds 2^53. + */ +jspb.BinaryDecoder.prototype.readInt64String = function() { + var bitsLow = this.readUint32(); + var bitsHigh = this.readUint32(); + return jspb.utils.joinSignedDecimalString(bitsLow, bitsHigh); +}; + + +/** * Reads a 32-bit floating-point number from the binary stream, using the * temporary buffer to realign the data. * |