shallowCustomHeader function
Extracts the JSON header (everything up to ,"data":) of a giant
custom record line as a parseable JSON object with data omitted —
or null when the line does not match the canonical writer order
(customType must precede data). Pre-truncating with this BEFORE the
batch parse keeps the ~0.75 MB payloads out of the isolate transfer
entirely (issue #503 round 3b): the truncated header decodes as a
CustomRecord with data: null through the normal path.
Implementation
String? shallowCustomHeader(String line) {
final dataIndex = line.indexOf(',"data":');
if (dataIndex < 0) return null;
// Canonical writer order has customType before data; a foreign order
// (data first) must keep the full line so no field is lost.
if (!line.substring(0, dataIndex).contains(',"customType":')) return null;
return '${line.substring(0, dataIndex)}}';
}