def _parseMessageBundle(self, messageBundle): if self.logger.isEnabledFor(logging.VERBOSE): self.logger.log(logging.VERBOSE, 'Processing message bundle') offset = 8 while offset < messageBundle['length']: (messageType, length) = struct.unpack('>LL', messageBundle['data'][offset:offset + 8]) if messageType != definitions.MESSAGE_TYPE_EVENT_DATA: raise estreamer.ParsingException( 'Bundle item expected MESSAGE_TYPE_EVENT_DATA but got: {0}' .format(messageType)) message = { 'version': 1, 'messageType': messageType, 'length': length } if length > 0: dataStart = offset + 8 dataEnd = offset + 8 + length message['data'] = messageBundle['data'][dataStart:dataEnd] self._send(message) offset = offset + 8 + length
def create( filepath ): """Creates a new settings object and initialises logging""" if not os.path.isfile( filepath ): raise estreamer.EncoreException( 'Settings file: {0} does not exist or is not a file'.format( filepath )) with open( filepath, 'r' ) as configFile: try: config = json.load( configFile ) settings = Settings( config ) return settings except ValueError: raise estreamer.ParsingException('Invalid JSON in settings file')