public Writer writeTag(Object tag, int componentCount) throws IOException {
        Integer shortcutCode = tagToCode.get(tag);
        if (shortcutCode != null) {
            writeCode(shortcutCode);
        } else {
            int index = getStructCache().oldIndex(tag);
            if (index == -1) {
                writeCode(Codes.STRUCTTYPE);
                writeObject(tag);
                writeInt(componentCount);
            } else if (index < Ranges.STRUCT_CACHE_PACKED_END) {
                writeCode((int) Codes.STRUCT_CACHE_PACKED_START + index);
            } else {
                writeCode(Codes.STRUCT);
                writeInt(index);
            }
        }
        return this;
    }