private void writeIterator(int length, Iterator it) throws IOException {
        if (length < Ranges.LIST_PACKED_LENGTH_END) {
            rawOut.writeRawByte((int) (Codes.LIST_PACKED_LENGTH_START + length));
        } else {
            writeCode(Codes.LIST);
            writeCount(length);
        }
        while (it.hasNext()) {
            writeObject(it.next());
        }
    }