#NEWLINE# def serialize( self ) : #NEWLINE# #INDENT# if ( ( self . __magic__ is None ) or ( self . __fields__ is None ) ) : #NEWLINE# #INDENT# raise exceptions . ProtocolError ( 'Serialization can only be performed on classes implementing __fields__ and __magic__' ) #NEWLINE# #UNINDENT# p = packer_class ( ) #NEWLINE# p . pack_fstring ( 1 , self . __magic__ ) #NEWLINE# for ( name , field ) in self . __fields__ : #NEWLINE# #INDENT# value = getattr ( field , name ) #NEWLINE# field . pack ( p , value ) #NEWLINE# #UNINDENT# return p . get_buffer ( )