parameters: (message_descriptor, cls)
docstring: Helper for _AddMessageMethods().
docstring_summary: Helper for _AddMessageMethods().
docstring_tokens: Helper for _AddMessageMethods () .
function: def _AddSerializePartialToStringMethod(message_descriptor, cls):
    """Helper for _AddMessageMethods()."""
    Encoder = encoder.Encoder
  
    def SerializePartialToString(self):
      encoder = Encoder()
      # We need to serialize all extension and non-extension fields
      # together, in sorted order by field number.
      for field_descriptor, field_value in self.ListFields():
        if field_descriptor.label == _FieldDescriptor.LABEL_REPEATED:
          repeated_value = field_value
        else:
          repeated_value = [field_value]
        if field_descriptor.GetOptions().packed:
          # First, write the field number and WIRETYPE_LENGTH_DELIMITED.
          field_number = field_descriptor.number
          encoder.AppendTag(field_number, wire_format.WIRETYPE_LENGTH_DELIMITED)
          # Next, write the number of bytes.
          content_bytes = self._ContentBytesForPackedField(
              field_descriptor, field_value)
          encoder.AppendInt32NoTag(content_bytes)
          # Finally, write the actual values.
          try:
            method = type_checkers.TYPE_TO_NOTAG_SERIALIZE_METHOD[
                field_descriptor.type]
            for value in repeated_value:
              method(encoder, value)
          except KeyError:
            raise message_mod.EncodeError('Unrecognized field type: %d' %
                                          field_descriptor.type)
        else:
          for element in repeated_value:
            _SerializeValueToEncoder(element, field_descriptor.number,
                                     field_descriptor, encoder)
      return encoder.ToString()
  
    cls.SerializePartialToString = SerializePartialToString
function_tokens: def _AddSerializePartialToStringMethod ( message_descriptor , cls ) : Encoder = encoder . Encoder def SerializePartialToString ( self ) : encoder = Encoder ( ) # We need to serialize all extension and non-extension fields # together, in sorted order by field number. for field_descriptor , field_value in self . ListFields ( ) : if field_descriptor . label == _FieldDescriptor . LABEL_REPEATED : repeated_value = field_value else : repeated_value = [ field_value ] if field_descriptor . GetOptions ( ) . packed : # First, write the field number and WIRETYPE_LENGTH_DELIMITED. field_number = field_descriptor . number encoder . AppendTag ( field_number , wire_format . WIRETYPE_LENGTH_DELIMITED ) # Next, write the number of bytes. content_bytes = self . _ContentBytesForPackedField ( field_descriptor , field_value ) encoder . AppendInt32NoTag ( content_bytes ) # Finally, write the actual values. try : method = type_checkers . TYPE_TO_NOTAG_SERIALIZE_METHOD [ field_descriptor . type ] for value in repeated_value : method ( encoder , value ) except KeyError : raise message_mod . EncodeError ( 'Unrecognized field type: %d' % field_descriptor . type ) else : for element in repeated_value : _SerializeValueToEncoder ( element , field_descriptor . number , field_descriptor , encoder ) return encoder . ToString ( ) cls . SerializePartialToString = SerializePartialToString