public Writer writeString(Object o) throws IOException {
        if (o == null) {
            writeNull();
            return this;
        }
        CharSequence s = (CharSequence) o;
        int stringPos = 0;
        int bufPos = 0;
        int maxBufNeeded = Math.min(s.length() * 3, 65536);
        if ((stringBuffer == null) || (stringBuffer.length < maxBufNeeded)) {
            stringBuffer = new byte[maxBufNeeded];
        }
        do {
            int[] temp = bufferStringChunkUTF8(s, stringPos, stringBuffer);
            stringPos = temp[0];
            bufPos = temp[1];
            if (bufPos < Ranges.STRING_PACKED_LENGTH_END) {
                rawOut.writeRawByte((int) (Codes.STRING_PACKED_LENGTH_START + bufPos));
            } else if (stringPos == s.length()) {
                writeCode(Codes.STRING);
                writeCount(bufPos);
            } else {
                writeCode(Codes.STRING_CHUNK);
                writeCount(bufPos);
            }
            rawOut.writeRawBytes(stringBuffer, 0, bufPos);
        } while (stringPos < s.length());

        return this;
    }