code: def _AddSerializeToStringMethod(message_descriptor, cls):
    
  
    def SerializeToString(self):
      # Check if the message has all of its required fields set.
      errors = []
      if not self.IsInitialized():
        raise message_mod.EncodeError(
            'Message %s is missing required fields: %s' % (
            self.DESCRIPTOR.full_name, ','.join(self.FindInitializationErrors())))
      return self.SerializePartialToString()
    cls.SerializeToString = SerializeToString
docs: Helper for _AddMessageMethods().