import { asciiToUint6 , uint6ToASCII } from './base64' ; import Reader from './reader' ; import Writer from './writer' ; export function encodeVLQ ( writer , v ) { let num = v < 0 ? ( - v << 1 ) | 1 : v << 1 ; let cont = false ; do { let digit = num & 31 ; num >>= 5 ; cont = num > 0 ; if ( cont ) { digit |= 32 ; } writer . write ( uint6ToASCII [ digit ] ) ; } while ( cont ) ; } export function decodeVLQ ( reader ) { let num = 0 ; let shift = 0 ; let digit = 0 ; let cont = 0 ; do { digit = asciiToUint6 [ reader . read ( ) ] ; cont = digit & 32 ; digit = digit & 31 ; num = num + ( digit << shift ) ; shift += 5 ; } while ( cont > 0 ) ; return num & 1 ? - ( num >> 1 ) : ( num >> 1 ) ; }