code: public static int calculateEncodedLength(BigInteger value) {
          if (value == null) {
              return 1;
          }
          int byteCount = (value.bitLength() >> 3) + 1;
          return unsignedVarIntLength(byteCount) + byteCount;
      }
docs: Returns the amount of bytes required to encode the given BigInteger.
  
  @param value BigInteger value to encode, may be null
  @return amount of bytes needed to encode
  @since 1.2