* @param {Object} table A table used for parsing and processing * log records. * exampleDispatchTable = { * "log-entry-XXX": { * parser: [parseString, parseInt, ..., parseVarArgs], * processor: this.processXXX.bind(this) * }, * ... * }
(table)
| 84 | * } |
| 85 | */ |
| 86 | setDispatchTable(table) { |
| 87 | if (Object.getPrototypeOf(table) !== null) { |
| 88 | throw new Error("Dispatch expected table.__proto__=null for speedup"); |
| 89 | } |
| 90 | for (let name in table) { |
| 91 | const parser = table[name]; |
| 92 | if (parser === undefined) continue; |
| 93 | if (!parser.isAsync) parser.isAsync = false; |
| 94 | if (!Array.isArray(parser.parsers)) { |
| 95 | throw new Error(`Invalid parsers: dispatchTable['${ |
| 96 | name}'].parsers should be an Array.`); |
| 97 | } |
| 98 | let type = typeof parser.processor; |
| 99 | if (type !== 'function') { |
| 100 | throw new Error(`Invalid processor: typeof dispatchTable['${ |
| 101 | name}'].processor is '${type}' instead of 'function'`); |
| 102 | } |
| 103 | if (!parser.processor.name.startsWith('bound ')) { |
| 104 | parser.processor = parser.processor.bind(this); |
| 105 | } |
| 106 | this.dispatchTable_.set(name, parser); |
| 107 | } |
| 108 | } |
| 109 | |
| 110 | |
| 111 | /** |
no test coverage detected