#NEWLINE# def _SetFieldType( self , field_proto , field_desc , package , scope ) : #NEWLINE# #INDENT# "Sets the field's type, cpp_type, message_type and enum_type.\n\n    Args:\n      field_proto: Data about the field in proto format.\n      field_desc: The descriptor to modiy.\n      package: The package the field's container is in.\n      scope: Enclosing scope of available types.\n    " #NEWLINE# if field_proto . type_name : #NEWLINE# #INDENT# desc = self . _GetTypeFromScope ( package , field_proto . type_name , scope ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# desc = None #NEWLINE# #UNINDENT# if ( not field_proto . HasField ( 'type' ) ) : #NEWLINE# #INDENT# if isinstance ( desc , descriptor . Descriptor ) : #NEWLINE# #INDENT# field_proto . type = descriptor . FieldDescriptor . TYPE_MESSAGE #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# field_proto . type = descriptor . FieldDescriptor . TYPE_ENUM #NEWLINE# #UNINDENT# #UNINDENT# field_desc . cpp_type = descriptor . FieldDescriptor . ProtoTypeToCppProtoType ( field_proto . type ) #NEWLINE# if ( ( field_proto . type == descriptor . FieldDescriptor . TYPE_MESSAGE ) or ( field_proto . type == descriptor . FieldDescriptor . TYPE_GROUP ) ) : #NEWLINE# #INDENT# field_desc . message_type = desc #NEWLINE# #UNINDENT# if ( field_proto . type == descriptor . FieldDescriptor . TYPE_ENUM ) : #NEWLINE# #INDENT# field_desc . enum_type = desc #NEWLINE# #UNINDENT# if ( field_proto . label == descriptor . FieldDescriptor . LABEL_REPEATED ) : #NEWLINE# #INDENT# field_desc . has_default_value = False #NEWLINE# field_desc . default_value = [ ] #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if field_proto . HasField ( 'default_value' ) : #NEWLINE# #INDENT# field_desc . has_default_value = True #NEWLINE# if ( ( field_proto . type == descriptor . FieldDescriptor . TYPE_DOUBLE ) or ( field_proto . type == descriptor . FieldDescriptor . TYPE_FLOAT ) ) : #NEWLINE# #INDENT# field_desc . default_value = float ( self . default_value ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if ( field_proto . type == descriptor . FieldDescriptor . TYPE_STRING ) : #NEWLINE# #INDENT# field_desc . default_value = field_proto . default_value #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if ( field_proto . type == descriptor . FieldDescriptor . TYPE_BOOL ) : #NEWLINE# #INDENT# field_desc . default_value = ( field_proto . default_value . lower ( ) == 'true' ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if ( field_proto . type == descriptor . FieldDescriptor . TYPE_ENUM ) : #NEWLINE# #INDENT# field_desc . default_value = field_desc . enum_type . values_by_name [ field_proto . default_value ] . number #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if ( field_proto . type == descriptor . FieldDescriptor . TYPE_BYTES ) : #NEWLINE# #INDENT# field_desc . default_value = text_encoding . CUnescape ( field_proto . default_value ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# field_desc . default_value = int ( field_proto . default_value ) #NEWLINE# #UNINDENT# #UNINDENT# #UNINDENT# #UNINDENT# #UNINDENT# #UNINDENT# else : #NEWLINE# #INDENT# field_desc . has_default_value = False #NEWLINE# field_desc . default_value = None #NEWLINE# #UNINDENT# #UNINDENT# field_desc . type = field_proto . type