Files
rea/src/captures/parsePacketOutput.ts
T
morluto d97db6ebaf fix(captures): preserve canonical TShark alias fields
TShark resolves selected field aliases before writing packet JSON. Keep the requested selector in Evidence while accepting the canonical field key produced for it.

Fixes #6595
2026-10-23 19:07:46 +08:00

26 lines
848 B
TypeScript

import { z } from "zod";
import { AnalysisOutputError } from "../domain/analysisErrorCore.js";
import { packetFieldsSchema } from "../domain/captures/packetCapture.js";
// _index/_score are TShark export metadata, not captured packet fields.
const producerSchema = z.array(
z.object({ _source: z.object({ layers: packetFieldsSchema }) }),
);
export const parsePacketOutput = (text: string) => {
const decoded: unknown = JSON.parse(text);
const packets = producerSchema
.parse(decoded)
.map((packet) => packet._source.layers);
let previous = 0n;
for (const packet of packets) {
const frame = BigInt(packet["frame.number"][0]);
if (frame <= previous)
throw new AnalysisOutputError(
"inspect_packet_capture",
"TShark returned unordered frames.",
);
previous = frame;
}
return packets;
};