#NEWLINE# def define_message( message_descriptor , module_name ) : #NEWLINE# #INDENT# 'Define Message class from descriptor.\n\n  Args:\n    message_descriptor: MessageDescriptor to describe message class from.\n    module_name: Module name to give to new descriptor class.\n\n  Returns:\n    New messages.Message sub-class as described by message_descriptor.\n  ' #NEWLINE# class_dict = { #NEWLINE# #INDENT# '__module__' : module_name , #NEWLINE# #UNINDENT# } #NEWLINE# for enum in ( message_descriptor . enum_types or [ ] ) : #NEWLINE# #INDENT# enum_instance = define_enum ( enum , module_name ) #NEWLINE# class_dict [ enum . name ] = enum_instance #NEWLINE# #UNINDENT# for field in ( message_descriptor . fields or [ ] ) : #NEWLINE# #INDENT# field_instance = define_field ( field ) #NEWLINE# class_dict [ field . name ] = field_instance #NEWLINE# #UNINDENT# class_name = message_descriptor . name . encode ( 'utf-8' ) #NEWLINE# return type ( class_name , ( messages . Message , ) , class_dict )