def fieldsReceived_WaitingForMessageID(self, fields): msgid, msgversion = map(int, fields) msgname = MESSAGE_NAMES.get(msgid, 'Unknown') log.debug('Parsing: {0}({1}) {2}'.format(msgname, msgid, msgversion)) parser = MESSAGE_PARSERS.get(msgid, None) if parser: generator = parser(msgid, msgversion) action, fieldcount = generator.next() assert action == FieldCount, 'Parsing generator must return a field count on first yield.' self.transition(WaitingForGenerator(generator, fieldcount, 2)) else: log.error('Unimplemented message ID: {0}'.format(msgid))
def fieldsReceived_WaitingForGenerator(self, fields): generator = self.state.generator cumfieldcount = self.state.cumfieldcount + len(fields) action, value = generator.send(fields) if action == FieldCount: self.transition(WaitingForGenerator(generator, value, cumfieldcount)) elif action == Done: generator.close() msgid = int(value[0]) msgname = MESSAGE_NAMES.get(msgid, 'Unknown') log.info('Message Parsed. Field Count: {0:>2}, Type: ({1:02}) {2}'.format(len(value), msgid, msgname)) assert cumfieldcount == len(value), 'The number of consumed fields shall equal the length of the resulting message.' self.publishFields(value) self.transition(WaitingForMessageID()) else: raise Expection('Unrecognised parser action {0}.'.format(action))
def fieldsReceived_WaitingForGenerator(self, fields): generator = self.state.generator cumfieldcount = self.state.cumfieldcount + len(fields) action, value = generator.send(fields) if action == FieldCount: self.transition( WaitingForGenerator(generator, value, cumfieldcount)) elif action == Done: generator.close() msgid = int(value[0]) msgname = MESSAGE_NAMES.get(msgid, 'Unknown') log.info('Message Parsed. Field Count: {0:>2}, Type: ({1:02}) {2}'. format(len(value), msgid, msgname)) assert cumfieldcount == len( value ), 'The number of consumed fields shall equal the length of the resulting message.' self.publishFields(value) self.transition(WaitingForMessageID()) else: raise Expection('Unrecognised parser action {0}.'.format(action))