Lines Matching +full:- +full:error +full:- +full:asserts
1 // Protocol Buffers - Google's data interchange format
3 // https://developers.google.com/protocol-buffers/
37 * Major caveat - Javascript is unable to accurately represent integers larger
38 * than 2^53 due to its use of a double-precision floating point format or all
39 * numbers. If you need to guarantee that 64-bit values survive with all bits
41 * an 8-character string.
48 goog.require('goog.asserts');
56 * https://developers.google.com/protocol-buffers/docs/encoding.
60 * @param {number=} opt_length The optional length of the block to read -
67 * Typed byte-wise view of the source buffer.
91 * Set to true if this decoder encountered an error due to corrupt data.
114 * @param {number=} opt_length The optional length of the block to read -
148 this.start_, this.end_ - this.start_);
177 * @param {number=} opt_length The optional length of the block to read -
238 goog.asserts.assert(this.cursor_ <= this.end_);
261 * Returns true if this decoder encountered an error due to corrupt data.
276 * It's possible for an unsigned varint to be incorrectly encoded - more than
278 * throw an error.
280 * Decoding varints requires doing some funny base-128 math - for more
282 * https://developers.google.com/protocol-buffers/docs/encoding
321 goog.asserts.fail('Failed to read varint, encoding is invalid.');
332 * It's possible for an unsigned varint to be incorrectly encoded - more than
334 * throw an error.
337 * storage overhead for small negative integers - for more details on the
338 * format, see https://developers.google.com/protocol-buffers/docs/encoding
353 * Reads a 64-bit fixed-width value from the stream and invokes the conversion
368 for (var i = cursor + 7; i >= cursor; i--) {
388 * Skips backwards over a varint in the block - to do this correctly, we have
394 this.cursor_--;
397 this.cursor_--;
402 * Reads a 32-bit varint from the binary stream. Due to a quirk of the encoding
404 * correctly for both signed and unsigned 32-bit varints.
410 * sign-extension. If we're in debug mode and the high 32 bits don't match the
411 * expected sign extension, this method will throw an error.
413 * Decoding varints requires doing some funny base-128 math - for more
415 * https://developers.google.com/protocol-buffers/docs/encoding
417 * @return {number} The decoded unsigned 32-bit varint.
427 goog.asserts.assert(this.cursor_ <= this.end_);
435 goog.asserts.assert(this.cursor_ <= this.end_);
443 goog.asserts.assert(this.cursor_ <= this.end_);
451 goog.asserts.assert(this.cursor_ <= this.end_);
461 goog.asserts.assert(this.cursor_ <= this.end_);
474 goog.asserts.assert(false);
477 goog.asserts.assert(this.cursor_ <= this.end_);
483 * The readUnsignedVarint32 above deals with signed 32-bit varints correctly,
486 * @return {number} The decoded signed 32-bit varint.
493 * Reads a 32-bit unsigned variant and returns its value as a string.
495 * @return {string} The decoded unsigned 32-bit varint as a string.
498 // 32-bit integers fit in JavaScript numbers without loss of precision, so
499 // string variants of 32-bit varint readers can simply delegate then convert
507 * Reads a 32-bit signed variant and returns its value as a string.
509 * @return {string} The decoded signed 32-bit varint as a string.
512 // 32-bit integers fit in JavaScript numbers without loss of precision, so
513 // string variants of 32-bit varint readers can simply delegate then convert
521 * Reads a signed, zigzag-encoded 32-bit varint from the binary stream.
524 * storage overhead for small negative integers - for more details on the
525 * format, see https://developers.google.com/protocol-buffers/docs/encoding
527 * @return {number} The decoded signed, zigzag-encoded 32-bit varint.
531 return (result >>> 1) ^ - (result & 1);
536 * Reads an unsigned 64-bit varint from the binary stream. Note that since
537 * Javascript represents all numbers as double-precision floats, there will be
549 * Reads an unsigned 64-bit varint from the binary stream and returns the value
560 * Reads a signed 64-bit varint from the binary stream. Note that since
561 * Javascript represents all numbers as double-precision floats, there will be
573 * Reads an signed 64-bit varint from the binary stream and returns the value
584 * Reads a signed, zigzag-encoded 64-bit varint from the binary stream. Note
585 * that since Javascript represents all numbers as double-precision floats,
590 * storage overhead for small negative integers - for more details on the
591 * format, see https://developers.google.com/protocol-buffers/docs/encoding
602 * Reads a signed, zigzag-encoded 64-bit varint from the binary stream
603 * losslessly and returns it as an 8-character Unicode string for use as a hash
607 * storage overhead for small negative integers - for more details on the
608 * format, see https://developers.google.com/protocol-buffers/docs/encoding
618 * Reads a signed, zigzag-encoded 64-bit varint from the binary stream and
622 * storage overhead for small negative integers - for more details on the
623 * format, see https://developers.google.com/protocol-buffers/docs/encoding
625 * @return {string} The decoded signed, zigzag-encoded 64-bit varint as a
634 * Reads a raw unsigned 8-bit integer from the binary stream.
636 * @return {number} The unsigned 8-bit integer read from the binary stream.
641 goog.asserts.assert(this.cursor_ <= this.end_);
647 * Reads a raw unsigned 16-bit integer from the binary stream.
649 * @return {number} The unsigned 16-bit integer read from the binary stream.
655 goog.asserts.assert(this.cursor_ <= this.end_);
661 * Reads a raw unsigned 32-bit integer from the binary stream.
663 * @return {number} The unsigned 32-bit integer read from the binary stream.
671 goog.asserts.assert(this.cursor_ <= this.end_);
677 * Reads a raw unsigned 64-bit integer from the binary stream. Note that since
678 * Javascript represents all numbers as double-precision floats, there will be
681 * @return {number} The unsigned 64-bit integer read from the binary stream.
692 * Reads a raw unsigned 64-bit integer from the binary stream. Note that since
693 * Javascript represents all numbers as double-precision floats, there will be
696 * @return {string} The unsigned 64-bit integer read from the binary stream.
706 * Reads a raw signed 8-bit integer from the binary stream.
708 * @return {number} The signed 8-bit integer read from the binary stream.
713 goog.asserts.assert(this.cursor_ <= this.end_);
719 * Reads a raw signed 16-bit integer from the binary stream.
721 * @return {number} The signed 16-bit integer read from the binary stream.
727 goog.asserts.assert(this.cursor_ <= this.end_);
733 * Reads a raw signed 32-bit integer from the binary stream.
735 * @return {number} The signed 32-bit integer read from the binary stream.
743 goog.asserts.assert(this.cursor_ <= this.end_);
749 * Reads a raw signed 64-bit integer from the binary stream. Note that since
750 * Javascript represents all numbers as double-precision floats, there will be
753 * @return {number} The signed 64-bit integer read from the binary stream.
764 * Reads a raw signed 64-bit integer from the binary stream and returns it as a
767 * @return {string} The signed 64-bit integer read from the binary stream.
778 * Reads a 32-bit floating-point number from the binary stream, using the
791 * Reads a 64-bit floating-point number from the binary stream, using the
823 * Reads and parses a UTF-8 encoded unicode string from the stream.
826 * (http://en.wikipedia.org/wiki/UTF-8).
839 if (c < 128) { // Regular 7-bit ASCII.
842 // UTF-8 continuation mark. We are out of sync. This
846 } else if (c < 224) { // UTF-8 with two bytes.
849 } else if (c < 240) { // UTF-8 with three bytes.
853 } else if (c < 248) { // UTF-8 with 4 bytes.
862 codepoint -= 0x10000;
863 // 2. Split this into the high 10-bit value and the low 10-bit value
884 * Reads and parses a UTF-8 encoded unicode string (with length prefix) from
905 goog.asserts.fail('Invalid byte length!');
912 goog.asserts.assert(this.cursor_ <= this.end_);
918 * Reads a 64-bit varint from the stream and returns it as an 8-character
929 * Reads a 64-bit fixed-width value from the stream and returns it as an
930 * 8-character Unicode string for use as a hash table key.