import base64


def _message_to_dict(message):
  """Convert the message to a dict."""
  result = {}

  if message.data:
    result['data'] = base64.b64encode(message.data).decode('utf-8')

  if message.attributes:
    result['attributes'] = message.attributes

  return result