public static int encode(int codepoint, byte[] destination, int offset) {
        int writeOffset = offset;
        byte firstByte = firstByte(codepoint);
        int leftToWrite = codePointAsUtf8Length(codepoint) - 1;
        destination[writeOffset++] = firstByte;
        while (leftToWrite-- > 0) {
            destination[writeOffset++] = trailingOctet(codepoint, leftToWrite);
        }
        return writeOffset;
    }
Encode a valid Unicode codepoint as a sequence of UTF-8 bytes into an array.

@param codepoint Unicode codepoint to encode
@param destination array to write into
@param offset index of first byte written
@return index of the first byte after the last byte written (i.e. offset plus number of bytes written)
@throws IndexOutOfBoundsException if there is insufficient room for the encoded data in the given array
vespajlib/src/main/java/com/yahoo/text/Utf8.java