private void encodeStructure(Encoder encoder, Structure type, int size) throws IOException {
		encoder.openElement(ELEM_TYPE);
		encodeNameIdAttributes(encoder, type);
		// if size is 0, insert an Undefined4 component
		//
		int sz = type.getLength();
		if (sz == 0) {
			type = new StructureDataType(type.getCategoryPath(), type.getName(), 1);
			sz = type.getLength();
		}
		encoder.writeString(ATTRIB_METATYPE, "struct");
		encoder.writeSignedInteger(ATTRIB_SIZE, sz);
		encoder.writeSignedInteger(ATTRIB_ALIGNMENT, type.getAlignment());
		DataTypeComponent[] comps = type.getDefinedComponents();
		for (DataTypeComponent comp : comps) {
			if (comp.isBitFieldComponent() || comp.getLength() == 0) {
				// TODO: bitfields, zero-length components and zero-element arrays are not yet supported by decompiler
				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());
			DataType fieldtype = comp.getDataType();
			encodeTypeRef(encoder, fieldtype, comp.getLength());
			encoder.closeElement(ELEM_FIELD);
		}
		encoder.closeElement(ELEM_TYPE);
	}
Encode a Structure data-type to stream
@param encoder is the stream encoder
@param type is the Structure data-type
@param size if non-zero, is the size of the data-type in context
@throws IOException for errors in the underlying stream
Ghidra/Framework/SoftwareModeling/src/main/java/ghidra/program/model/pcode/PcodeDataTypeManager.java