code: def to_dict(self):
          
          d = {field: getattr(self, field) for field in self._top_fields if hasattr(self, field)}
  
          # set values of data fields
          d['data'] = {}
          for field in self._fields:
              if hasattr(self, field):
                  # base64 encode the field for transmission if necessary
                  if field in self._encode_fields:
                      val = getattr(self, field)
                      if val:
                          val = cast_s(base64.b64encode(cast_b(val)))
                      d['data'][field] = val
                  else:
                      d['data'][field] = getattr(self, field)
  
          return d
docs: Return a transmission-safe dictionary representation of the API message properties.