code: def multidim_measurement_to_attachment(name, measurement):
    
  
    dimensions = list(measurement.dimensions)
    if measurement.units:
      dimensions.append(
          measurements.Dimension.from_unit_descriptor(measurement.units))
  
    dims = []
    for d in dimensions:
      if d.suffix is None:
        suffix = u''
      # Ensure that the suffix is unicode. It's typically str/bytes because
      # units.py looks them up against str/bytes.
      elif isinstance(d.suffix, unicode):
        suffix = d.suffix
      else:
        suffix = d.suffix.decode('utf8')
      dims.append({
          'uom_suffix': suffix,
          'uom_code': d.code,
          'name': d.name,
      })
    # Refer to the module docstring for the expected schema.
    dimensioned_measured_value = measurement.measured_value
    value = (sorted(dimensioned_measured_value.value, key=lambda x: x[0])
             if dimensioned_measured_value.is_value_set else None)
    outcome_str = MEASUREMENT_OUTCOME_TO_TEST_RUN_STATUS_NAME[measurement.outcome]
    data = _convert_object_to_json({
        'outcome': outcome_str,
        'name': name,
        'dimensions': dims,
        'value': value,
    })
    attachment = htf_test_record.Attachment(data, test_runs_pb2.MULTIDIM_JSON)
  
    return attachment
docs: Convert a multi-dim measurement to an `openhtf.test_record.Attachment`.