def _SetFieldType(self, field_proto, field_desc, package, scope):
if field_proto.type_name:<EOL><INDENT>desc = self._GetTypeFromScope(package, field_proto.type_name, scope)<EOL><DEDENT>else:<EOL><INDENT>desc = None<EOL><DEDENT>if not field_proto.HasField('<STR_LIT:type>'):<EOL><INDENT>if isinstance(desc, descriptor.Descriptor):<EOL><INDENT>field_proto.type = descriptor.FieldDescriptor.TYPE_MESSAGE<EOL><DEDENT>else:<EOL><INDENT>field_proto.type = descriptor.FieldDescriptor.TYPE_ENUM<EOL><DEDENT><DEDENT>field_desc.cpp_type = descriptor.FieldDescriptor.ProtoTypeToCppProtoType(<EOL>field_proto.type)<EOL>if (field_proto.type == descriptor.FieldDescriptor.TYPE_MESSAGE<EOL>or field_proto.type == descriptor.FieldDescriptor.TYPE_GROUP):<EOL><INDENT>field_desc.message_type = desc<EOL><DEDENT>if field_proto.type == descriptor.FieldDescriptor.TYPE_ENUM:<EOL><INDENT>field_desc.enum_type = desc<EOL><DEDENT>if field_proto.label == descriptor.FieldDescriptor.LABEL_REPEATED:<EOL><INDENT>field_desc.has_default_value = False<EOL>field_desc.default_value = []<EOL><DEDENT>elif field_proto.HasField('<STR_LIT>'):<EOL><INDENT>field_desc.has_default_value = True<EOL>if (field_proto.type == descriptor.FieldDescriptor.TYPE_DOUBLE or<EOL>field_proto.type == descriptor.FieldDescriptor.TYPE_FLOAT):<EOL><INDENT>field_desc.default_value = float(field_proto.default_value)<EOL><DEDENT>elif field_proto.type == descriptor.FieldDescriptor.TYPE_STRING:<EOL><INDENT>field_desc.default_value = field_proto.default_value<EOL><DEDENT>elif field_proto.type == descriptor.FieldDescriptor.TYPE_BOOL:<EOL><INDENT>field_desc.default_value = field_proto.default_value.lower() == '<STR_LIT:true>'<EOL><DEDENT>elif field_proto.type == descriptor.FieldDescriptor.TYPE_ENUM:<EOL><INDENT>field_desc.default_value = field_desc.enum_type.values_by_name[<EOL>field_proto.default_value].number<EOL><DEDENT>elif field_proto.type == descriptor.FieldDescriptor.TYPE_BYTES:<EOL><INDENT>field_desc.default_value = text_encoding.CUnescape(<EOL>field_proto.default_value)<EOL><DEDENT>else:<EOL><INDENT>field_desc.default_value = int(field_proto.default_value)<EOL><DEDENT><DEDENT>else:<EOL><INDENT>field_desc.has_default_value = False<EOL>if (field_proto.type == descriptor.FieldDescriptor.TYPE_DOUBLE or<EOL>field_proto.type == descriptor.FieldDescriptor.TYPE_FLOAT):<EOL><INDENT>field_desc.default_value = <NUM_LIT:0.0><EOL><DEDENT>elif field_proto.type == descriptor.FieldDescriptor.TYPE_STRING:<EOL><INDENT>field_desc.default_value = u'<STR_LIT>'<EOL><DEDENT>elif field_proto.type == descriptor.FieldDescriptor.TYPE_BOOL:<EOL><INDENT>field_desc.default_value = False<EOL><DEDENT>elif field_proto.type == descriptor.FieldDescriptor.TYPE_ENUM:<EOL><INDENT>field_desc.default_value = field_desc.enum_type.values[<NUM_LIT:0>].number<EOL><DEDENT>elif field_proto.type == descriptor.FieldDescriptor.TYPE_BYTES:<EOL><INDENT>field_desc.default_value = b'<STR_LIT>'<EOL><DEDENT>else:<EOL><INDENT>field_desc.default_value = <NUM_LIT:0><EOL><DEDENT><DEDENT>field_desc.type = field_proto.type<EOL>
Sets the field's type, cpp_type, message_type and enum_type.

        Args:
          field_proto: Data about the field in proto format.
          field_desc: The descriptor to modiy.
          package: The package the field's container is in.
          scope: Enclosing scope of available types.