parameters: (tokenizer, message, field, allow_multiple_scalars)
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.
      allow_multiple_scalars: Determines if repeated values for a non-repeated
        field are permitted, e.g., the string "foo: 1 foo: 2" for a
        required/optional field named "foo".
  
    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, allow_multiple_scalars):
    """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.
      allow_multiple_scalars: Determines if repeated values for a non-repeated
        field are permitted, e.g., the string "foo: 1 foo: 2" for a
        required/optional field named "foo".
  
    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:
      value = tokenizer.ConsumeEnum(field)
    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:
        if not allow_multiple_scalars and message.HasExtension(field):
          raise tokenizer.ParseErrorPreviousToken(
              'Message type "%s" should not have multiple "%s" extensions.' %
              (message.DESCRIPTOR.full_name, field.full_name))
        else:
          message.Extensions[field] = value
      else:
        if not allow_multiple_scalars and message.HasField(field.name):
          raise tokenizer.ParseErrorPreviousToken(
              'Message type "%s" should not have multiple "%s" fields.' %
              (message.DESCRIPTOR.full_name, field.name))
        else:
          setattr(message, field.name, value)
function_tokens: def _MergeScalarField ( tokenizer , message , field , allow_multiple_scalars ) : 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 : value = tokenizer . ConsumeEnum ( field ) 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 : if not allow_multiple_scalars and message . HasExtension ( field ) : raise tokenizer . ParseErrorPreviousToken ( 'Message type "%s" should not have multiple "%s" extensions.' % ( message . DESCRIPTOR . full_name , field . full_name ) ) else : message . Extensions [ field ] = value else : if not allow_multiple_scalars and message . HasField ( field . name ) : raise tokenizer . ParseErrorPreviousToken ( 'Message type "%s" should not have multiple "%s" fields.' % ( message . DESCRIPTOR . full_name , field . name ) ) else : setattr ( message , field . name , value )