def define_field(field_descriptor):
 field_class = _VARIANT_MAP[field_descriptor.variant]
 params = {'number': field_descriptor.number, 'variant': field_descriptor.variant}
 if (field_descriptor.label == descriptor.FieldDescriptor.Label.REQUIRED):
  params['required'] = True
 elif (field_descriptor.label == descriptor.FieldDescriptor.Label.REPEATED):
  params['repeated'] = True
 message_type_field = _MESSAGE_TYPE_MAP.get(field_descriptor.type_name)
 if message_type_field:
  return message_type_field(**params)
 elif (field_class in (messages.EnumField, messages.MessageField)):
  return field_class(field_descriptor.type_name, **params)
 else:
  return field_class(**params)

def define_field ( field_descriptor ) : field_class = _VARIANT_MAP [ field_descriptor . variant ] params = { 'number' : field_descriptor . number , 'variant' : field_descriptor . variant } if ( field_descriptor . label == descriptor . FieldDescriptor . Label . REQUIRED ) : params [ 'required' ] = True elif ( field_descriptor . label == descriptor . FieldDescriptor . Label . REPEATED ) : params [ 'repeated' ] = True message_type_field = _MESSAGE_TYPE_MAP . get ( field_descriptor . type_name ) if message_type_field : return message_type_field ( ** params ) elif ( field_class in ( messages . EnumField , messages . MessageField ) ) : return field_class ( field_descriptor . type_name , ** params ) else : return field_class ( ** params )
define field instance from descriptor .