| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286 | // Protocol Buffers - Google's data interchange format// Copyright 2008 Google Inc.  All rights reserved.// https://developers.google.com/protocol-buffers///// Redistribution and use in source and binary forms, with or without// modification, are permitted provided that the following conditions are// met:////     * Redistributions of source code must retain the above copyright// notice, this list of conditions and the following disclaimer.//     * Redistributions in binary form must reproduce the above// copyright notice, this list of conditions and the following disclaimer// in the documentation and/or other materials provided with the// distribution.//     * Neither the name of Google Inc. nor the names of its// contributors may be used to endorse or promote products derived from// this software without specific prior written permission.//// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE./** * @fileoverview This file contains utilities for converting binary, * wire-format protocol buffers into Javascript data structures. * * jspb's BinaryReader class wraps the BinaryDecoder class to add methods * that understand the protocol buffer syntax and can do the type checking and * bookkeeping necessary to parse trees of nested messages. * * Major caveat - Users of this library _must_ keep their Javascript proto * parsing code in sync with the original .proto file - presumably you'll be * using the typed jspb code generator, but if you bypass that you'll need * to keep things in sync by hand. * * @author aappleby@google.com (Austin Appleby) */goog.provide('jspb.BinaryReader');goog.require('goog.asserts');goog.require('jspb.BinaryConstants');goog.require('jspb.BinaryDecoder');goog.require('jspb.utils');/** * BinaryReader implements the decoders for all the wire types specified in * https://developers.google.com/protocol-buffers/docs/encoding. * * @param {jspb.ByteSource=} opt_bytes The bytes we're reading from. * @param {number=} opt_start The optional offset to start reading at. * @param {number=} opt_length The optional length of the block to read - *     we'll throw an assertion if we go off the end of the block. * @constructor * @struct */jspb.BinaryReader = function(opt_bytes, opt_start, opt_length) {  /**   * Wire-format decoder.   * @private {!jspb.BinaryDecoder}   */  this.decoder_ = jspb.BinaryDecoder.alloc(opt_bytes, opt_start, opt_length);  /**   * Cursor immediately before the field tag.   * @private {number}   */  this.fieldCursor_ = this.decoder_.getCursor();  /**   * Field number of the next field in the buffer, filled in by nextField().   * @private {number}   */  this.nextField_ = jspb.BinaryConstants.INVALID_FIELD_NUMBER;  /**   * Wire type of the next proto field in the buffer, filled in by   * nextField().   * @private {jspb.BinaryConstants.WireType}   */  this.nextWireType_ = jspb.BinaryConstants.WireType.INVALID;  /**   * Set to true if this reader encountered an error due to corrupt data.   * @private {boolean}   */  this.error_ = false;  /**   * User-defined reader callbacks.   * @private {?Object<string, function(!jspb.BinaryReader):*>}   */  this.readCallbacks_ = null;};/** * Global pool of BinaryReader instances. * @private {!Array<!jspb.BinaryReader>} */jspb.BinaryReader.instanceCache_ = [];/** * Pops an instance off the instance cache, or creates one if the cache is * empty. * @param {jspb.ByteSource=} opt_bytes The bytes we're reading from. * @param {number=} opt_start The optional offset to start reading at. * @param {number=} opt_length The optional length of the block to read - *     we'll throw an assertion if we go off the end of the block. * @return {!jspb.BinaryReader} */jspb.BinaryReader.alloc =    function(opt_bytes, opt_start, opt_length) {  if (jspb.BinaryReader.instanceCache_.length) {    var newReader = jspb.BinaryReader.instanceCache_.pop();    if (opt_bytes) {      newReader.decoder_.setBlock(opt_bytes, opt_start, opt_length);    }    return newReader;  } else {    return new jspb.BinaryReader(opt_bytes, opt_start, opt_length);  }};/** * Alias for the above method. * @param {jspb.ByteSource=} opt_bytes The bytes we're reading from. * @param {number=} opt_start The optional offset to start reading at. * @param {number=} opt_length The optional length of the block to read - *     we'll throw an assertion if we go off the end of the block. * @return {!jspb.BinaryReader} */jspb.BinaryReader.prototype.alloc = jspb.BinaryReader.alloc;/** * Puts this instance back in the instance cache. */jspb.BinaryReader.prototype.free = function() {  this.decoder_.clear();  this.nextField_ = jspb.BinaryConstants.INVALID_FIELD_NUMBER;  this.nextWireType_ = jspb.BinaryConstants.WireType.INVALID;  this.error_ = false;  this.readCallbacks_ = null;  if (jspb.BinaryReader.instanceCache_.length < 100) {    jspb.BinaryReader.instanceCache_.push(this);  }};/** * Returns the cursor immediately before the current field's tag. * @return {number} The internal read cursor. */jspb.BinaryReader.prototype.getFieldCursor = function() {  return this.fieldCursor_;};/** * Returns the internal read cursor. * @return {number} The internal read cursor. */jspb.BinaryReader.prototype.getCursor = function() {  return this.decoder_.getCursor();};/** * Returns the raw buffer. * @return {?Uint8Array} The raw buffer. */jspb.BinaryReader.prototype.getBuffer = function() {  return this.decoder_.getBuffer();};/** * @return {number} The field number of the next field in the buffer, or *     INVALID_FIELD_NUMBER if there is no next field. */jspb.BinaryReader.prototype.getFieldNumber = function() {  return this.nextField_;};/** * @return {jspb.BinaryConstants.WireType} The wire type of the next field *     in the stream, or WireType.INVALID if there is no next field. */jspb.BinaryReader.prototype.getWireType = function() {  return this.nextWireType_;};/** * @return {boolean} Whether the current wire type is an end-group tag. Used as * an exit condition in decoder loops in generated code. */jspb.BinaryReader.prototype.isEndGroup = function() {  return this.nextWireType_ == jspb.BinaryConstants.WireType.END_GROUP;};/** * Returns true if this reader hit an error due to corrupt data. * @return {boolean} */jspb.BinaryReader.prototype.getError = function() {  return this.error_ || this.decoder_.getError();};/** * Points this reader at a new block of bytes. * @param {!Uint8Array} bytes The block of bytes we're reading from. * @param {number} start The offset to start reading at. * @param {number} length The length of the block to read. */jspb.BinaryReader.prototype.setBlock = function(bytes, start, length) {  this.decoder_.setBlock(bytes, start, length);  this.nextField_ = jspb.BinaryConstants.INVALID_FIELD_NUMBER;  this.nextWireType_ = jspb.BinaryConstants.WireType.INVALID;};/** * Rewinds the stream cursor to the beginning of the buffer and resets all * internal state. */jspb.BinaryReader.prototype.reset = function() {  this.decoder_.reset();  this.nextField_ = jspb.BinaryConstants.INVALID_FIELD_NUMBER;  this.nextWireType_ = jspb.BinaryConstants.WireType.INVALID;};/** * Advances the stream cursor by the given number of bytes. * @param {number} count The number of bytes to advance by. */jspb.BinaryReader.prototype.advance = function(count) {  this.decoder_.advance(count);};/** * Reads the next field header in the stream if there is one, returns true if * we saw a valid field header or false if we've read the whole stream. * Throws an error if we encountered a deprecated START_GROUP/END_GROUP field. * @return {boolean} True if the stream contains more fields. */jspb.BinaryReader.prototype.nextField = function() {  // If we're at the end of the block, there are no more fields.  if (this.decoder_.atEnd()) {    return false;  }  // If we hit an error decoding the previous field, stop now before we  // try to decode anything else  if (this.getError()) {    goog.asserts.fail('Decoder hit an error');    return false;  }  // Otherwise just read the header of the next field.  this.fieldCursor_ = this.decoder_.getCursor();  var header = this.decoder_.readUnsignedVarint32();  var nextField = header >>> 3;  var nextWireType = /** @type {jspb.BinaryConstants.WireType} */      (header & 0x7);  // If the wire type isn't one of the valid ones, something's broken.  if (nextWireType != jspb.BinaryConstants.WireType.VARINT &&      nextWireType != jspb.BinaryConstants.WireType.FIXED32 &&      nextWireType != jspb.BinaryConstants.WireType.FIXED64 &&      nextWireType != jspb.BinaryConstants.WireType.DELIMITED &&      nextWireType != jspb.BinaryConstants.WireType.START_GROUP &&      nextWireType != jspb.BinaryConstants.WireType.END_GROUP) {    goog.asserts.fail(        'Invalid wire type: %s (at position %s)', nextWireType,        this.fieldCursor_);    this.error_ = true;    return false;  }  this.nextField_ = nextField;  this.nextWireType_ = nextWireType;  return true;};/** * Winds the reader back to just before this field's header. */jspb.BinaryReader.prototype.unskipHeader = function() {  this.decoder_.unskipVarint((this.nextField_ << 3) | this.nextWireType_);};/** * Skips all contiguous fields whose header matches the one we just read. */jspb.BinaryReader.prototype.skipMatchingFields = function() {  var field = this.nextField_;  this.unskipHeader();  while (this.nextField() && (this.getFieldNumber() == field)) {    this.skipField();  }  if (!this.decoder_.atEnd()) {    this.unskipHeader();  }};/** * Skips over the next varint field in the binary stream. */jspb.BinaryReader.prototype.skipVarintField = function() {  if (this.nextWireType_ != jspb.BinaryConstants.WireType.VARINT) {    goog.asserts.fail('Invalid wire type for skipVarintField');    this.skipField();    return;  }  this.decoder_.skipVarint();};/** * Skips over the next delimited field in the binary stream. */jspb.BinaryReader.prototype.skipDelimitedField = function() {  if (this.nextWireType_ != jspb.BinaryConstants.WireType.DELIMITED) {    goog.asserts.fail('Invalid wire type for skipDelimitedField');    this.skipField();    return;  }  var length = this.decoder_.readUnsignedVarint32();  this.decoder_.advance(length);};/** * Skips over the next fixed32 field in the binary stream. */jspb.BinaryReader.prototype.skipFixed32Field = function() {  if (this.nextWireType_ != jspb.BinaryConstants.WireType.FIXED32) {    goog.asserts.fail('Invalid wire type for skipFixed32Field');    this.skipField();    return;  }  this.decoder_.advance(4);};/** * Skips over the next fixed64 field in the binary stream. */jspb.BinaryReader.prototype.skipFixed64Field = function() {  if (this.nextWireType_ != jspb.BinaryConstants.WireType.FIXED64) {    goog.asserts.fail('Invalid wire type for skipFixed64Field');    this.skipField();    return;  }  this.decoder_.advance(8);};/** * Skips over the next group field in the binary stream. */jspb.BinaryReader.prototype.skipGroup = function() {  var previousField = this.nextField_;  do {    if (!this.nextField()) {      goog.asserts.fail('Unmatched start-group tag: stream EOF');      this.error_ = true;      return;    }    if (this.nextWireType_ ==               jspb.BinaryConstants.WireType.END_GROUP) {      // Group end: check that it matches top-of-stack.      if (this.nextField_ != previousField) {        goog.asserts.fail('Unmatched end-group tag');        this.error_ = true;        return;      }      return;    }    this.skipField();  } while (true);};/** * Skips over the next field in the binary stream - this is useful if we're * decoding a message that contain unknown fields. */jspb.BinaryReader.prototype.skipField = function() {  switch (this.nextWireType_) {    case jspb.BinaryConstants.WireType.VARINT:      this.skipVarintField();      break;    case jspb.BinaryConstants.WireType.FIXED64:      this.skipFixed64Field();      break;    case jspb.BinaryConstants.WireType.DELIMITED:      this.skipDelimitedField();      break;    case jspb.BinaryConstants.WireType.FIXED32:      this.skipFixed32Field();      break;    case jspb.BinaryConstants.WireType.START_GROUP:      this.skipGroup();      break;    default:      goog.asserts.fail('Invalid wire encoding for field.');  }};/** * Registers a user-defined read callback. * @param {string} callbackName * @param {function(!jspb.BinaryReader):*} callback */jspb.BinaryReader.prototype.registerReadCallback =    function(callbackName, callback) {  if (goog.isNull(this.readCallbacks_)) {    this.readCallbacks_ = {};  }  goog.asserts.assert(!this.readCallbacks_[callbackName]);  this.readCallbacks_[callbackName] = callback;};/** * Runs a registered read callback. * @param {string} callbackName The name the callback is registered under. * @return {*} The value returned by the callback. */jspb.BinaryReader.prototype.runReadCallback = function(callbackName) {  goog.asserts.assert(!goog.isNull(this.readCallbacks_));  var callback = this.readCallbacks_[callbackName];  goog.asserts.assert(callback);  return callback(this);};/** * Reads a field of any valid non-message type from the binary stream. * @param {jspb.BinaryConstants.FieldType} fieldType * @return {jspb.AnyFieldType} */jspb.BinaryReader.prototype.readAny = function(fieldType) {  this.nextWireType_ = jspb.BinaryConstants.FieldTypeToWireType(fieldType);  var fieldTypes = jspb.BinaryConstants.FieldType;  switch (fieldType) {    case fieldTypes.DOUBLE:      return this.readDouble();    case fieldTypes.FLOAT:      return this.readFloat();    case fieldTypes.INT64:      return this.readInt64();    case fieldTypes.UINT64:      return this.readUint64();    case fieldTypes.INT32:      return this.readInt32();    case fieldTypes.FIXED64:      return this.readFixed64();    case fieldTypes.FIXED32:      return this.readFixed32();    case fieldTypes.BOOL:      return this.readBool();    case fieldTypes.STRING:      return this.readString();    case fieldTypes.GROUP:      goog.asserts.fail('Group field type not supported in readAny()');    case fieldTypes.MESSAGE:      goog.asserts.fail('Message field type not supported in readAny()');    case fieldTypes.BYTES:      return this.readBytes();    case fieldTypes.UINT32:      return this.readUint32();    case fieldTypes.ENUM:      return this.readEnum();    case fieldTypes.SFIXED32:      return this.readSfixed32();    case fieldTypes.SFIXED64:      return this.readSfixed64();    case fieldTypes.SINT32:      return this.readSint32();    case fieldTypes.SINT64:      return this.readSint64();    case fieldTypes.FHASH64:      return this.readFixedHash64();    case fieldTypes.VHASH64:      return this.readVarintHash64();    default:      goog.asserts.fail('Invalid field type in readAny()');  }  return 0;};/** * Deserialize a proto into the provided message object using the provided * reader function. This function is templated as we currently have one client * who is using manual deserialization instead of the code-generated versions. * @template T * @param {T} message * @param {function(T, !jspb.BinaryReader)} reader */jspb.BinaryReader.prototype.readMessage = function(message, reader) {  goog.asserts.assert(      this.nextWireType_ == jspb.BinaryConstants.WireType.DELIMITED);  // Save the current endpoint of the decoder and move it to the end of the  // embedded message.  var oldEnd = this.decoder_.getEnd();  var length = this.decoder_.readUnsignedVarint32();  var newEnd = this.decoder_.getCursor() + length;  this.decoder_.setEnd(newEnd);  // Deserialize the embedded message.  reader(message, this);  // Advance the decoder past the embedded message and restore the endpoint.  this.decoder_.setCursor(newEnd);  this.decoder_.setEnd(oldEnd);};/** * Deserialize a proto into the provided message object using the provided * reader function, assuming that the message is serialized as a group * with the given tag. * @template T * @param {number} field * @param {T} message * @param {function(T, !jspb.BinaryReader)} reader */jspb.BinaryReader.prototype.readGroup =    function(field, message, reader) {  // Ensure that the wire type is correct.  goog.asserts.assert(      this.nextWireType_ == jspb.BinaryConstants.WireType.START_GROUP);  // Ensure that the field number is correct.  goog.asserts.assert(this.nextField_ == field);  // Deserialize the message. The deserialization will stop at an END_GROUP tag.  reader(message, this);  if (!this.error_ &&      this.nextWireType_ != jspb.BinaryConstants.WireType.END_GROUP) {    goog.asserts.fail('Group submessage did not end with an END_GROUP tag');    this.error_ = true;  }};/** * Return a decoder that wraps the current delimited field. * @return {!jspb.BinaryDecoder} */jspb.BinaryReader.prototype.getFieldDecoder = function() {  goog.asserts.assert(      this.nextWireType_ == jspb.BinaryConstants.WireType.DELIMITED);  var length = this.decoder_.readUnsignedVarint32();  var start = this.decoder_.getCursor();  var end = start + length;  var innerDecoder =      jspb.BinaryDecoder.alloc(this.decoder_.getBuffer(), start, length);  this.decoder_.setCursor(end);  return innerDecoder;};/** * Reads a signed 32-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 {number} The value of the signed 32-bit integer field. */jspb.BinaryReader.prototype.readInt32 = function() {  goog.asserts.assert(      this.nextWireType_ == jspb.BinaryConstants.WireType.VARINT);  return this.decoder_.readSignedVarint32();};/** * Reads a signed 32-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. * * Returns the value as a string. * * @return {string} The value of the signed 32-bit integer field as a decimal * string. */jspb.BinaryReader.prototype.readInt32String = function() {  goog.asserts.assert(      this.nextWireType_ == jspb.BinaryConstants.WireType.VARINT);  return this.decoder_.readSignedVarint32String();};/** * Reads a signed 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 {number} The value of the signed 64-bit integer field. */jspb.BinaryReader.prototype.readInt64 = function() {  goog.asserts.assert(      this.nextWireType_ == jspb.BinaryConstants.WireType.VARINT);  return this.decoder_.readSignedVarint64();};/** * Reads a signed 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. * * Returns the value as a string. * * @return {string} The value of the signed 64-bit integer field as a decimal * string. */jspb.BinaryReader.prototype.readInt64String = function() {  goog.asserts.assert(      this.nextWireType_ == jspb.BinaryConstants.WireType.VARINT);  return this.decoder_.readSignedVarint64String();};/** * Reads an unsigned 32-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 {number} The value of the unsigned 32-bit integer field. */jspb.BinaryReader.prototype.readUint32 = function() {  goog.asserts.assert(      this.nextWireType_ == jspb.BinaryConstants.WireType.VARINT);  return this.decoder_.readUnsignedVarint32();};/** * Reads an unsigned 32-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. * * Returns the value as a string. * * @return {string} The value of the unsigned 32-bit integer field as a decimal * string. */jspb.BinaryReader.prototype.readUint32String = function() {  goog.asserts.assert(      this.nextWireType_ == jspb.BinaryConstants.WireType.VARINT);  return this.decoder_.readUnsignedVarint32String();};/** * Reads an unsigned 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 {number} The value of the unsigned 64-bit integer field. */jspb.BinaryReader.prototype.readUint64 = function() {  goog.asserts.assert(      this.nextWireType_ == jspb.BinaryConstants.WireType.VARINT);  return this.decoder_.readUnsignedVarint64();};/** * Reads an unsigned 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. * * Returns the value as a string. * * @return {string} The value of the unsigned 64-bit integer field as a decimal * string. */jspb.BinaryReader.prototype.readUint64String = function() {  goog.asserts.assert(      this.nextWireType_ == jspb.BinaryConstants.WireType.VARINT);  return this.decoder_.readUnsignedVarint64String();};/** * Reads a signed zigzag-encoded 32-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 {number} The value of the signed 32-bit integer field. */jspb.BinaryReader.prototype.readSint32 = function() {  goog.asserts.assert(      this.nextWireType_ == jspb.BinaryConstants.WireType.VARINT);  return this.decoder_.readZigzagVarint32();};/** * 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 {number} The value of the signed 64-bit integer field. */jspb.BinaryReader.prototype.readSint64 = function() {  goog.asserts.assert(      this.nextWireType_ == jspb.BinaryConstants.WireType.VARINT);  return this.decoder_.readZigzagVarint64();};/** * 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. * * @return {number} The value of the double field. */jspb.BinaryReader.prototype.readFixed32 = function() {  goog.asserts.assert(      this.nextWireType_ == jspb.BinaryConstants.WireType.FIXED32);  return this.decoder_.readUint32();};/** * Reads an unsigned 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. */jspb.BinaryReader.prototype.readFixed64 = function() {  goog.asserts.assert(      this.nextWireType_ == jspb.BinaryConstants.WireType.FIXED64);  return this.decoder_.readUint64();};/** * 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 signed 32-bit integer field. */jspb.BinaryReader.prototype.readSfixed32 = function() {  goog.asserts.assert(      this.nextWireType_ == jspb.BinaryConstants.WireType.FIXED32);  return this.decoder_.readInt32();};/** * 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 sfixed64 field. */jspb.BinaryReader.prototype.readSfixed64 = function() {  goog.asserts.assert(      this.nextWireType_ == jspb.BinaryConstants.WireType.FIXED64);  return this.decoder_.readInt64();};/** * 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. * * @return {number} The value of the float field. */jspb.BinaryReader.prototype.readFloat = function() {  goog.asserts.assert(      this.nextWireType_ == jspb.BinaryConstants.WireType.FIXED32);  return this.decoder_.readFloat();};/** * Reads a 64-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. * * @return {number} The value of the double field. */jspb.BinaryReader.prototype.readDouble = function() {  goog.asserts.assert(      this.nextWireType_ == jspb.BinaryConstants.WireType.FIXED64);  return this.decoder_.readDouble();};/** * Reads a boolean field from the binary stream, or throws an error if the next * field in the stream is not of the correct wire type. * * @return {boolean} The value of the boolean field. */jspb.BinaryReader.prototype.readBool = function() {  goog.asserts.assert(      this.nextWireType_ == jspb.BinaryConstants.WireType.VARINT);  return !!this.decoder_.readUnsignedVarint32();};/** * Reads an enum field 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 enum field. */jspb.BinaryReader.prototype.readEnum = function() {  goog.asserts.assert(      this.nextWireType_ == jspb.BinaryConstants.WireType.VARINT);  return this.decoder_.readSignedVarint64();};/** * Reads a string 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 string field. */jspb.BinaryReader.prototype.readString = function() {  goog.asserts.assert(      this.nextWireType_ == jspb.BinaryConstants.WireType.DELIMITED);  var length = this.decoder_.readUnsignedVarint32();  return this.decoder_.readString(length);};/** * Reads a length-prefixed block of bytes from the binary stream, or returns * null if the next field in the stream has an invalid length value. * * @return {!Uint8Array} The block of bytes. */jspb.BinaryReader.prototype.readBytes = function() {  goog.asserts.assert(      this.nextWireType_ == jspb.BinaryConstants.WireType.DELIMITED);  var length = this.decoder_.readUnsignedVarint32();  return this.decoder_.readBytes(length);};/** * Reads a 64-bit varint or fixed64 field from the stream and returns it as an * 8-character Unicode string for use as a hash table key, or throws an error * if the next field in the stream is not of the correct wire type. * * @return {string} The hash value. */jspb.BinaryReader.prototype.readVarintHash64 = function() {  goog.asserts.assert(      this.nextWireType_ == jspb.BinaryConstants.WireType.VARINT);  return this.decoder_.readVarintHash64();};/** * Reads an sint64 field from the stream and returns it as an 8-character * Unicode string for use as a hash table key, or throws an error if the next * field in the stream is not of the correct wire type. * * @return {string} The hash value. */jspb.BinaryReader.prototype.readSintHash64 = function() {  goog.asserts.assert(      this.nextWireType_ == jspb.BinaryConstants.WireType.VARINT);  return this.decoder_.readZigzagVarintHash64();};/** * Reads a 64-bit varint field from the stream and invokes `convert` to produce * the return value, or throws an error if the next field in the stream is not * of the correct wire type. * * @param {function(number, number): T} convert Conversion function to produce *     the result value, takes parameters (lowBits, highBits). * @return {T} * @template T */jspb.BinaryReader.prototype.readSplitVarint64 = function(convert) {  goog.asserts.assert(      this.nextWireType_ == jspb.BinaryConstants.WireType.VARINT);  return this.decoder_.readSplitVarint64(convert);};/** * Reads a 64-bit zig-zag varint field from the stream and invokes `convert` to * produce the return value, or throws an error if the next field in the stream * is not of the correct wire type. * * @param {function(number, number): T} convert Conversion function to produce *     the result value, takes parameters (lowBits, highBits). * @return {T} * @template T */jspb.BinaryReader.prototype.readSplitZigzagVarint64 = function(convert) {  goog.asserts.assert(      this.nextWireType_ == jspb.BinaryConstants.WireType.VARINT);  return this.decoder_.readSplitVarint64(function(lowBits, highBits) {    return jspb.utils.fromZigzag64(lowBits, highBits, convert);  });};/** * Reads a 64-bit varint or fixed64 field from the stream and returns it as a * 8-character Unicode string for use as a hash table key, or throws an error * if the next field in the stream is not of the correct wire type. * * @return {string} The hash value. */jspb.BinaryReader.prototype.readFixedHash64 = function() {  goog.asserts.assert(      this.nextWireType_ == jspb.BinaryConstants.WireType.FIXED64);  return this.decoder_.readFixedHash64();};/** * Reads a 64-bit fixed64 field from the stream and invokes `convert` * to produce the return value, or throws an error if the next field in the * stream is not of the correct wire type. * * @param {function(number, number): T} convert Conversion function to produce *     the result value, takes parameters (lowBits, highBits). * @return {T} * @template T */jspb.BinaryReader.prototype.readSplitFixed64 = function(convert) {  goog.asserts.assert(      this.nextWireType_ == jspb.BinaryConstants.WireType.FIXED64);  return this.decoder_.readSplitFixed64(convert);};/** * Reads a packed scalar field using the supplied raw reader function. * @param {function(this:jspb.BinaryDecoder)} decodeMethod * @return {!Array} * @private */jspb.BinaryReader.prototype.readPackedField_ = function(decodeMethod) {  goog.asserts.assert(      this.nextWireType_ == jspb.BinaryConstants.WireType.DELIMITED);  var length = this.decoder_.readUnsignedVarint32();  var end = this.decoder_.getCursor() + length;  var result = [];  while (this.decoder_.getCursor() < end) {    // TODO(aappleby): .call is slow    result.push(decodeMethod.call(this.decoder_));  }  return result;};/** * Reads a packed int32 field, which consists of a length header and a list of * signed varints. * @return {!Array<number>} */jspb.BinaryReader.prototype.readPackedInt32 = function() {  return this.readPackedField_(this.decoder_.readSignedVarint32);};/** * 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>} */jspb.BinaryReader.prototype.readPackedInt32String = function() {  return this.readPackedField_(this.decoder_.readSignedVarint32String);};/** * Reads a packed int64 field, which consists of a length header and a list of * signed varints. * @return {!Array<number>} */jspb.BinaryReader.prototype.readPackedInt64 = function() {  return this.readPackedField_(this.decoder_.readSignedVarint64);};/** * 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>} */jspb.BinaryReader.prototype.readPackedInt64String = function() {  return this.readPackedField_(this.decoder_.readSignedVarint64String);};/** * Reads a packed uint32 field, which consists of a length header and a list of * unsigned varints. * @return {!Array<number>} */jspb.BinaryReader.prototype.readPackedUint32 = function() {  return this.readPackedField_(this.decoder_.readUnsignedVarint32);};/** * 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>} */jspb.BinaryReader.prototype.readPackedUint32String = function() {  return this.readPackedField_(this.decoder_.readUnsignedVarint32String);};/** * Reads a packed uint64 field, which consists of a length header and a list of * unsigned varints. * @return {!Array<number>} */jspb.BinaryReader.prototype.readPackedUint64 = function() {  return this.readPackedField_(this.decoder_.readUnsignedVarint64);};/** * 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>} */jspb.BinaryReader.prototype.readPackedUint64String = function() {  return this.readPackedField_(this.decoder_.readUnsignedVarint64String);};/** * Reads a packed sint32 field, which consists of a length header and a list of * zigzag varints. * @return {!Array<number>} */jspb.BinaryReader.prototype.readPackedSint32 = function() {  return this.readPackedField_(this.decoder_.readZigzagVarint32);};/** * Reads a packed sint64 field, which consists of a length header and a list of * zigzag varints. * @return {!Array<number>} */jspb.BinaryReader.prototype.readPackedSint64 = function() {  return this.readPackedField_(this.decoder_.readZigzagVarint64);};/** * 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>} */jspb.BinaryReader.prototype.readPackedFixed32 = function() {  return this.readPackedField_(this.decoder_.readUint32);};/** * Reads a packed fixed64 field, which consists of a length header and a list * of unsigned 64-bit ints. * @return {!Array<number>} */jspb.BinaryReader.prototype.readPackedFixed64 = function() {  return this.readPackedField_(this.decoder_.readUint64);};/** * 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>} */jspb.BinaryReader.prototype.readPackedSfixed32 = function() {  return this.readPackedField_(this.decoder_.readInt32);};/** * Reads a packed sfixed64 field, which consists of a length header and a list * of 64-bit ints. * @return {!Array<number>} */jspb.BinaryReader.prototype.readPackedSfixed64 = function() {  return this.readPackedField_(this.decoder_.readInt64);};/** * 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>} */jspb.BinaryReader.prototype.readPackedFloat = function() {  return this.readPackedField_(this.decoder_.readFloat);};/** * Reads a packed double field, which consists of a length header and a list of * doubles. * @return {!Array<number>} */jspb.BinaryReader.prototype.readPackedDouble = function() {  return this.readPackedField_(this.decoder_.readDouble);};/** * Reads a packed bool field, which consists of a length header and a list of * unsigned varints. * @return {!Array<boolean>} */jspb.BinaryReader.prototype.readPackedBool = function() {  return this.readPackedField_(this.decoder_.readBool);};/** * Reads a packed enum field, which consists of a length header and a list of * unsigned varints. * @return {!Array<number>} */jspb.BinaryReader.prototype.readPackedEnum = function() {  return this.readPackedField_(this.decoder_.readEnum);};/** * Reads a packed varint hash64 field, which consists of a length header and a * list of varint hash64s. * @return {!Array<string>} */jspb.BinaryReader.prototype.readPackedVarintHash64 = function() {  return this.readPackedField_(this.decoder_.readVarintHash64);};/** * Reads a packed fixed hash64 field, which consists of a length header and a * list of fixed hash64s. * @return {!Array<string>} */jspb.BinaryReader.prototype.readPackedFixedHash64 = function() {  return this.readPackedField_(this.decoder_.readFixedHash64);};
 |