#NEWLINE# def sort_messages( fileObject ) : #NEWLINE# #INDENT# 'Return a sorted list of messages (sub-messages first).\n\n  This avoids compilation problems involving declaration order.\n  ' #NEWLINE# dependencies = [ ] #NEWLINE# msgDict = { #NEWLINE# #INDENT# #NEWLINE# #UNINDENT# } #NEWLINE# def visit( baseName , messages , parent = None ) : #NEWLINE# #INDENT# 'Visitor for the message tree.' #NEWLINE# for msg in messages : #NEWLINE# #INDENT# typeName = ( ( baseName + '.' ) + msg . name ) #NEWLINE# msgDict [ typeName ] = msg #NEWLINE# if ( parent is not None ) : #NEWLINE# #INDENT# msg . name = ( ( parent . name + '_' ) + msg . name ) #NEWLINE# #UNINDENT# if msg . nested_type : #NEWLINE# #INDENT# visit ( typeName , msg . nested_type , parent = msg ) #NEWLINE# #UNINDENT# deps = set ( [ field . type_name for field in msg . field if ( field . type == TYPE [ 'MESSAGE' ] ) ] ) #NEWLINE# dependencies . append ( ( typeName , deps ) ) #NEWLINE# #UNINDENT# #UNINDENT# visit ( ( '.' + fileObject . package ) , fileObject . message_type ) #NEWLINE# sortedMsgNames = order_dependencies ( dependencies ) #NEWLINE# return [ msgDict [ n ] for n in sortedMsgNames ]