import BitArray from '../../common/BitArray' ; import Token from './Token' ; import SimpleToken from './SimpleToken' ; import { short , int } from '../../../customTypings' ; export default class BinaryShiftToken extends SimpleToken { private binaryShiftStart : short ; private binaryShiftByteCount : short ; constructor ( previous , binaryShiftStart , binaryShiftByteCount ) { super ( previous , 0 , 0 ) ; this . binaryShiftStart = < short > binaryShiftStart ; this . binaryShiftByteCount = < short > binaryShiftByteCount ; } Override public appendTo ( bitArray , text ) { for ( let i = 0 ; i < this . binaryShiftByteCount ; i ++ ) { if ( i === 0 || ( i === 31 && this . binaryShiftByteCount <= 62 ) ) { bitArray . appendBits ( 31 , 5 ) ; if ( this . binaryShiftByteCount > 62 ) { bitArray . appendBits ( this . binaryShiftByteCount - 31 , 16 ) ; } else if ( i === 0 ) { bitArray . appendBits ( Math . min ( this . binaryShiftByteCount , 31 ) , 5 ) ; } else { bitArray . appendBits ( this . binaryShiftByteCount - 31 , 5 ) ; } } bitArray . appendBits ( text [ this . binaryShiftStart + i ] , 8 ) ; } } public addBinaryShift ( start , byteCount ) { return new BinaryShiftToken ( this , start , byteCount ) ; } Override public toString ( ) { return '<' + this . binaryShiftStart + '::' + ( this . binaryShiftStart + this . binaryShiftByteCount - 1 ) + '>' ; } }