code: def to_yaml(obj):
      
      if not isinstance(obj, CompoundValue) and hasattr(obj, 'transfer'):
          if hasattr(obj, 'message'):
              payload = obj.message
              header = 'Message'
          elif hasattr(obj, 'request'):
              payload = obj.request
              header = 'Request'
          elif hasattr(obj, 'response'):
              payload = obj.response
              header = 'Response'
          else:
              raise ValueError('Cannot generate YAML representation for %r' % type(obj))
  
          prefix = '### %s from %s to %s  ts_mono=%.6f  ts_real=%.6f\n' % \
                   (header,
                    obj.transfer.source_node_id or 'Anon',
                    obj.transfer.dest_node_id or 'All',
                    obj.transfer.ts_monotonic, obj.transfer.ts_real)
  
          return prefix + _to_yaml_impl(payload)
      else:
          return _to_yaml_impl(obj)
docs: This function returns correct YAML representation of a UAVCAN structure (message, request, or response), or
      a DSDL entity (array or primitive), or a UAVCAN transfer, with comments for human benefit.
      Args:
          obj:            Object to convert.
  
      Returns: Unicode string containing YAML representation of the object.