public static void writeUnsignedVarint ( ByteBuffer buffer , int val ) { // Extra bytes have the high bit set while ( ( val & 0x7F ) != val ) { buffer . put ( ( byte ) ( ( val & 0x7F ) | 0x80 ) ) ; val >>>= 7 ; } // Last byte doesn't have high bit set buffer . put ( ( byte ) ( val & 0x7F ) ) ; }
Write an unsigned integer using a variable - length encoding .