public static int writeVint ( byte [ ] dest , int offset , int i ) { if ( i >= - 112 && i <= 127 ) { dest [ offset ++ ] = ( byte ) i ; } else { int len = - 112 ; if ( i < 0 ) { i ^= - 1L ; // take one's complement' len = - 120 ; } long tmp = i ; while ( tmp != 0 ) { tmp = tmp >> 8 ; len -- ; } dest [ offset ++ ] = ( byte ) len ; len = ( len < - 120 ) ? - ( len + 120 ) : - ( len + 112 ) ; for ( int idx = len ; idx != 0 ; idx -- ) { int shiftbits = ( idx - 1 ) * 8 ; long mask = 0xFF L << shiftbits ; dest [ offset ++ ] = ( byte ) ( ( i & mask ) >> shiftbits ) ; } } return offset ; }
Writes a vInt directly to a byte array