MCPcopy
hub / github.com/nestjs/nest / parse

Method parse

packages/microservices/helpers/kafka-parser.ts:11–34  ·  view source on GitHub ↗
(data: any)

Source from the content-addressed store, hash-verified

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)) {

Callers 15

convertInspectToJSONFunction · 0.80
toClassInstanceMethod · 0.80
parseMessageContentMethod · 0.80
decodeMemberMethod · 0.80
emitMessageFunction · 0.80
decodeMethod · 0.80

Calls 2

decodeMethod · 0.95
isNilFunction · 0.90

Tested by 2

convertInspectToJSONFunction · 0.64
parseFramesFunction · 0.64