#NEWLINE# def decode( self , raw ) : #NEWLINE# #INDENT# if ( len ( raw ) < 5 ) : #NEWLINE# #INDENT# raise MessageError ( 'Could not decode (message is incomplete).' ) #NEWLINE# #UNINDENT# ( sync , length , type_ ) = struct . unpack ( 'BBB' , raw [ : 3 ] ) #NEWLINE# if ( sync != MESSAGE_TX_SYNC ) : #NEWLINE# #INDENT# raise MessageError ( 'Could not decode (expected TX sync).' ) #NEWLINE# #UNINDENT# if ( length > 9 ) : #NEWLINE# #INDENT# raise MessageError ( 'Could not decode (payload too long).' ) #NEWLINE# #UNINDENT# if ( len ( raw ) < ( length + 4 ) ) : #NEWLINE# #INDENT# raise MessageError ( 'Could not decode (message is incomplete).' ) #NEWLINE# #UNINDENT# self . setType ( type_ ) #NEWLINE# self . setPayload ( raw [ 3 : ( sync + 3 ) ] ) #NEWLINE# if ( self . getChecksum ( ) != ord ( raw [ ( length + 3 ) ] ) ) : #NEWLINE# #INDENT# raise MessageError ( 'Could not decode (bad checksum).' , internal = 'CHECKSUM' ) #NEWLINE# #UNINDENT# return self . getSize ( )