final void encodeUtf8(final String stringValue, final int offset) {
        int charLength = stringValue.length();
        int byteLength = offset;
        for (int i = offset; i < charLength; ++i) {
            char charValue = stringValue.charAt(i);
            if (charValue >= 0x0001 && charValue <= 0x007F) {
                byteLength++;
            } else if (charValue <= 0x07FF) {
                byteLength += 2;
            } else {
                byteLength += 3;
            }
        }
        if (byteLength > 65535) {
            throw new IllegalArgumentException("UTF8 string too large");
        }
        // Compute where 'byteLength' must be stored in 'data', and store it at this location.
        int byteLengthOffset = length - offset - 2;
        if (byteLengthOffset >= 0) {
            data[byteLengthOffset] = (byte) (byteLength >>> 8);
            data[byteLengthOffset + 1] = (byte) byteLength;
        }
        if (length + byteLength - offset > data.length) {
            enlarge(byteLength - offset);
        }
        int currentLength = length;
        for (int i = offset; i < charLength; ++i) {
            char charValue = stringValue.charAt(i);
            if (charValue >= 0x0001 && charValue <= 0x007F) {
                data[currentLength++] = (byte) charValue;
            } else if (charValue <= 0x07FF) {
                data[currentLength++] = (byte) (0xC0 | charValue >> 6 & 0x1F);
                data[currentLength++] = (byte) (0x80 | charValue & 0x3F);
            } else {
                data[currentLength++] = (byte) (0xE0 | charValue >> 12 & 0xF);
                data[currentLength++] = (byte) (0x80 | charValue >> 6 & 0x3F);
                data[currentLength++] = (byte) (0x80 | charValue & 0x3F);
            }
        }
        length = currentLength;
    }
Puts an UTF8 string into this byte vector. The byte vector is automatically enlarged if
necessary. The string length is encoded in two bytes before the encoded characters, if there is
space for that (i.e. if this.length - offset - 2 &gt;= 0).

@param stringValue the String to encode.
@param offset the index of the first character to encode. The previous characters are supposed
to have already been encoded, using only one byte per character.
core/src/main/java/com/alibaba/fastjson2/internal/asm/ByteVector.java