code: static long readUnary(
        final int[] compressedWords,
        final long[] ptrArr) {
  
      int nextWordIndex = (int) ptrArr[NEXT_WORD_IDX]; //must be int
      assert nextWordIndex == ptrArr[NEXT_WORD_IDX]; //catch truncation error
      long bitBuf = ptrArr[BIT_BUF];
      int bufBits = (int) ptrArr[BUF_BITS];
  
      assert compressedWords != null;
      assert nextWordIndex >= 0;
      assert bitBuf >= 0;
      assert bufBits >= 0;
  
      long subTotal = 0;
      int trailingZeros;
  
      //readUnaryLoop:
      while (true) {
        //MAYBE_FILL_BITBUF(compressedWords,nextWordIndex,8); // ensure 8 bits in bit buffer
        if (bufBits < 8) {  // Prepare for an 8-bit peek into the bitstream.
          bitBuf |= ((compressedWords[nextWordIndex++] & 0XFFFF_FFFFL) << bufBits);
          bufBits += 32;
        }
  
        // These 8 bits include either all or part of the Unary codeword.
        final int peek8 = (int) (bitBuf & 0XFFL);
        trailingZeros = Math.min(8, Integer.numberOfTrailingZeros(peek8));
  
        assert ((trailingZeros >= 0) && (trailingZeros <= 8)) : "TZ+ " + trailingZeros;
  
        if (trailingZeros == 8) { // The codeword was partial, so read some more.
          subTotal += 8;
          bufBits -= 8;
          bitBuf >>>= 8;
          continue;
        }
        break;
      }
  
      bufBits -= (1 + trailingZeros);
      bitBuf >>>= (1 + trailingZeros);
  
      ptrArr[NEXT_WORD_IDX] = nextWordIndex;
      assert nextWordIndex == ptrArr[NEXT_WORD_IDX]; //catch sign extension error
      ptrArr[BIT_BUF] = bitBuf;
      ptrArr[BUF_BITS] = bufBits;
      return subTotal + trailingZeros;
    }
docs: visible for test