private void encodeTypeDef(Encoder encoder, TypeDef type, int size) throws IOException {
		DataType refType = type.getDataType();
		String format = null;
		int sz = refType.getLength();
		if (sz <= 0) {
			sz = size;
		}
		if (type.isPointer()) {
			if (hasUnsupportedTypedefSettings(type)) {
				// switch refType to undefined type if pointer-typedef settings are unsupported
				refType = Undefined.getUndefinedDataType(sz);
			}
			else {
				AddressSpace space = PointerTypedefInspector.getPointerAddressSpace(type,
					program.getAddressFactory());
				long offset = PointerTypedefInspector.getPointerComponentOffset(type);
				if (offset != 0) {
					encodePointerRelative(encoder, type, offset, space);
					return;
				}
				if (space != null) {
					// Cannot use space, unless we are build an actual Pointer
					// Its possible that refType is still a TypeDef
					refType = type.getBaseDataType();
					encodePointer(encoder, (Pointer) refType, space, type, size);
					return;
				}
			}
		}
		else {
			if (FormatSettingsDefinition.DEF.hasValue(type.getDefaultSettings())) {
				format = FormatSettingsDefinition.DEF.getValueString(type.getDefaultSettings());
				if (format.length() > 4) {
					format = format.substring(0, 3);
				}
			}
		}

		encoder.openElement(ELEM_DEF);
		encodeNameIdAttributes(encoder, type);
		if (format != null) {
			encoder.writeString(ATTRIB_FORMAT, format);
		}

		encodeTypeRef(encoder, refType, sz);
		encoder.closeElement(ELEM_DEF);
	}
Encode a TypeDef data-type to the stream.  Generally this sends
a {@code <def>} element with a {@code <typeref>} reference to the underlying data-type being
typedefed, but we check for Settings on the TypeDef object that can indicate
specialty data-types with their own encodings.
@param encoder is the stream encoder
@param type is the TypeDef to build the XML for
@param size is the size of the data-type for the specific instantiation
@throws IOException for errors in the underlying stream
Ghidra/Framework/SoftwareModeling/src/main/java/ghidra/program/model/pcode/PcodeDataTypeManager.java