code: private function doMarshal(Message $message)
      {
          $schema = $message::schema();
          $message->validate();
  
          $payload = [];
  
          foreach ($schema->getFields() as $field) {
              $fieldName = $field->getName();
  
              if (!$message->has($fieldName)) {
                  /*
                  if ($message->hasClearedField($fieldName)) {
                      $payload[$fieldName] = null;
                  }
                  */
  
                  continue;
              }
  
              $value = $message->get($fieldName);
              $type = $field->getType();
  
              switch ($field->getRule()->getValue()) {
                  case FieldRule::A_SINGLE_VALUE:
                      $payload[$fieldName] = $type->encode($value, $field, $this);
                      break;
  
                  case FieldRule::A_SET:
                  case FieldRule::A_LIST:
                      $payload[$fieldName] = [];
                      foreach ($value as $v) {
                          $payload[$fieldName][] = $type->encode($v, $field, $this);
                      }
                      break;
  
                  case FieldRule::A_MAP:
                      $payload[$fieldName] = [];
                      foreach ($value as $k => $v) {
                          $payload[$fieldName][$k] = $type->encode($v, $field, $this);
                      }
                      break;
  
                  default:
                      break;
              }
          }
  
          return $payload;
      }
docs: @param Message $message
  
  @return array