public void writeRawTags(Writable writable, int nextDefinedTag) {
        while (iter.hasNext()) {
            RawTaggedField field = iter.next();
            int tag = field.tag();
            if (tag >= nextDefinedTag) {
                if (tag == nextDefinedTag) {
                    // We must not have a raw tag field that duplicates the tag of another field.
                    throw new RuntimeException("Attempted to use tag " + tag + " as an " +
                        "undefined tag.");
                }
                iter.previous();
                return;
            }
            if (tag <= prevTag) {
                // The raw tag field list must be sorted by tag, and there must not be
                // any duplicate tags.
                throw new RuntimeException("Invalid raw tag field list: tag " + tag +
                    " comes after tag " + prevTag + ", but is not higher than it.");
            }
            writable.writeUnsignedVarint(field.tag());
            writable.writeUnsignedVarint(field.data().length);
            writable.writeByteArray(field.data());
            prevTag = tag;
        }
    }
The RawTaggedFieldWriter is used by Message subclasses to serialize their
lists of raw tags.
clients/src/main/java/org/apache/kafka/common/protocol/types/RawTaggedFieldWriter.java