code: static int writeUtf8(AbstractByteBuf buffer, int writerIndex, CharSequence seq, int len) {
          int oldWriterIndex = writerIndex;
  
          // We can use the _set methods as these not need to do any index checks and reference checks.
          // This is possible as we called ensureWritable(...) before.
          for (int i = 0; i < len; i++) {
              char c = seq.charAt(i);
              if (c < 0x80) {
                  buffer._setByte(writerIndex++, (byte) c);
              } else if (c < 0x800) {
                  buffer._setByte(writerIndex++, (byte) (0xc0 | (c >> 6)));
                  buffer._setByte(writerIndex++, (byte) (0x80 | (c & 0x3f)));
              } else if (isSurrogate(c)) {
                  if (!Character.isHighSurrogate(c)) {
                      buffer._setByte(writerIndex++, WRITE_UTF_UNKNOWN);
                      continue;
                  }
                  final char c2;
                  try {
                      // Surrogate Pair consumes 2 characters. Optimistically try to get the next character to avoid
                      // duplicate bounds checking with charAt. If an IndexOutOfBoundsException is thrown we will
                      // re-throw a more informative exception describing the problem.
                      c2 = seq.charAt(++i);
                  } catch (IndexOutOfBoundsException ignored) {
                      buffer._setByte(writerIndex++, WRITE_UTF_UNKNOWN);
                      break;
                  }
                  // Extra method to allow inlining the rest of writeUtf8 which is the most likely code path.
                  writerIndex = writeUtf8Surrogate(buffer, writerIndex, c, c2);
              } else {
                  buffer._setByte(writerIndex++, (byte) (0xe0 | (c >> 12)));
                  buffer._setByte(writerIndex++, (byte) (0x80 | ((c >> 6) & 0x3f)));
                  buffer._setByte(writerIndex++, (byte) (0x80 | (c & 0x3f)));
              }
          }
          return writerIndex - oldWriterIndex;
      }
docs: Fast-Path implementation