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

Method decode

packages/microservices/helpers/kafka-parser.ts:36–62  ·  view source on GitHub ↗
(value: Buffer)

Source from the content-addressed store, hash-verified

34 }
35
36 public decode(value: Buffer): object | string | null | Buffer {
37 if (isNil(value)) {
38 return null;
39 }
40 // A value with the "leading zero byte" indicates the schema payload.
41 // The "content" is possibly binary and should not be touched & parsed.
42 if (
43 Buffer.isBuffer(value) &&
44 value.length > 0 &&
45 value.readUInt8(0) === 0
46 ) {
47 return value;
48 }
49
50 let result = value.toString();
51 const startChar = result.charAt(0);
52
53 // Only try to parse objects and arrays
54 if (startChar === '{' || startChar === '[') {
55 try {
56 result = JSON.parse(value.toString());
57 } catch (e) {
58 // Do nothing
59 }
60 }
61 return result;
62 }
63}

Callers 2

parseMethod · 0.95
decodeHeaderByKeyMethod · 0.95

Calls 3

isNilFunction · 0.90
parseMethod · 0.80
toStringMethod · 0.45

Tested by

no test coverage detected