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

Function parseFrames

integration/microservices/e2e/tcp-json-socket-pipeline.spec.ts:35–59  ·  view source on GitHub ↗

* Decode as many complete `"<len>#<json>"` frames as possible from `raw`, * returning parsed objects and the leftover bytes.

(raw: string)

Source from the content-addressed store, hash-verified

33 * returning parsed objects and the leftover bytes.
34 */
35function parseFrames(raw: string): {
36 frames: Record<string, unknown>[];
37 remaining: string;
38} {
39 const frames: Record<string, unknown>[] = [];
40 let buf = raw;
41
42 while (true) {
43 const delim = buf.indexOf('#');
44 if (delim === -1) break;
45
46 const len = parseInt(buf.substring(0, delim), 10);
47 if (isNaN(len)) break;
48
49 const payload = buf.substring(delim + 1);
50 if (payload.length < len) break;
51
52 frames.push(
53 JSON.parse(payload.substring(0, len)) as Record<string, unknown>,
54 );
55 buf = payload.substring(len);
56 }
57
58 return { frames, remaining: buf };
59}
60
61const TEST_PORT = 4500;
62

Calls 1

parseMethod · 0.80

Tested by

no test coverage detected