public void encodeUnion(Encoder encoder, Union unionType) throws IOException {
		encoder.openElement(ELEM_TYPE);
		encodeNameIdAttributes(encoder, unionType);
		encoder.writeString(ATTRIB_METATYPE, "union");
		encoder.writeSignedInteger(ATTRIB_SIZE, unionType.getLength());
		encoder.writeSignedInteger(ATTRIB_ALIGNMENT, unionType.getAlignment());
		DataTypeComponent[] comps = unionType.getDefinedComponents();
		for (DataTypeComponent comp : comps) {
			if (comp.getLength() == 0) {
				continue;
			}
			encoder.openElement(ELEM_FIELD);
			String field_name = comp.getFieldName();
			if (field_name == null || field_name.length() == 0) {
				field_name = comp.getDefaultFieldName();
			}
			encoder.writeString(ATTRIB_NAME, field_name);
			encoder.writeSignedInteger(ATTRIB_OFFSET, comp.getOffset());
			encoder.writeSignedInteger(ATTRIB_ID, comp.getOrdinal());
			DataType fieldtype = comp.getDataType();
			encodeTypeRef(encoder, fieldtype, comp.getLength());
			encoder.closeElement(ELEM_FIELD);
		}
		encoder.closeElement(ELEM_TYPE);
	}
Encode a Union data-type to the stream
@param encoder is the stream encoder
@param unionType is the Union data-type
@throws IOException for errors in the underlying stream
Ghidra/Framework/SoftwareModeling/src/main/java/ghidra/program/model/pcode/PcodeDataTypeManager.java