| 9 | } |
| 10 | |
| 11 | public parse<T = any>(data: any): T { |
| 12 | // Clone object to as modifying the original one would break KafkaJS retries |
| 13 | const result = { |
| 14 | ...data, |
| 15 | headers: { ...data.headers }, |
| 16 | }; |
| 17 | |
| 18 | if (!this.keepBinary) { |
| 19 | result.value = this.decode(data.value); |
| 20 | } |
| 21 | |
| 22 | if (!isNil(data.key)) { |
| 23 | result.key = this.decode(data.key); |
| 24 | } |
| 25 | if (!isNil(data.headers)) { |
| 26 | const decodeHeaderByKey = (key: string) => { |
| 27 | result.headers[key] = this.decode(data.headers[key]); |
| 28 | }; |
| 29 | Object.keys(data.headers).forEach(decodeHeaderByKey); |
| 30 | } else { |
| 31 | result.headers = {}; |
| 32 | } |
| 33 | return result; |
| 34 | } |
| 35 | |
| 36 | public decode(value: Buffer): object | string | null | Buffer { |
| 37 | if (isNil(value)) { |