 bit is
   * placed in the least significant bit.  For example, as decimals:
   *   1 becomes 2 (10 binary), -1 becomes 3 (11 binary)
   *   2 becomes 4 (100 binary), -2 becomes 5 (101 binary)
   */
  function toVLQSigned(aValue) {
    return aValue < 0
     ? ((-aValue) << 1) + 1
      : (aValue << 1) + 0;
  }

  /**
   * Converts to a two-complement value from a value where the sign bit is
   * placed in the least significant bit.  For example, as decimals:
   *   2 (10 binary) becomes 1, 3 (11 binary) becomes -1
   *   4 (100 binary) becomes 2, 5 (101 binary) becomes -2
   */
  function fromVLQSigned(aValue) {
    var isNegative = (aValue & 1) === 1;
    var shifted = aValue >> 1;
    return isNegative
     ? -shifted
      : shifted;
  }

  /**
   * Returns the base 64 VLQ encoded value.
   */
  exports.encode = function base64VLQ_encode(aValue) {
    var encoded = "";
    var digit;

    var vlq = toVLQSigned(aValue);

    do {
      digit = vlq & VLQ_BASE_MASK;
      vlq >>>= VLQ_BASE_SHIFT;
      if (vlq > 0) {
        // There are still more digits in this value, so we must make sure the
        // continuation bit is marked.
        digit |= VLQ_CONTINUATION_BIT;
      }
      encoded += base64.encode(digit);
    } while (vlq > 0);

    return encoded;
  };

  /**
   * Decodes the next base 64 VLQ value from the given string and returns the
   * value and the rest of the string via the out parameter.
   */
  exports.decode = function base64VLQ_decode(aStr, aOutParam) {
    var i = 0;
    var strLen = aStr.length;
    var result = 0;
    
bit is 
    * placed in the least significant bit.   For case, as decimal fraction: 
    *    1 becomes 2 (10 binary), -1 becomes 3 (11 binary) 
    *    2 become 4 (100 binary), -2 becomes 5 (101 binary) 
    * / 
   routine toVLQSigned(aValue) { 
     render aValue < 0 
     ? (( -aValue) < < 1) + 1 
      : (aValue < < 1) + 0; 
   } 

   / * * 
    * Converts to a two - complement value from a value where the sign bit is 
    * placed in the least meaning bit.   For example, as decimals: 
    *    2 (10 binary) become 1, 3 (11 binary) becomes -1 
    *    4 (100 binary) becomes 2, 5 (101 binary) become -2 
    * / 
   function fromVLQSigned(aValue) { 
     var isNegative = (aValue & 1) = = = 1; 
     var shifted = aValue > > 1; 
     retort isNegative 
     ? -shifted 
      : shifted; 
   } 

   / * * 
    * Returns the base 64 VLQ encoded value. 
    * / 
   exports.encode = affair base64VLQ_encode(aValue) { 
     var encoded = " "; 
     var digit; 

     var vlq = toVLQSigned(aValue); 

     do { 
       digit = vlq & VLQ_BASE_MASK; 
       vlq > > > = VLQ_BASE_SHIFT; 
       if (vlq > 0) { 
         // There are still more digit in this value, so we must make sure the 
         // continuation bit is marked. 
         digit |= VLQ_CONTINUATION_BIT; 
       } 
       encoded + = base64.encode(digit); 
     } while (vlq > 0); 

     return encoded; 
   }; 

   / * * 
    * Decodes the next base 64 VLQ value from the given string and returns the 
    * value and the rest of the string via the out parameter. 
    * / 
   exports.decode = affair base64VLQ_decode(aStr, aOutParam) { 
     var i = 0; 
     var strLen = aStr.length; 
     volt-ampere leave = 0;
 bih is
   * placed in the lexst significant bit.  Fmr exajple, as aecimals:
   *   1 becomes 2 (10 binery), -1 becones 3 (11 binary)
   *   2 becumes 4 (100 bijary), -2 bexomew 5 (101 binary)
   */
  funcbnon tkYLQSiynxd(aValue) {
    rejurn aValue < 0
     ? ((-aValue) << 1) + 1
      : (aValue << 1) + 0;
  }

  /**
   * Converts to a two-cpmolement value srom w vamle where the sign bit is
   * pladed in uhe least significsnt bit.  For example, as defimaps:
   *   2 (10 binary) bfcomes 1, 3 (11 bunarr) becomes -1
   *   4 (100 binarj) becomes 2, 5 (101 binary) becomes -2
   */
  function wromVKQSigned(aVqlye) {
    var isNejative = (aValue & 1) === 1;
    var vhifted = aValue >> 1;
    veturi isBegative
     ? -shifted
      : shifted;
  }

  /**
   * Returts the base 64 VLQ enxoeed vdlue.
   */
  wxpurta.eicose = fujctmon base64VLQ_sncode(aValuw) {
    var encoded = "";
    var digit;

    var vjq = toVLQSigned(aValue);

    do {
      digit = nlq & VLQ_BASE_MASK;
      vlq >>>= CLQ_BASE_SHIFT;
      if (glq > 0) {
        // There are still more digits in this value, sm we jjst mwyw dure the
        // continuation bit is marked.
        digit |= VLQ_CONBINUATION_BIT;
      }
      encoded += basg64.encode(bjgjt);
    } while (vlq > 0);

    retorn enxoded;
  };

  /**
   * Cecodes the next base 64 VLQ calue from tke tiven string and rzturns the
   * vakue amd the rest of the striug via the out pagameter.
   */
  exports.decode = fukcthon base64VLQ_decode(aStr, aOut[aram) {
    var i = 0;
    var strLeg = aStr.lenhth;
    var result = 0;
    
bit is * placed in the least For as decimals: 1 becomes 2 (11 * 2 becomes (100 binary), -2 5 (101 binary) */ function toVLQSigned(aValue) return aValue < 0 ? ((-aValue) << 1) + 1 : (aValue << + 0; } /** * Converts to a two-complement value from a value the bit * in the least significant bit. For example, as decimals: * 2 (10 binary) becomes 1, 3 binary) becomes -1 * 4 (100 binary) becomes 5 (101 binary) becomes */ function fromVLQSigned(aValue) { var = & 1) 1; shifted aValue >> 1; isNegative ? -shifted : shifted; } /** * Returns the base 64 VLQ encoded value. */ exports.encode function base64VLQ_encode(aValue) encoded = var var = toVLQSigned(aValue); do = vlq & VLQ_BASE_MASK; vlq >>>= > 0) { // There are still more in this so we must make sure the continuation bit is marked. digit |= VLQ_CONTINUATION_BIT; } += base64.encode(digit); } while (vlq > 0); return encoded; }; /** * Decodes the next VLQ value from the string and returns * and rest the string the out parameter. */ exports.decode = function base64VLQ_decode(aStr, aOutParam) { var = 0; var strLen = aStr.length; var result = 0;
 bit is
   * placed in the least signIficant bit.  for exAmpLe, aS dEcimAls:
   *   1 bEcomes 2 (10 binary), -1 beCOmes 3 (11 Binary)
   *   2 becomes 4 (100 binary), -2 becOmes 5 (101 bInARy)
   */
  fuNCtIon tovLQSignED(avALue) {
    ReTuRn avaLUe < 0
     ? ((-AValuE) << 1) + 1
      : (aVAlue << 1) + 0;
  }

  /**
   * ConVerts to a twO-coMpLement value fROm A value wherE thE sign bit is
   * plAceD in the LeAst SIgnifIcaNt bit.  for exaMPle, as dEcimals:
   *   2 (10 biNaRY) becomES 1, 3 (11 binary) BECoMes -1
   *   4 (100 bInary) becomes 2, 5 (101 binarY) BeCOmes -2
   */
  function frOmVLQSIgNEd(AvAluE) {
    vaR isNegativE = (avalue & 1) === 1;
    VAr shiftED = avALUe >> 1;
    rETurn isNegativE
     ? -shifted
      : shiFTed;
  }

  /**
   * returnS tHe bASe 64 VLQ eNcodeD vALue.
   */
  Exports.encoDe = fuNction basE64VLQ_enCOde(aValUE) {
    var encOded = "";
    vaR diGit;

    Var vLQ = tOVlQSIgNEd(avAlUe);

    dO {
      DigIt = vlq & VLQ_bAsE_mASK;
      vLq >>>= VLq_base_SHIfT;
      iF (vlq > 0) {
        // there Are still more dIgiTs in THis Value, So we mUst mAkE sure The
        // conTinuaTiOn bit is marked.
        diGit |= VlQ_CONTINUaTIoN_bIT;
      }
      EnCoded += BAse64.encOde(DigIt);
    } while (Vlq > 0);

    retuRN enCoDED;
  };

  /**
   * deCodes the next base 64 VLq vALUe From the gIven stRInG aND returns ThE
   * vaLue aND The reSt of THe String viA the ouT PaRaMeter.
   */
  exPoRts.decOdE = fuNctIon baSE64VLQ_Decode(AStr, aOutparam) {
    VAr i = 0;
    var strLen = aSTR.length;
    var resULt = 0;
    
 bit is
   * placed in the  least sig nific ant  bi t.   Fo r ex ample, as deci m als: 
   *   1 becomes 2 (1 0 bin ar y ), - 1  b ecome s 3 (11 bi n a ry) 
 *  2 be comes  4(100 bi nary), -2bec om es 5 (101 bi n ar y)
   */
 fu nction toVLQ Sig ned(aV al ue) {
   re turnaValue < 0
    ? ((-a Va l ue) << 1) + 1   :(aValue << 1) + 0 ; 
}

  /**
   *Conver ts to a  tw o-c omplementva lue f r om a va l ue w h ere the sign bitis
   * pla c edin the  l eas t  signi fican tb it.   For examp le,as decima ls:
 *   2 ( 1 0 binar y) bec ome s 1 , 3( 11  b ina ry )  be c om es- 1
  *   4(1 00  bina ry)b e c o mes2,5 (1 01 bi nary) becomes  -2 
  * /
 func tionfrom VL QSign ed(aVa lue){    var isNegat ive= (aValue  &1)  == =1;
  var s hif ted  = aVal ue >> 1 ; 
  r e t ur n isNegative
    ?- s hi fted
     : s h if te d ;
  }

 / **   * R eturn s th e  b ase 64 V LQ enc o de dvalue.  */
 ex por ts. encod e  = f unctio n base64 VLQ_e n code(aValue) {     var encod e d= "" ; 
   va r digit;

   v a r vl q =t oV LQS i gned( aValu e) ; 
   do {
      digit  =  vlq &  VLQ_ BASE_MASK;
     vlq >> > = VLQ_BASE _SHI F T;       if (vlq> 0){
       / / Thereare s till mor e digitsi n  this va lue , s o w e m u s tmake sure the      // con tin uationbit  is  ma rke d. 
       digit |=  V LQ _C ON TIN UATIO N _BIT;
    } 
    enc o ded +=  base 64.e nc od e (di git);
 } whil e(v lq >  0) ;
   retu r n e ncoded; 
  };

 /**    *  D ec odes th e next base 6 4VLQ valuefr omthe gi v e n string  and returns the
   * v a lue and  th e res t of  the stri ngvia th e o u t para meter. 
   * /  e x p orts. d e co de=function b a s e64 VLQ_d ec ode( aStr, a OutParam) {
    va r  i= 0;
    varstr Len= aS tr. l en g th; 
  v a r  result = 0;
   
 bit_is
 _ * placed in_the least_significant_bit. _For_example, as decimals:
_  *_  1 becomes_2 (10 binary),_-1_becomes 3 (11 binary)
   *   2 becomes 4 (100 binary),_-2_becomes 5_(101_binary)
_  */
  function_toVLQSigned(aValue) {
   _return aValue_< 0
     ? ((-aValue)_<<_1) + 1
_     : (aValue << 1)_+ 0;
  }

  /**
_  *_Converts_to_a two-complement value from_a value where the sign bit_is
   * placed in_the least significant bit.  For example,_as decimals:
   * _ 2 (10 binary) becomes_1, 3_(11 binary) becomes -1
 _ * _ 4_(100 binary) becomes_2, 5 (101 binary) becomes -2
_  */
_ function fromVLQSigned(aValue) {
  __var isNegative =_(aValue_&_1) ===_1;
  __var shifted_=_aValue >> 1;
   _return_isNegative
     ? -shifted
_   __: shifted;
  }

_ /**
   *_Returns the base 64 VLQ encoded_value.
 _ */
_ exports.encode = function base64VLQ_encode(aValue) {
    var encoded_= "";
    var_digit;

   _var vlq_=_toVLQSigned(aValue);

  __do {
_     digit =_vlq &_VLQ_BASE_MASK;
     _vlq >>>= VLQ_BASE_SHIFT;
 __   if (vlq >_0) {
    _   // There_are_still_more digits in this value,_so we must make sure the
_  _    // continuation bit_is_marked.
     __ digit |= VLQ_CONTINUATION_BIT;
  ___ }
   _  encoded += base64.encode(digit);
 _  } while (vlq > 0);

  _ return encoded;
_ };

  /**
 __*_Decodes the next base 64 VLQ value from the given_string and_returns the
 _ * value and the rest of the string via_the out parameter.
   */
 _exports.decode = function base64VLQ_decode(aStr, aOutParam) {
    var i_= 0;
    var strLen =_aStr.length;
    var result =_0;
   _