parameters: (tokenizer, message, field)
docstring: Merges a single protocol message scalar field into a message.
  
    Args:
      tokenizer: A tokenizer to parse the field value.
      message: A protocol message to record the data.
      field: The descriptor of the field to be merged.
  
    Raises:
      ParseError: In case of ASCII parsing problems.
      RuntimeError: On runtime errors.
docstring_summary: Merges a single protocol message scalar field into a message.
docstring_tokens: Merges a single protocol message scalar field into a message .
function: def _MergeScalarField(tokenizer, message, field):
    """Merges a single protocol message scalar field into a message.
  
    Args:
      tokenizer: A tokenizer to parse the field value.
      message: A protocol message to record the data.
      field: The descriptor of the field to be merged.
  
    Raises:
      ParseError: In case of ASCII parsing problems.
      RuntimeError: On runtime errors.
    """
    tokenizer.Consume(':')
    value = None
  
    if field.type in (descriptor.FieldDescriptor.TYPE_INT32,
                      descriptor.FieldDescriptor.TYPE_SINT32,
                      descriptor.FieldDescriptor.TYPE_SFIXED32):
      value = tokenizer.ConsumeInt32()
    elif field.type in (descriptor.FieldDescriptor.TYPE_INT64,
                        descriptor.FieldDescriptor.TYPE_SINT64,
                        descriptor.FieldDescriptor.TYPE_SFIXED64):
      value = tokenizer.ConsumeInt64()
    elif field.type in (descriptor.FieldDescriptor.TYPE_UINT32,
                        descriptor.FieldDescriptor.TYPE_FIXED32):
      value = tokenizer.ConsumeUint32()
    elif field.type in (descriptor.FieldDescriptor.TYPE_UINT64,
                        descriptor.FieldDescriptor.TYPE_FIXED64):
      value = tokenizer.ConsumeUint64()
    elif field.type in (descriptor.FieldDescriptor.TYPE_FLOAT,
                        descriptor.FieldDescriptor.TYPE_DOUBLE):
      value = tokenizer.ConsumeFloat()
    elif field.type == descriptor.FieldDescriptor.TYPE_BOOL:
      value = tokenizer.ConsumeBool()
    elif field.type == descriptor.FieldDescriptor.TYPE_STRING:
      value = tokenizer.ConsumeString()
    elif field.type == descriptor.FieldDescriptor.TYPE_BYTES:
      value = tokenizer.ConsumeByteString()
    elif field.type == descriptor.FieldDescriptor.TYPE_ENUM:
      # Enum can be specified by a number (the enum value), or by
      # a string literal (the enum name).
      enum_descriptor = field.enum_type
      if tokenizer.LookingAtInteger():
        number = tokenizer.ConsumeInt32()
        enum_value = enum_descriptor.values_by_number.get(number, None)
        if enum_value is None:
          raise tokenizer.ParseErrorPreviousToken(
              'Enum type "%s" has no value with number %d.' % (
                  enum_descriptor.full_name, number))
      else:
        identifier = tokenizer.ConsumeIdentifier()
        enum_value = enum_descriptor.values_by_name.get(identifier, None)
        if enum_value is None:
          raise tokenizer.ParseErrorPreviousToken(
              'Enum type "%s" has no value named %s.' % (
                  enum_descriptor.full_name, identifier))
      value = enum_value.number
    else:
      raise RuntimeError('Unknown field type %d' % field.type)
  
    if field.label == descriptor.FieldDescriptor.LABEL_REPEATED:
      if field.is_extension:
        message.Extensions[field].append(value)
      else:
        getattr(message, field.name).append(value)
    else:
      if field.is_extension:
        message.Extensions[field] = value
      else:
        setattr(message, field.name, value)
function_tokens: def _MergeScalarField ( tokenizer , message , field ) : tokenizer . Consume ( ':' ) value = None if field . type in ( descriptor . FieldDescriptor . TYPE_INT32 , descriptor . FieldDescriptor . TYPE_SINT32 , descriptor . FieldDescriptor . TYPE_SFIXED32 ) : value = tokenizer . ConsumeInt32 ( ) elif field . type in ( descriptor . FieldDescriptor . TYPE_INT64 , descriptor . FieldDescriptor . TYPE_SINT64 , descriptor . FieldDescriptor . TYPE_SFIXED64 ) : value = tokenizer . ConsumeInt64 ( ) elif field . type in ( descriptor . FieldDescriptor . TYPE_UINT32 , descriptor . FieldDescriptor . TYPE_FIXED32 ) : value = tokenizer . ConsumeUint32 ( ) elif field . type in ( descriptor . FieldDescriptor . TYPE_UINT64 , descriptor . FieldDescriptor . TYPE_FIXED64 ) : value = tokenizer . ConsumeUint64 ( ) elif field . type in ( descriptor . FieldDescriptor . TYPE_FLOAT , descriptor . FieldDescriptor . TYPE_DOUBLE ) : value = tokenizer . ConsumeFloat ( ) elif field . type == descriptor . FieldDescriptor . TYPE_BOOL : value = tokenizer . ConsumeBool ( ) elif field . type == descriptor . FieldDescriptor . TYPE_STRING : value = tokenizer . ConsumeString ( ) elif field . type == descriptor . FieldDescriptor . TYPE_BYTES : value = tokenizer . ConsumeByteString ( ) elif field . type == descriptor . FieldDescriptor . TYPE_ENUM : # Enum can be specified by a number (the enum value), or by # a string literal (the enum name). enum_descriptor = field . enum_type if tokenizer . LookingAtInteger ( ) : number = tokenizer . ConsumeInt32 ( ) enum_value = enum_descriptor . values_by_number . get ( number , None ) if enum_value is None : raise tokenizer . ParseErrorPreviousToken ( 'Enum type "%s" has no value with number %d.' % ( enum_descriptor . full_name , number ) ) else : identifier = tokenizer . ConsumeIdentifier ( ) enum_value = enum_descriptor . values_by_name . get ( identifier , None ) if enum_value is None : raise tokenizer . ParseErrorPreviousToken ( 'Enum type "%s" has no value named %s.' % ( enum_descriptor . full_name , identifier ) ) value = enum_value . number else : raise RuntimeError ( 'Unknown field type %d' % field . type ) if field . label == descriptor . FieldDescriptor . LABEL_REPEATED : if field . is_extension : message . Extensions [ field ] . append ( value ) else : getattr ( message , field . name ) . append ( value ) else : if field . is_extension : message . Extensions [ field ] = value else : setattr ( message , field . name , value )